我按照以下步骤使用postgresql构建soci并使用soci构建我的应用程序。
1)从git到目录/ home / sujith / soci / src的结帐代码
sujith@sujith-VirtualBox:~/soci/src$ pwd
/home/sujith/soci/src
sujith@sujith-VirtualBox:~/soci/src$ ls
appveyor.yml AUTHORS bin CHANGES cmake CMakeLists.txt CTestConfig.cmake docs include languages LICENSE_1_0.txt README.md src tests TODO Vagrantfile www
sujith@sujith-VirtualBox:~/soci/src$
2)完成cmake
sujith@sujith-VirtualBox:~/soci/build$ pwd
/home/sujith/soci/build
sujith@sujith-VirtualBox:~/soci/build$ cmake -G "Unix Makefiles" -DWITH_POSTGRESQL=ON ../src
-- The C compiler identification is GNU 5.2.1
-- The CXX compiler identification is GNU 5.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for __i386__
-- Looking for __i386__ - not found
-- Looking for __x86_64__
-- Looking for __x86_64__ - found
-- Looking for __arm__
-- Looking for __arm__ - not found
-- Configuring SOCI:
-- SOCI_VERSION = 4.0.0
-- SOCI_ABI_VERSION = 4.0
-- SOCI_SHARED = ON
-- SOCI_STATIC = ON
-- SOCI_TESTS = ON
-- SOCI_CXX_C11 = OFF
-- Looking for SOCI dependencies:
-- Threads:
-- CMAKE_THREAD_LIBS_INIT = -lpthread
-- Boost:
-- Boost_RELEASE_VERSION = 1.60.0
-- Boost_INCLUDE_DIR = /usr/local/include
-- Boost_LIBRARIES = /usr/local/lib/libboost_date_time.so
-- MySQL:
-- Performing Test HAVE_MYSQL_OPT_EMBEDDED_CONNECTION
-- Performing Test HAVE_MYSQL_OPT_EMBEDDED_CONNECTION - Failed
-- MySQL not found.
-- MySQL Embedded not found.
-- WARNING:
-- MySQL not found, some libraries or features will be disabled.
-- See the documentation for MySQL or manually set these variables:
-- MYSQL_INCLUDE_DIR = MYSQL_INCLUDE_DIR-NOTFOUND
-- MYSQL_LIBRARIES = MYSQL_LIBRARIES-NOTFOUND
-- ODBC:
-- Looking for include files windows.h, sqlext.h
-- Looking for include files windows.h, sqlext.h - not found
-- WARNING:
-- ODBC not found, some libraries or features will be disabled.
-- See the documentation for ODBC or manually set these variables:
-- ODBC_INCLUDE_DIR = ODBC_INCLUDE_DIR-NOTFOUND
-- ODBC_LIBRARIES = ODBC_LIBRARY-NOTFOUND
-- Oracle:
-- ORACLE_HOME=
-- WARNING:
-- Oracle not found, some libraries or features will be disabled.
-- See the documentation for Oracle or manually set these variables:
-- ORACLE_INCLUDE_DIR = ORACLE_INCLUDE_DIR-NOTFOUND
-- ORACLE_LIBRARIES = ORACLE_OCI_LIBRARY-NOTFOUND ORACLE_OCCI_LIBRARY-NOTFOUND ORACLE_NNZ_LIBRARY-NOTFOUND
-- PostgreSQL:
-- POSTGRESQL_INCLUDE_DIR = /usr/include/postgresql
-- POSTGRESQL_LIBRARIES = /usr/lib/x86_64-linux-gnu/libpq.so
-- POSTGRESQL_VERSION = 9.4.6
-- SQLite3:
-- WARNING:
-- SQLite3 not found, some libraries or features will be disabled.
-- See the documentation for SQLite3 or manually set these variables:
-- SQLITE3_INCLUDE_DIR = SQLITE3_INCLUDE_DIR-NOTFOUND
-- SQLITE3_LIBRARIES = SQLITE3_LIBRARY-NOTFOUND
-- Firebird:
-- SOCI_FIREBIRD_EMBEDDED = OFF
-- WARNING:
-- Firebird not found, some libraries or features will be disabled.
-- See the documentation for Firebird or manually set these variables:
-- FIREBIRD_INCLUDE_DIR = FIREBIRD_INCLUDE_DIR-NOTFOUND
-- FIREBIRD_LIBRARIES = FIREBIRD_LIBRARIES-NOTFOUND
-- FIREBIRD_VERSION =
-- DB2:
-- WARNING:
-- DB2 not found, some libraries or features will be disabled.
-- See the documentation for DB2 or manually set these variables:
-- DB2_INCLUDE_DIR = DB2_INCLUDE_DIR-NOTFOUND
-- DB2_LIBRARIES = DB2_LIBRARY-NOTFOUND
-- Configuring SOCI core library:
-- SOCI_CORE_TARGET = soci_core
-- SOCI_CORE_TARGET_OUTPUT_NAME = soci_core
-- SOCI_CORE_DEPS_LIBS = -lpthread /usr/lib/x86_64-linux-gnu/libdl.so /usr/local/lib/libboost_date_time.so
-- SOCI_CORE_INCLUDE_DIRS = /usr/local/include /home/sujith/soci/build /home/sujith/soci/src/include /home/sujith/soci/build/include /home/sujith/soci/src/include/private /home/sujith/soci/build/src/core
-- WITH_BOOST = ON
-- COMPILE_DEFINITIONS = SOCI_ABI_VERSION="4.0" HAVE_DL=1 BOOST_ALL_NO_LIB SOCI_LIB_PREFIX="libsoci_" SOCI_LIB_SUFFIX=".so" SOCI_DEBUG_POSTFIX=""
--
-- Configuring SOCI backend libraries:
-- MySQL not found.
-- MySQL Embedded not found.
-- ORACLE_HOME=
-- Empty - SOCI backend skeleton for new backends development
-- SOCI_EMPTY = ON
-- SOCI_EMPTY_TARGET = soci_empty
-- SOCI_EMPTY_OUTPUT_NAME = soci_empty
-- SOCI_EMPTY_COMPILE_DEFINITIONS = SOCI_ABI_VERSION="4.0" HAVE_DL=1 BOOST_ALL_NO_LIB
-- SOCI_EMPTY_INCLUDE_DIRECTORIES = /usr/local/include /home/sujith/soci/build /home/sujith/soci/src/include /home/sujith/soci/build/include /home/sujith/soci/src/include/private /home/sujith/soci/src/include/private
-- PostgreSQL - SOCI backend for PostgreSQL
-- SOCI_POSTGRESQL = ON
-- SOCI_POSTGRESQL_TARGET = soci_postgresql
-- SOCI_POSTGRESQL_OUTPUT_NAME = soci_postgresql
-- SOCI_POSTGRESQL_COMPILE_DEFINITIONS = SOCI_ABI_VERSION="4.0" HAVE_DL=1 BOOST_ALL_NO_LIB
-- SOCI_POSTGRESQL_INCLUDE_DIRECTORIES = /usr/local/include /home/sujith/soci/build /home/sujith/soci/src/include /home/sujith/soci/build/include /home/sujith/soci/src/include/private /home/sujith/soci/src/include/private /usr/include/postgresql
-- SOCI_POSTGRESQL_NOPARAMS = OFF
-- SOCI_POSTGRESQL_NOBINDBYNAME = OFF
-- SOCI_POSTGRESQL_NOPREPARE = OFF
--
-- Configuring SOCI tests:
-- SOCI_EMPTY_TEST_CONNSTR = dummy
-- MS Access test disabled on non-Windows platform
-- SOCI_POSTGRESQL_TEST_CONNSTR = dbname=soci_test
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sujith/soci/build
sujith@sujith-VirtualBox:~/soci/build$
3)制作 4)构建我的代码
sujith@sujith-VirtualBox:~/soci/test$ pwd
/home/sujith/soci/test
sujith@sujith-VirtualBox:~/soci/test$ cat main.cpp
#include <iostream>
#include <stdlib.h>
#include <soci/soci.h>
#include <soci/postgresql/soci-postgresql.h>
#include <vector>
using namespace std;
int main(const int argc, const char** argv)
{
try
{
soci::session sql;
sql.open(soci::postgresql, "service=exd16 user=exd16 password=exd16");
return 0;
}
catch (exception const &e)
{
cerr << "ERROR : " << e.what() << endl;
}
return 0;
};
sujith@sujith-VirtualBox:~/soci/test$ cat c
g++ -ggdb -I /home/sujith/soci/src/include -I /home/sujith/soci/build/include -I /usr/include/postgresql -L /home/sujith/soci/build/lib -L /usr/local/pgsql/lib -lsoci_core -lsoci_empty -lpq -lsoci_postgresql -lsoci_empty main.cpp
sujith@sujith-VirtualBox:~/soci/test$ ./c
/tmp/ccLp881A.o: In function `main':
/home/sujith/soci/test/main.cpp:13: undefined reference to `soci::session::session()'
/home/sujith/soci/test/main.cpp:14: undefined reference to `soci::postgresql'
/home/sujith/soci/test/main.cpp:14: undefined reference to `soci::session::open(soci::backend_factory const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/sujith/soci/test/main.cpp:13: undefined reference to `soci::session::~session()'
/home/sujith/soci/test/main.cpp:13: undefined reference to `soci::session::~session()'
collect2: error: ld returned 1 exit status
sujith@sujith-VirtualBox:~/soci/test$
请帮我找到链接错误。
根据我的理解,我已经链接了所有必需的库。