Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译时报错找不到libpq-fe.h #187

Open
chen2142 opened this issue Jan 12, 2025 · 5 comments
Open

编译时报错找不到libpq-fe.h #187

chen2142 opened this issue Jan 12, 2025 · 5 comments

Comments

@chen2142
Copy link

系统: Ubuntu22.04 LTS
按照要求装了libpq-dev,根据说明在cmake --build build --config DEBUG 的时候报错找不到libpq-fe.h,如下

Consolidate compiler generated dependencies of target test_ormpp
[ 20%] Building CXX object tests/CMakeFiles/test_ormpp.dir/test_ormpp.cpp.o
In file included from /home/ormpp/tests/test_ormpp.cpp:12:
/home/ormpp/ormpp/postgresql.hpp:8:10: fatal error: libpq-fe.h: No such file or directory
    8 | #include <libpq-fe.h>
      |          ^~~~~~~~~~~~

确定已经安装了libpq-dev,查看了libpq-fe.h是在/usr/include/postgresql下,又改了CMakeLists.txt
加了这一句

include_directories(/usr/include/postgresql)

之后这里是不报错了,但是出现一大堆连接时找不到的报错
也试过安装整个postgres,还是不行。

@qicosmos
Copy link
Owner

@Jacyking
看一下

@Jacyking
Copy link
Collaborator

cmake版本低了,最新的pr有解决这个问题,或者直接升级cmake到3.29吧

@chen2142
Copy link
Author

感谢,安装了cmake3.31后确实成功了

@chen2142
Copy link
Author

大佬们,小白又遇到个问题。我在尝试整合进我的项目的时候,把整个项目目录下到了我的 src/utils下,即整个目录路径是
xxxx(我的项目名字)/src/utils/ormpp
这个时候使用

set(ENABLE_PG ON)
add_definitions(-DORMPP_ENABLE_PG)
add_subdirectory(/src/utils/ormpp)

或是

set(ENABLE_PG ON)
add_definitions(-DORMPP_ENABLE_PG)
add_library(ormpp INTERFACE)
include(src/utils/ormpp/cmake/pgsql.cmake)
target_link_libraries(ormpp INTERFACE ${PGSQL_LIBRARY})
target_include_directories(ormpp INTERFACE ormpp src/utils/ormpp/ormpp ${PGSQL_INCLUDE_DIR})

都不行,因为会报这个错误

src/utils/ormpp/example/main.cpp:10:10: fatal error: postgresql.hpp: No such file or directory
   10 | #include "postgresql.hpp"
      |          ^~~~~~~~~~~~~~~~

但是我把全部东西都挪到项目目录下,按照说明的方法,add_subdirectory(ormpp) 就可以正常编译。请问我要如何在其他地方编译成功呢,或者把它变成一个库可以随时用?

@Jacyking
Copy link
Collaborator

大佬们,小白又遇到个问题。我在尝试整合进我的项目的时候,把整个项目目录下到了我的 src/utils下,即整个目录路径是 xxxx(我的项目名字)/src/utils/ormpp 这个时候使用

set(ENABLE_PG ON)
add_definitions(-DORMPP_ENABLE_PG)
add_subdirectory(/src/utils/ormpp)
或是

set(ENABLE_PG ON)
add_definitions(-DORMPP_ENABLE_PG)
add_library(ormpp INTERFACE)
include(src/utils/ormpp/cmake/pgsql.cmake)
target_link_libraries(ormpp INTERFACE ${PGSQL_LIBRARY})
target_include_directories(ormpp INTERFACE ormpp src/utils/ormpp/ormpp ${PGSQL_INCLUDE_DIR})
都不行,因为会报这个错误

src/utils/ormpp/example/main.cpp:10:10: fatal error: postgresql.hpp: No such file or directory
   10 | #include "postgresql.hpp"
      |          ^~~~~~~~~~~~~~~~

但是我把全部东西都挪到项目目录下,按照说明的方法,add_subdirectory(ormpp) 就可以正常编译。请问我要如何在其他地方编译成功呢,或者把它变成一个库可以随时用?

你检查一下路径吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants