Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 当我链接动态库而不是静态库时,CMake可以工作_C++_Postgresql_Cmake_Static Libraries_Static Linking - Fatal编程技术网

C++ 当我链接动态库而不是静态库时,CMake可以工作

C++ 当我链接动态库而不是静态库时,CMake可以工作,c++,postgresql,cmake,static-libraries,static-linking,C++,Postgresql,Cmake,Static Libraries,Static Linking,当我将动态库与CMake链接时,创建make文件,然后使用make,它会正确编译和构建 当我链接一个静态库时,CMake不会抱怨,但当我运行make时,它会向我抛出一个链接器错误,尽管我所做的只是将.dylib替换为同名的.a 这是链接到静态库的我的CMake文件: cmake_minimum_required (VERSION 3.0) add_executable (TEST main.cpp) include_directories ("${CMAKE_SOURCE_DIR}/Depen

当我将动态库与CMake链接时,创建make文件,然后使用make,它会正确编译和构建

当我链接一个静态库时,CMake不会抱怨,但当我运行make时,它会向我抛出一个链接器错误,尽管我所做的只是将
.dylib
替换为同名的
.a

这是链接到静态库的我的CMake文件:

cmake_minimum_required (VERSION 3.0)
add_executable (TEST main.cpp)

include_directories ("${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/include")
target_link_libraries (TEST "${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/lib/libpqxx.a")
有什么想法吗

cmake的输出:

>> cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/john/Documents/Test/src
make的输出:

>> make
[ 33%] Linking CXX executable TEST
Undefined symbols for architecture x86_64:
  "_PQbackendPID", referenced from:
      pqxx::connection_base::backendpid() const in libpqxx.a(connection_base.o)
  "_PQcancel", referenced from:
      pqxx::connection_base::cancel_query() in libpqxx.a(connection_base.o)
  "_PQclear", referenced from:
      pqxx::internal::clear_result(pg_result const*) in libpqxx.a(result.o)
  "_PQclientEncoding", referenced from:
      pqxx::connection_base::encoding_code() in libpqxx.a(connection_base.o)
  "_PQcmdStatus", referenced from:
      pqxx::result::cmd_status() const in libpqxx.a(result.o)
  "_PQcmdTuples", referenced from:
      pqxx::result::affected_rows() const in libpqxx.a(result.o)
  "_PQconnectPoll", referenced from:
      pqxx::connect_async::do_completeconnect(pg_conn*) in libpqxx.a(connection.o)
  "_PQconnectStart", referenced from:
      pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
  "_PQconnectdb", referenced from:
      pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
  "_PQconsumeInput", referenced from:
      pqxx::connection_base::consume_input() in libpqxx.a(connection_base.o)
  "_PQdb", referenced from:
      pqxx::connection_base::dbname() in libpqxx.a(connection_base.o)
  "_PQencryptPassword", referenced from:
      pqxx::encrypt_password(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
  "_PQendcopy", referenced from:
      pqxx::connection_base::write_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
  "_PQerrorMessage", referenced from:
      pqxx::connection_base::err_msg() const in libpqxx.a(connection_base.o)
      pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
      pqxx::connect_direct::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
      pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
      pqxx::connect_async::do_completeconnect(pg_conn*) in libpqxx.a(connection.o)
  "_PQescapeByteaConn", referenced from:
      pqxx::connection_base::esc_raw(unsigned char const*, unsigned long) in libpqxx.a(connection_base.o)
  "_PQescapeIdentifier", referenced from:
      pqxx::connection_base::quote_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
  "_PQescapeStringConn", referenced from:
      pqxx::connection_base::esc(char const*, unsigned long) in libpqxx.a(connection_base.o)
  "_PQexec", referenced from:
      pqxx::connection_base::exec(char const*, int) in libpqxx.a(connection_base.o)
      pqxx::connection_base::add_receiver(pqxx::notification_receiver*) in libpqxx.a(connection_base.o)
  "_PQexecParams", referenced from:
      pqxx::connection_base::parameterized_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const* const*, int const*, int const*, int) in libpqxx.a(connection_base.o)
      pqxx::connection_base::exec_params(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pqxx::internal::params const&) in libpqxx.a(connection_base.o)
  "_PQexecPrepared", referenced from:
      pqxx::connection_base::prepared_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const* const*, int const*, int const*, int) in libpqxx.a(connection_base.o)
      pqxx::connection_base::exec_prepared(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pqxx::internal::params const&) in libpqxx.a(connection_base.o)
  "_PQfinish", referenced from:
      pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
      pqxx::connectionpolicy::do_disconnect(pg_conn*) in libpqxx.a(connection.o)
  "_PQfname", referenced from:
      pqxx::result::column_name(unsigned int) const in libpqxx.a(result.o)
  "_PQfnumber", referenced from:
      pqxx::result::column_number(char const*) const in libpqxx.a(row.o)
  "_PQfreeCancel", referenced from:
      (anonymous namespace)::cancel_wrapper::~cancel_wrapper() in libpqxx.a(connection_base.o)
  "_PQfreemem", referenced from:
      pqxx::internal::freepqmem(void const*) in libpqxx.a(util.o)
  "_PQftable", referenced from:
      pqxx::result::column_table(unsigned int) const in libpqxx.a(result.o)
  "_PQftablecol", referenced from:
      pqxx::result::table_column(unsigned int) const in libpqxx.a(result.o)
  "_PQftype", referenced from:
      pqxx::result::column_type(unsigned int) const in libpqxx.a(result.o)
  "_PQgetCancel", referenced from:
      pqxx::connection_base::cancel_query() in libpqxx.a(connection_base.o)
  "_PQgetCopyData", referenced from:
      pqxx::connection_base::read_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libpqxx.a(connection_base.o)
  "_PQgetResult", referenced from:
      pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
      pqxx::connection_base::read_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libpqxx.a(connection_base.o)
      pqxx::connection_base::end_copy_write() in libpqxx.a(connection_base.o)
      pqxx::connection_base::get_result() in libpqxx.a(connection_base.o)
  "_PQgetisnull", referenced from:
      pqxx::result::get_is_null(unsigned long, unsigned int) const in libpqxx.a(result.o)
  "_PQgetlength", referenced from:
      pqxx::result::get_length(unsigned long, unsigned int) const in libpqxx.a(result.o)
  "_PQgetvalue", referenced from:
      pqxx::result::GetValue(unsigned long, unsigned int) const in libpqxx.a(result.o)
  "_PQhost", referenced from:
      pqxx::connection_base::hostname() in libpqxx.a(connection_base.o)
  "_PQisBusy", referenced from:
      pqxx::connection_base::is_busy() const in libpqxx.a(connection_base.o)
  "_PQisthreadsafe", referenced from:
      pqxx::describe_thread_safety() in libpqxx.a(util.o)
  "_PQnfields", referenced from:
      pqxx::result::columns() const in libpqxx.a(result.o)
  "_PQnotifies", referenced from:
      pqxx::connection_base::get_notifs() in libpqxx.a(connection_base.o)
  "_PQntuples", referenced from:
      pqxx::result::size() const in libpqxx.a(result.o)
      pqxx::result::empty() const in libpqxx.a(result.o)
  "_PQoidValue", referenced from:
      pqxx::result::inserted_oid() const in libpqxx.a(result.o)
  "_PQport", referenced from:
      pqxx::connection_base::port() in libpqxx.a(connection_base.o)
  "_PQprepare", referenced from:
      pqxx::connection_base::register_prepared(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
  "_PQprotocolVersion", referenced from:
      pqxx::connection_base::protocol_version() const in libpqxx.a(connection_base.o)
  "_PQputCopyData", referenced from:
      pqxx::connection_base::write_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
  "_PQputCopyEnd", referenced from:
      pqxx::connection_base::end_copy_write() in libpqxx.a(connection_base.o)
  "_PQreset", referenced from:
      pqxx::connection_base::reset() in libpqxx.a(connection_base.o)
  "_PQresultErrorField", referenced from:
      pqxx::result::ThrowSQLError(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libpqxx.a(result.o)
      pqxx::result::errorposition() const in libpqxx.a(result.o)
  "_PQresultErrorMessage", referenced from:
      pqxx::result::StatusError() const in libpqxx.a(result.o)
  "_PQresultStatus", referenced from:
      pqxx::result::StatusError() const in libpqxx.a(result.o)
  "_PQsendQuery", referenced from:
      pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
      pqxx::connection_base::start_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
  "_PQserverVersion", referenced from:
      pqxx::connection_base::read_capabilities() in libpqxx.a(connection_base.o)
  "_PQsetErrorVerbosity", referenced from:
      pqxx::connection_base::set_verbosity(pqxx::connection_base::error_verbosity) in libpqxx.a(connection_base.o)
  "_PQsetNoticeProcessor", referenced from:
      pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
      pqxx::connection_base::close() in libpqxx.a(connection_base.o)
  "_PQsocket", referenced from:
      (anonymous namespace)::socket_of(pg_conn const*) in libpqxx.a(connection_base.o)
  "_PQstatus", referenced from:
      pqxx::connection_base::status() const in libpqxx.a(connection_base.o)
      pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
      pqxx::connect_direct::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
      pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
  "_PQtrace", referenced from:
      pqxx::connection_base::internal_set_trace() in libpqxx.a(connection_base.o)
  "_PQunescapeBytea", referenced from:
      pqxx::connection_base::unesc_raw(char const*) in libpqxx.a(connection_base.o)
  "_PQuntrace", referenced from:
      pqxx::connection_base::internal_set_trace() in libpqxx.a(connection_base.o)
  "_PQuser", referenced from:
      pqxx::connection_base::username() in libpqxx.a(connection_base.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [TEST] Error 1
make[1]: *** [CMakeFiles/TEST.dir/all] Error 2
make: *** [all] Error 2
>制作
[33%]链接CXX可执行测试
架构x86_64的未定义符号:
“_PQbackendPID”,引用自:
pqxx::connection_base::libpqxx.a(connection_base.o)中的backendpid()常量
“取消”,引用自:
pqxx::connection_base::取消libpqxx.a(connection_base.o)中的查询()
“_PQclear”,引用自:
pqxx::内部::清除libpqxx.a(result.o)中的结果(pg\u result const*)
“客户编码”,引用自:
pqxx::connection_base::在libpqxx.a(connection_base.o)中编码_code()
“PQcmdStatus”,引用自:
pqxx::result::libpqxx.a(result.o)中的cmd_status()常量
“_PQcmdTuples”,引用自:
pqxx::result::libpqxx.a(result.o)中受影响的_行()常量
“_PQconnectPoll”,引用自:
pqxx::connect\u async::在libpqxx.a(connection.o)中完成连接(pg\u conn*)
“_PQconnectStart”,引用自:
pqxx::connect\u async::do\u startconnect(pg\u conn*)在libpqxx.a(connection.o)中
“_PQconnectdb”,引用自:
libpqxx.a(connection.o)中的pqxx::connectionpolicy::normalconnect(pg_conn*)
“输入”,引用自:
pqxx::connection_base::使用libpqxx.a(connection_base.o)中的输入()
“PQdb”,引用自:
libpqxx.a(connection_base.o)中的pqxx::connection_base::dbname()
“_PQencryptPassword”,引用自:
pqxx::在libpqxx.a(connection\u base.o)中加密\u密码(std::\u 1::basic\u string const&,std:\u 1::basic\u string const&)
“_PQendcopy”,引用自:
pqxx::connection_base::在libpqxx.a(connection_base.o)中写入_copy_行(std:_1::basic_string const&)
“\u PQerrorMessage”,引用自:
pqxx::connection_base::libpqxx.a(connection_base.o)中的err_msg()常量
libpqxx.a(connection.o)中的pqxx::connectionpolicy::normalconnect(pg_conn*)
pqxx::connect\u direct::在libpqxx.a(connection.o)中启动连接(pg\u conn*)
pqxx::connect\u async::do\u startconnect(pg\u conn*)在libpqxx.a(connection.o)中
pqxx::connect\u async::在libpqxx.a(connection.o)中完成连接(pg\u conn*)
“_PQESCAPEBYTECON”,引用自:
pqxx::connection_base::libpqxx.a(connection_base.o)中的esc_raw(unsigned char const*,unsigned long)
“\u PQescapeIdentifier”,引用自:
libpqxx.a(connection_base.o)中的pqxx::connection_base::quote_name(std::_1::basic_string const&)
“\u PQescapeStringConn”,引用自:
pqxx::connection_base::libpqxx.a(connection_base.o)中的esc(char const*,unsigned long)
“_PQexec”,引用自:
libpqxx.a(connection_base.o)中的pqxx::connection_base::exec(char const*,int)
pqxx::connection_base::在libpqxx.a(connection_base.o)中添加_receiver(pqxx::notification_receiver*)
“_PQexecParams”,引用自:
pqxx::connection_base::libpqxx.a(connection_base.o)中的参数化_exec(std:_1::basic_字符串常量&,char const*const*,int const*,int const*,int)
libpqxx.a(connection_base.o)中的pqxx::connection_base::exec_params(std::_1::basic_string const&,pqxx::internal::params const&)
“准备就绪”,引用自:
pqxx::connection_base::在libpqxx.a(connection_base.o)中准备好的_exec(标准::_1::basic_string const&,char const*const*,int const*,int const*,int)
libpqxx.a(connection_base.o)中的pqxx::connection_base::exec_prepared(标准::_1::basic_字符串常量&,pqxx::internal::params常量&)
“_PQfinish”,引用自:
libpqxx.a(connection.o)中的pqxx::connectionpolicy::normalconnect(pg_conn*)
连接策略::在libpqxx.a(connection.o)中断开连接(pg\u conn*)
“_PQfname”,引用自:
pqxx::result::libpqxx.a(result.o)中的列名称(unsigned int)常量
“_PQfnumber”,引用自:
pqxx::result::libpqxx.a(row.o)中的列号(char const*)常量
“取消”,引用自:
(匿名命名空间)::cancel_wrapper::~cancel_wrapper()位于libpqxx.a(connection_base.o)中
“\u PQfreemem”,引用自:
libpqxx.a(util.o)中的pqxx::internal::freepqmem(void const*)
“_PQftable”,引用自:
pqxx::result::libpqxx.a(result.o)中的列_表(unsigned int)常量
“_PQftablecol”,引用自:
pqxx::result::libpqxx.a(result.o)中的表_列(unsigned int)常量
“_PQftype”,引用自:
pqxx::result::libpqxx.a(result.o)中的列类型(无符号int)常量
“\u PQgetCancel”,引用自:
pqxx::connection_base::取消libpqxx.a(connection_base.o)中的查询()
“\u PQgetCopyData”,引用自:
pqxx::connection_base::读取libpqxx.a(connection_base.o)中的\u copy_行(std::\uu 1::basic_string&)
“_PQgetResult”,引用自:
pqxx::connection_base::在libpqxx.a(connection_base.o)中设置_-up_-state()
pqxx::connection_base::读取libpqxx.a(connection_base.o)中的\u copy_行(std::\uu 1::basic_string&)
pqxx::connection_base::end_copy_write()在libpqxx.a(connection_base.o)中
pqxx::connection_base::在libpqxx.a(connection_base.o)中获取结果()
“_PQgetisnull”,引用自:
pqxx::result::get_是libpqxx.a(result.o)中的null(无符号长,无符号整数)常量
“_PQgetlength”,引用自:
pqxx::result::获取libpqxx.a(result.o)中的长度(无符号长,无符号整数)常量
“_PQgetvalue”,引用自:
pqxx::result::libpqxx.a(result.o)中的GetValue(无符号长,无符号整数)常量
“PQU主机”,引用自:
libpqxx.a(connection_base.o)中的pqxx::connection_base::hostname()
“\u PQisBusy”,引用自:
pqxx::连接\基础::忙吗()
link_directories(${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/lib)
target_link_libraries (TEST pqxx)