繁体   English   中英

如何用PostgreSQL构建SOCI?

[英]How to build SOCI with PostgreSQL?

我正在尝试构建SOCI库以与PostgreSQL一起运行。 我按照以下步骤操作:

  • 在Ubutu 15.10中安装PostgreSQL
  • 下载SOCI源代码
  • 提取SOCI代码

然后,我运行以下命令:

mkdir build
cd build
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON -DPOSTGRESQL_INCLUDE_DIR=/usr/local/pgsql/include -DPOSTGRESQL_LIBRARIES=/usr/local/pgsql/lib ../soci

此时,CMake发出以下警告:

WARNING: Target "soci_postgresql" requests linking to directory "/usr/local/pgsql/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "soci_postgresql_static" requests linking to directory "/usr/local/pgsql/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "soci_postgresql_test" requests linking to directory "/usr/local/pgsql/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "soci_postgresql_test" requests linking to directory "/usr/local/pgsql/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "soci_postgresql_test_static" requests linking to directory "/usr/local/pgsql/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "soci_postgresql_test_static" requests linking to directory "/usr/local/pgsql/lib".  Targets may link only to libraries.  CMake is dropping the item.

坚持构建,然后运行make ,失败并显示以下错误:

[ 98%] Building CXX object tests/postgresql/CMakeFiles/soci_postgresql_test.dir/test-postgresql.cpp.o
Linking CXX executable ../../bin/soci_postgresql_test
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultStatus'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQgetvalue'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQclear'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQserverVersion'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultErrorMessage'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexec'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_lseek'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfsize'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQgetisnull'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQerrorMessage'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_open'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexecPrepared'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQftype'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_close'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexecParams'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfname'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQconnectdb'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQstatus'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQntuples'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultErrorField'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfformat'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_read'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfinish'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQprepare'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_write'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQcmdTuples'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQnfields'
collect2: error: ld returned 1 exit status
tests/postgresql/CMakeFiles/soci_postgresql_test.dir/build.make:89: recipe for target 'bin/soci_postgresql_test' failed
make[2]: *** [bin/soci_postgresql_test] Error 1
CMakeFiles/Makefile2:609: recipe for target 'tests/postgresql/CMakeFiles/soci_postgresql_test.dir/all' failed
make[1]: *** [tests/postgresql/CMakeFiles/soci_postgresql_test.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
make: *** [all] Error 2

知道CMake警告和构建错误的原因是什么?

尝试使用稍微不同的选项来调用cmake

cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON \
  -DPOSTGRESQL_INCLUDE_DIR:STRING="/usr/local/pgsql/include" \
  -DPOSTGRESQL_LIBRARIES:STRING="/usr/local/pgsql/lib" ../soci

我从github得到了正确的答案, 这是link 以下答复大部分是从此处获得的,但为方便起见在此处重复(进行清理和澄清):

-DPOSTGRESQL_LIBRARIES=/usr/local/psql/lib应该指向库,而不是目录。

这是以下警告已突出显示的内容:

警告:目标“ soci_postgresql”请求链接到目录“ / usr / local / postgresql / lib”

请改用以下命令(您可能还需要CMakeCache.txt构建目录中删除CMakeCache.txt ):

cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON ../soci

在安装了"postgresql-devel.x86_64 : PostgreSQL development header files and libraries" Linux系统上,此命令就足够了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM