我正在尝试测试到我的postgreSQL数据库的连接。我从这里安装了libpqxx,官方的C++客户端PostgreSQL API。我运行./configure PG_CONFIG=/usr/pgsql-10/bin/pg_config,以便在使用默认设置执行make和make install之前进行配置。首先,我必须安装postgresql10-libs和postgresql10-devel才能拥有pg_config文件,因为我的真正的PostgreSQL服务器不在我的PC上。
我试图使用标志-lpqxx -lpq进行编译。我已经把这个添加到我的CMakeLists.txt中了
set(GCC_COVERAGE_COMPILE_FLAGS "-lpqxx -lpq -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")但是我不断地发现这个错误:
Linking CXX executable myproject
/usr/bin/ld: cannot find -lpq
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/myproject.dir/build.make:1187: myproject] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/myproject.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/myproject.dir/rule] Error 2
gmake: *** [Makefile:118: myproject] Error 2更新12.06.18
我安装了postgresql-devel并进行了更改
set(GCC_COVERAGE_COMPILE_FLAGS "-lpqxx -lpq -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")至
set(GCC_COVERAGE_COMPILE_FLAGS "-std=gnu++11")
set(PQXX_AND_PQ_FLAGS "-lpqxx -lpq -I/usr/local/include -L/usr/local/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PQXX_AND_PQ_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")错误/usr/bin/ld: cannot find -lpq就消失了。
但是现在我得到了一些关于pqxx的其他错误
CMakeFiles/myproject.dir/dev/hmmenc_client/db/db.cpp.o: In function `db::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
/home/tglozman/CLionProjects/myproject/dev/hmmenc_client/db/db.cpp:17: undefined reference to `pqxx::connection_base::is_open() const'
/home/tglozman/CLionProjects/myproject/dev/hmmenc_client/db/db.cpp:18: undefined reference to `pqxx::connection_base::dbname()'
/home/tglozman/CLionProjects/myproject/dev/hmmenc_client/db/db.cpp:23: undefined reference to `pqxx::connection_base::disconnect()'
CMakeFiles/myproject.dir/dev/hmmenc_client/db/db.cpp.o: In function `pqxx::connection_base::connection_base(pqxx::connectionpolicy&)':
/usr/local/include/pqxx/connection_base.hxx:695: undefined reference to `int pqxx::internal::check_library_version<6, 2>()'
/usr/local/include/pqxx/connection_base.hxx:698: undefined reference to `pqxx::connection_base::clearcaps()'
CMakeFiles/myproject.dir/dev/hmmenc_client/db/db.cpp.o: In function `pqxx::connect_direct::connect_direct(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/connection.hxx:83: undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/include/pqxx/connection.hxx:83: undefined reference to `vtable for pqxx::connect_direct'
CMakeFiles/myproject.dir/dev/hmmenc_client/db/db.cpp.o: In function `pqxx::connect_direct::~connect_direct()':
/usr/local/include/pqxx/connection.hxx:78: undefined reference to `vtable for pqxx::connect_direct'
/usr/local/include/pqxx/connection.hxx:78: undefined reference to `pqxx::connectionpolicy::~connectionpolicy()'
CMakeFiles/myproject.dir/dev/hmmenc_client/db/db.cpp.o: In function `pqxx::basic_connection<pqxx::connect_direct>::basic_connection(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/basic_connection.hxx:57: undefined reference to `pqxx::connection_base::init()'
CMakeFiles/myproject.dir/dev/hmmenc_client/db/db.cpp.o: In function `pqxx::basic_connection<pqxx::connect_direct>::~basic_connection()':
/usr/local/include/pqxx/basic_connection.hxx:66: undefined reference to `pqxx::connection_base::close()'
collect2: error: ld returned 1 exit status我在#include <pqxx/pqxx>的代码中没有任何问题
发布于 2018-06-11 21:02:12
您可能需要告诉cmake 'pq‘和'pqxx’的安装位置。通过指定完整路径‘-lfullpath to-pq’或使用目录
https://stackoverflow.com/questions/50805595
复制相似问题