Когда я компилирую свою программу PostgreSQL на C ++, я получаю эти ошибки. Может кто-нибудь сказать мне причину этого.
user@linux-yyzo:~/WorkDir/Program> g++ test.cpp -lpqxx -I/usr/local/include -I/usr/local/pgsql/include
/usr/local/lib/libpqxx.a(util.o): In function `pqxx::describe_thread_safety()':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/util.cxx:69: undefined reference to `PQisthreadsafe'
/usr/local/lib/libpqxx.a(util.o): In function `pqxx::internal::freepqmem(void const*)':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/util.cxx:195: undefined reference to `PQfreemem'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::internal::result_data::~result_data()':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:55: undefined reference to `PQclear'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::size() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:101: undefined reference to `PQntuples'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::empty() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:107: undefined reference to `PQntuples'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::CmdStatus() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:241: undefined reference to `PQcmdStatus'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::inserted_oid() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:256: undefined reference to `PQoidValue'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::affected_rows() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:262: undefined reference to `PQcmdTuples'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::GetIsNull(unsigned long, unsigned int) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:279: undefined reference to `PQgetisnull'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::GetLength(unsigned long, unsigned int) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:286: undefined reference to `PQgetlength'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::errorposition() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:344: undefined reference to `PQresultErrorField'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::ThrowSQLError(std::string const&, std::string const&) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:132: undefined reference to `PQresultErrorField'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::columns() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:363: undefined reference to `PQnfields'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::column_name(unsigned int) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:353: undefined reference to `PQfname'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::table_column(unsigned int) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:318: undefined reference to `PQftablecol'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::StatusError() const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:214: undefined reference to `PQresultStatus'
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:233: undefined reference to `PQresultStatus'
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:228: undefined reference to `PQresultErrorMessage'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::column_table(unsigned int) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/result.cxx:303: undefined reference to `PQftable'
/usr/local/lib/libpqxx.a(result.o): In function `pqxx::result::column_type(unsigned int) const':
/usr/local/lib/libpqxx.a(connection.o): In function `pqxx::connect_direct::do_startconnect(pg_conn*)':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/connection.cxx:94: undefined reference to `PQstatus'
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/connection.cxx:96: undefined reference to `PQerrorMessage'
/usr/local/lib/libpqxx.a(tuple.o): In function `pqxx::result::column_number(char const*) const':
/home/user/WorkDir/Program/Connections/libpqxx-4.0/src/tuple.cxx:194: undefined reference to `PQfnumber'
collect2: error: ld returned 1 exit status
Вам нужно добавить -lpq
как вариант для GCC, чтобы связать libpq
сам. Это должно идти после -lpqxx
:
g++ test.cpp -lpqxx -lpq -I/usr/local/include -I/usr/local/pgsql/include
# ^^^^ here
Это нужно как libpqxx
это просто оболочка C ++ вокруг интерфейса C libpq
которая является настоящей клиентской библиотекой для PostgreSQL. Вам может понадобиться добавить -L/path/to/libpq
перед -lpq
если он не найден в пути к системной библиотеке.
Других решений пока нет …