This is probably trivial. I'm using Qt with the Tableau C++ api and I am having a bad time trying to get things to link appropriately.
I have the following directory structure.
allenh1#localhost ~/CS/tableau-api/tableau-qt
$ ls
bin include lib64 share src tableau-qt.pro ui
Here's the .pro file
QT += core gui widgets
CONFIG += c++14
TARGET = qt-tableau-demo
TEMPLATE = app
# Link with the Tableau SDK library files
QMAKE_RPATHDIR += lib64/tableausdk
SOURCES += src/main.cpp \
src/TableauTable.cpp
HEADERS += include/TableauTable.hpp
Note: the UI is not implemented yet, but will be after I get this to compile.
When I try to build it, I get the following:
allenh1#localhost ~/CS/tableau-api/tableau-qt
$ make
g++ -c -pipe -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../Qt/5.6/gcc_64/include -I../../../../Qt/5.6/gcc_64/include/QtWidgets -I../../../../Qt/5.6/gcc_64/include/QtGui -I../../../../Qt/5.6/gcc_64/include/QtCore -I. -I../../../../Qt/5.6/gcc_64/mkspecs/linux-g++ -o main.o src/main.cpp
In file included from src/../include/tableau-sdk/TableauExtract.hpp:18:0,
from src/../include/TableauTable.hpp:3,
from src/main.cpp:2:
src/../include/tableau-sdk/TableauCommon.hpp:144:38: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
const TAB_RESULT GetResultCode() const { return m_result; }
^
src/main.cpp:14:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[])
^
src/main.cpp:14:31: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char *argv[])
^
g++ -c -pipe -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../Qt/5.6/gcc_64/include -I../../../../Qt/5.6/gcc_64/include/QtWidgets -I../../../../Qt/5.6/gcc_64/include/QtGui -I../../../../Qt/5.6/gcc_64/include/QtCore -I. -I../../../../Qt/5.6/gcc_64/mkspecs/linux-g++ -o TableauTable.o src/TableauTable.cpp
In file included from src/../include/tableau-sdk/TableauExtract.hpp:18:0,
from src/../include/TableauTable.hpp:3,
from src/TableauTable.cpp:1:
src/../include/tableau-sdk/TableauCommon.hpp:144:38: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
const TAB_RESULT GetResultCode() const { return m_result; }
^
g++ -Wl,-O1 -Wl,-z,origin -Wl,-rpath,\$ORIGIN/lib64/tableausdk -Wl,-rpath,/home/allenh1/Qt/5.6/gcc_64/lib -o perscio-tableau-demo main.o TableauTable.o -L/home/allenh1/Qt/5.6/gcc_64/lib -lQt5Widgets -L/usr/lib64 -lQt5Gui -lQt5Core -lGL -lpthread
main.o: In function `fill_table(TableauTable*&)':
main.cpp:(.text+0x88): undefined reference to `bool TableauTable::add_column<std::type_info const&>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::type_info const&)'
main.cpp:(.text+0xc6): undefined reference to `bool TableauTable::add_column<std::type_info const&>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::type_info const&)'
main.cpp:(.text+0xfd): undefined reference to `bool TableauTable::add_column<std::type_info const&>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::type_info const&)'
TableauTable.o: In function `Tableau::(anonymous namespace)::MakeTableauString(wchar_t const*)':
TableauTable.cpp:(.text+0x48): undefined reference to `ToTableauString'
TableauTable.o: In function `TableauTable::TableauTable()':
TableauTable.cpp:(.text+0x1b0): undefined reference to `TabTableDefinitionCreate'
TableauTable.cpp:(.text+0x1ba): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text+0x1ef): undefined reference to `TabTableDefinitionSetDefaultCollation'
TableauTable.cpp:(.text+0x22d): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0x2a7): undefined reference to `TabGetLastErrorMessage'
TableauTable.o: In function `TableauTable::init(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >)':
TableauTable.cpp:(.text+0x42b): undefined reference to `TabExtractAPIInitialize'
TableauTable.cpp:(.text+0x434): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text+0x47f): undefined reference to `TabExtractCreate'
TableauTable.cpp:(.text+0x509): undefined reference to `TabExtractHasTable'
TableauTable.cpp:(.text+0x5ff): undefined reference to `TabTableDefinitionCreate'
TableauTable.cpp:(.text+0x65f): undefined reference to `TabExtractAddTable'
TableauTable.cpp:(.text+0x721): undefined reference to `TabTableDefinitionClose'
TableauTable.cpp:(.text+0x74b): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0x7f7): undefined reference to `TabExtractOpenTable'
TableauTable.cpp:(.text+0x8b9): undefined reference to `TabTableGetTableDefinition'
TableauTable.cpp:(.text+0x8c2): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text+0x8df): undefined reference to `TabTableDefinitionCreate'
TableauTable.cpp:(.text+0xd0e): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xe09): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xe78): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xef7): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xf97): undefined reference to `TabGetLastErrorMessage'
TableauTable.o:TableauTable.cpp:(.text+0xffa): more undefined references to `TabGetLastErrorMessage' follow
TableauTable.o: In function `std::_Sp_counted_ptr<Tableau::TableDefinition*, (__gnu_cxx::_Lock_policy)2>::_M_dispose()':
TableauTable.cpp:(.text._ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x2a): undefined reference to `TabTableDefinitionClose'
TableauTable.cpp:(.text._ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x33): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text._ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x76): undefined reference to `TabGetLastErrorMessage'
TableauTable.o: In function `Tableau::TableDefinition::Close()':
TableauTable.cpp:(.text._ZN7Tableau15TableDefinition5CloseEv[_ZN7Tableau15TableDefinition5CloseEv]+0x24): undefined reference to `TabTableDefinitionClose'
TableauTable.cpp:(.text._ZN7Tableau15TableDefinition5CloseEv[_ZN7Tableau15TableDefinition5CloseEv]+0x2d): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text._ZN7Tableau15TableDefinition5CloseEv[_ZN7Tableau15TableDefinition5CloseEv]+0x68): undefined reference to `TabGetLastErrorMessage'
collect2: error: ld returned 1 exit status
Makefile:200: recipe for target 'qt-tableau-demo' failed
make: *** [qt-tableau-demo] Error 1
The .so files needed (at least to my understanding) are located in the lib64 directory.
allenh1#localhost ~/CS/tableau-api/tableau-qt
$ ls lib64/tableausdk
Java libboost_thread.so libicuuc.so.44
libQt5Core.so.5 libboost_thread.so.1.56.0 libicuuc.so.44.0
libQt5Core.so.5.4.1 libcurl.so libmetrics2.so
libQt5Network.so.5 libcurl.so.4 libtabcrypto.so
libQt5Network.so.5.4.1 libcurl.so.4.4.0 libtabcrypto.so.1.0.0
libTableauCommon.so libexpat.so libtabssl.so
libTableauExtract.so libexpat.so.1 libtabssl.so.1.0.0
libTableauServer.so libexpat.so.1.6.0 libtabsys.so
libboost_chrono.so libicudata.so.44 libtabz.so
libboost_chrono.so.1.56.0 libicudata.so.44.0 libtabz.so.1
libboost_date_time.so libicui18n.so.44 libtabz.so.1.2.8
libboost_date_time.so.1.56.0 libicui18n.so.44.0 libtbb.so.2
libboost_system.so libicuio.so.44 libtbbmalloc.so.2
libboost_system.so.1.56.0 libicuio.so.44.0
Related
Hi guys I have a project in QT5 which must connect to a mariadb server using C ++, the problem is that when compiling with qmake it returns several undefined reference errors with everything related to :: sql.
:-1: error: main.o: in function `printContacts(std::shared_ptr<sql::Statement>&)':
../test_server/main.cpp:12: error: undefined reference to `sql::SQLString::SQLString(char const*)'
../test_server/main.cpp:16: undefined reference to `sql::operator<<(std::ostream&, sql::SQLString const&)'
:-1: error: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::~pair()':
/usr/include/c++/11/bits/stl_pair.h:211: error: undefined reference to `sql::SQLString::~SQLString()'
:-1: error: /usr/include/c++/11/bits/stl_pair.h:211: undefined reference to `sql::SQLString::~SQLString()'
:-1: error: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair<char const (&) [5], char const (&) [8], true>(char const (&) [5], char const (&) [8])':
When compiling with g ++ directly from the console, it compiles without problems by passing the libraries as parameters, excluding the library in the main.cpp file.
g++ -o test_server main.cpp -std=c++11 -lmariadbcpp
In the .pro file I have created the link to the mariadb libraries that I have installed without any problem.
test_server.pro.
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += \
main.cpp
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
unix:CONFIG(release, debug|release): LIBS += -L/usr/lib64 -lmariadbcpp
unix {
INCLUDEPATH += /usr/include/mariadb -I..include
DEPENDPATH += /usr/include/mariadb -I..include
}
In the main function the following code: main.cpp
#include <QCoreApplication>
#include <iostream>
#include <mariadb/conncpp.hpp>
void printContacts(std::shared_ptr<sql::Statement> &stmnt)
{
try
{
std::unique_ptr<sql::ResultSet> res(
stmnt->executeQuery("SHOW DATABASES")
);
while (res->next())
{
std::cout << "- "
<< res->getString(1)
<< " " << std::endl;
}
}
catch (sql::SQLException& e)
{
std::cerr << "Error printing contacts: "
<< e.what() << std::endl;
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
try
{
sql::Driver* driver = sql::mariadb::get_driver_instance();
sql::SQLString url("jdbc:mariadb://127.0.0.1:3306/bt");
sql::Properties properties({
{"user", "mysuser"},
{"password", "mypassword"}
});
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
std::shared_ptr<sql::Statement> stmnt(conn->createStatement());
printContacts(stmnt);
conn->close();
}
catch (sql::SQLException &e)
{
std::cerr << "Error Connecting to MariaDB Platform: "
<< e.what() << std::endl;
return 1;
}
return a.exec();
}
Build output
22:08:05: Running steps for project test_server...
22:08:05: Configuration unchanged, skipping qmake step.
22:08:05: Starting: "/usr/bin/make" -j4
g++ -c -pipe -g -std=gnu++11 -Wall -Wextra -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_CORE_LIB -I../test_server -I. -I/usr/include/mariadb -I-I..include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I. -I/../lib64/qt5/mkspecs/linux-g++ -o main.o ../test_server/main.cpp
g++ -o test_server main.o /usr/lib64/libQt5Core.so -lpthread
/usr/bin/ld: main.o: in function `printContacts(std::shared_ptr<sql::Statement>&)':
/home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:12: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:12: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:16: undefined reference to `sql::operator<<(std::ostream&, sql::SQLString const&)'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:16: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:25: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:16: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `main':
/home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:34: undefined reference to `sql::mariadb::get_driver_instance()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:35: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:44: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /home/chls/Documentos/Mayoreo/Mayoreo/build-test_server-Desktop-Debug/../test_server/main.cpp:44: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::~pair()':
/usr/include/c++/11/bits/stl_pair.h:211: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:211: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair<char const (&) [5], char const (&) [8], true>(char const (&) [5], char const (&) [8])':
/usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair<char const (&) [9], char const (&) [11], true>(char const (&) [9], char const (&) [11])':
/usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::SQLString(char const*)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:353: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o: in function `std::less<sql::SQLString>::operator()(sql::SQLString const&, sql::SQLString const&) const':
/usr/include/c++/11/bits/stl_function.h:386: undefined reference to `sql::SQLString::operator<(sql::SQLString const&) const'
/usr/bin/ld: main.o: in function `std::pair<sql::SQLString const, sql::SQLString>::pair(std::pair<sql::SQLString const, sql::SQLString> const&)':
/usr/include/c++/11/bits/stl_pair.h:314: undefined reference to `sql::SQLString::SQLString(sql::SQLString const&)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:314: undefined reference to `sql::SQLString::SQLString(sql::SQLString const&)'
/usr/bin/ld: /usr/include/c++/11/bits/stl_pair.h:314: undefined reference to `sql::SQLString::~SQLString()'
/usr/bin/ld: main.o:(.data.rel.local.DW.ref._ZTIN3sql12SQLExceptionE[DW.ref._ZTIN3sql12SQLExceptionE]+0x0): undefined reference to `typeinfo for sql::SQLException'
collect2: error: ld returned 1 exit status
make: *** [Makefile:143: test_server] Error 1
22:08:05: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test_server (kit: Desktop)
When executing step "Make"
22:08:05: Elapsed time: 00:00.
I use the example code from mongodb site to show the problem here. OS: ArchLiux, c++ is a link to g++
[dean#dell_xps_13 ~]$ c++ --version c++ (GCC) 6.2.1 20160830 Copyright
(C) 2016 Free Software Foundation, Inc. This is free software; see the
source for copying conditions. There is NO warranty; not even for
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
code is in test.cc file
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
First compile it to object file:
c++ -g -std=c++11 -I../include -I/usr/include/bsoncxx/v_noabi
-I/usr/include/mongocxx/v_noabi -Wall -o test.o -c ./test.cc
Link it without -static works:
c++ test.o -o test -static-libgcc -static-libstdc++ -L/usr/lib
-lpthread -lmongocxx -lbsoncxx -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lboost_filesystem
This can run and print out some messages:
[dean#dell_xps_13 mongo-cxx-driver-r3.0.2]$ ./test
{
"_id" : {
"$oid" : "58218e821b489308ae4411d1"
},
"hello" : "world"
}
Now get error with -static option
c++ test.o -o test -static-libgcc -static-libstdc++ -static
-L/usr/lib -lpthread -lmongocxx -lbsoncxx -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lboost_filesystem
Many error messages show below:
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&,
mongocxx::v_noabi::options::client const&)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x28):
undefined reference tomongoc_client_new_from_uri'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x10c):
undefined reference to mongoc_client_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::operator=(mongocxx::v_noabi::client&&)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x190):
undefined reference to mongoc_client_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::~client()':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x1c3):
undefined reference to mongoc_client_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_concern(mongocxx::v_noabi::read_concern)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x214):
undefined reference to mongoc_client_set_read_concern'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_concern() const':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x243):
undefined reference to mongoc_client_get_read_concern'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x24b):
undefined reference tomongoc_read_concern_copy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x27c):
undefined reference to mongoc_read_concern_destroy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x2a3):
undefined reference tomongoc_read_concern_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_preference(mongocxx::v_noabi::read_preference)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3a4):
undefined reference tomongoc_client_set_read_prefs'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_preference() const':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3c3):
undefined reference tomongoc_client_get_read_prefs'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3cb):
undefined reference to mongoc_read_prefs_copy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3fc):
undefined reference tomongoc_read_prefs_destroy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x423):
undefined reference to mongoc_read_prefs_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::uri() const':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x463):
undefined reference to mongoc_client_get_uri'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x46b):
undefined reference tomongoc_uri_copy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x49c):
undefined reference to mongoc_uri_destroy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x4c3):
undefined reference tomongoc_uri_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::write_concern(mongocxx::v_noabi::write_concern)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x504):
undefined reference tomongoc_client_set_write_concern'
/usr/lib/libmongocxx.a(client.cpp.o): In function
`mongocxx::v_noabi::client::write_concern() const':
....
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::oid::to_string[abi:cxx11]() const':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x139):
undefined reference tobson_oid_to_string'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::oid::get_time_t() const':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x1ea):
undefined reference tobson_oid_get_time_t'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::oid_compare(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x24f):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator<(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x2af):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator>(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x30f):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator<=(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x36f):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator>=(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x3cf):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o):/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x42f):
more undefined references to `bson_oid_compare' follow collect2:
error: ld returned 1 exit status
The -static flag forces the linker to accept only static libraries and not any shared libraries. In other words it does not require a dependency on dynamic libraries at runtime in order to run.
Most likely mongocxx has some dependencies.
To achieve static linking requires that the archive (.a) versions of your libraries exist on the system.
The another possible issue is that the order of static libraries in the linker command line does matter, so that might also be an issue if there is a dependency on different static libs. The linker will process the libraries in order as they are in the command line, and from each static lib it will only pull those symbols that are required (with as much information as the linker has at that time)
Use nm . That will give you the symbol names.
I need to include dlib in a c++ project. I have properly linked the library in my Makefile. Here is the Makefile:
EXE = face_frontalization
OBJ_DIR = bin
CFLAGS = -g -w
# CXXFLAGS = -w -Wall -Wextra -g -std=c++0x
# LDFLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lSDL2_gfx -lm
dummy_build_folder := $(shell mkdir -p $(OBJ_DIR))
# c++ source files of the project
CXXFILES = $(shell find src -type f -name '*.cpp')
CXXOBJ = $(patsubst src/%.cpp,bin/%.o,$(CXXFILES))
INCLUDE = -I/usr/include/dlib-18.18
LIBS = `pkg-config --libs opencv`
CXXFLAGS = `pkg-config --cflags opencv` -w -Wall -Wextra -g -std=c++0x
LDFLAGS = -lcurl
CFLAGS = `pkg-config --cflags opencv` -g -w
MKDIR = mkdir -p
ifdef V
MUTE =
VTAG = -v
else
MUTE = #
endif
###################################################################
# This is a Makefile progress indicator.
# BUILD is initially undefined
ifndef BUILD
# max equals 256 x's
sixteen := x x x x x x x x x x x x x x x x
MAX := $(foreach x,$(sixteen),$(sixteen))
# T estimates how many targets we are building by replacing BUILD with
# a special string
T := $(shell $(MAKE) -nrRf $(firstword $(MAKEFILE_LIST)) $(MAKECMDGOALS) \
BUILD="COUNTTHIS" | grep -c "COUNTTHIS")
# N is the number of pending targets in base 1, well in fact, base x
# :-)
N := $(wordlist 1,$T,$(MAX))
# auto-decrementing counter that returns the number of pending targets
# in base 10
counter = $(words $N)$(eval N := $(wordlist 2,$(words $N),$N))
# BUILD is now defined to show the progress, this also avoids
# redefining T in loop
BUILD = #echo $(counter) of $(T)
endif
###################################################################
# .PHONY: directories all
#
# directories: ${OUT_DIR}
# ${OUT_DIR}:
# ${MKDIR} ${OUT_DIR}
all: $(EXE)
# build successful
$(EXE): $(CXXOBJ)
$(CXX) $(CXXOBJ) -o $(EXE) $(LIBS) $(LDFLAGS)
$(OBJ_DIR)/%.o: src/%.cpp
$(CXX) $(CXXFLAGS) $(INCLUDE) $< -c -o $#
$(BUILD)
$(OBJ_DIR)/%.o: src/%.c
$(CC) $(CFLAGS) $(INCLUDE) $< -c -o $#
run: all
./$(EXE)
clean:
# Cleaning...
-rm -f $(EXE) $(CXXOBJ)
rmdir bin/
I dont know why but its giving errors on compilation. I have compiled the dlib library itself too and the code examples are running as they should.
The error I am getting is:
bin/fatialfeaturedetect.o: In function `fatial_feature_detector()':
/home/playroom/Desktop/face-frontalization/src/fatialfeaturedetect.cpp:20: undefined reference to `dlib::base_window::wait_until_closed() const'
/home/playroom/Desktop/face-frontalization/src/fatialfeaturedetect.cpp:18: undefined reference to `dlib::image_window::~image_window()'
/home/playroom/Desktop/face-frontalization/src/fatialfeaturedetect.cpp:18: undefined reference to `dlib::image_window::~image_window()'
bin/fatialfeaturedetect.o: In function `dlib::get_serialized_frontal_faces()':
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:115: undefined reference to `dlib::base64::base64()'
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:2358: undefined reference to `dlib::base64::decode(std::istream&, std::ostream&) const'
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:2367: undefined reference to `dlib::base64::~base64()'
/usr/include/dlib-18.18/dlib/image_processing/frontal_face_detector.h:2367: undefined reference to `dlib::base64::~base64()'
bin/fatialfeaturedetect.o: In function `dlib_check_consistent_assert_usage':
/usr/include/dlib-18.18/dlib/gui_widgets/../gui_core/../threads/threads_kernel_shared.h:44: undefined reference to `USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_'
bin/fatialfeaturedetect.o: In function `dlib::drawable_window::drawable_window(bool, bool)':
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:79: undefined reference to `dlib::base_window::base_window(bool, bool)'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:79: undefined reference to `vtable for dlib::drawable_window'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:79: undefined reference to `dlib::base_window::~base_window()'
bin/fatialfeaturedetect.o: In function `dlib::drawable_window::~drawable_window()':
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:195: undefined reference to `vtable for dlib::drawable_window'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:195: undefined reference to `dlib::base_window::close_window()'
/usr/include/dlib-18.18/dlib/gui_widgets/drawable.h:195: undefined reference to `dlib::base_window::~base_window()'
bin/fatialfeaturedetect.o: In function `dlib::scrollable_region_style_default::draw_scrollable_region_border(dlib::canvas const&, dlib::rectangle const&, bool) const':
/usr/include/dlib-18.18/dlib/gui_widgets/style.h:527: undefined reference to `dlib::draw_sunken_rectangle(dlib::canvas const&, dlib::rectangle const&, unsigned char)'
bin/fatialfeaturedetect.o: In function `dlib::image_display::disable_overlay_editing()':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3485: undefined reference to `dlib::base_window::invalidate_rectangle(dlib::rectangle const&)'
bin/fatialfeaturedetect.o: In function `dlib::compress_stream_kernel_1<dlib::entropy_encoder_model_kernel_5<257ul, dlib::entropy_encoder_kernel_2, 200000ul, 4ul>, dlib::entropy_decoder_model_kernel_5<257ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>, dlib::crc32>::decompress(std::istream&, std::ostream&) const':
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:180: undefined reference to `dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:181: undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:196: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:201: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:243: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_processing/../compress_stream/compress_stream_kernel_1.h:243: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
bin/fatialfeaturedetect.o: In function `void dlib::image_window::add_overlay<dlib::rgb_pixel>(std::vector<dlib::rectangle, std::allocator<dlib::rectangle> > const&, dlib::rgb_pixel)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3968: undefined reference to `dlib::image_window::add_overlay(std::vector<dlib::image_display::overlay_rect, std::allocator<dlib::image_display::overlay_rect> > const&)'
bin/fatialfeaturedetect.o: In function `dlib::image_window::image_window<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > const&)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3883: undefined reference to `vtable for dlib::image_window'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3883: undefined reference to `dlib::image_display::image_display(dlib::drawable_window&)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3885: undefined reference to `dlib::image_window::on_image_clicked(dlib::vector<long, 2l> const&, bool, unsigned long)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3888: undefined reference to `dlib::base_window::show()'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3883: undefined reference to `dlib::image_display::~image_display()'
bin/fatialfeaturedetect.o: In function `dlib::entropy_decoder_model_kernel_5<257ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:422: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:456: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:503: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:551: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:553: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
bin/fatialfeaturedetect.o: In function `void dlib::image_window::set_image<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > const&)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3930: undefined reference to `dlib::image_display::get_image_display_rect() const'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3934: undefined reference to `dlib::base_window::set_size(int, int)'
bin/fatialfeaturedetect.o: In function `void dlib::load_dng<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> >&, std::istream&)':
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:585: undefined reference to `dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:586: undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:757: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:771: undefined reference to `dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:772: undefined reference to `dlib::entropy_decoder_kernel_2::set_stream(std::istream&)'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:771: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:757: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
/usr/include/dlib-18.18/dlib/image_loader/image_loader.h:771: undefined reference to `dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()'
bin/fatialfeaturedetect.o: In function `void dlib::image_display::set_image<dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<dlib::rgb_pixel, dlib::memory_manager_stateless_kernel_1<char> > const&)':
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3272: undefined reference to `dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3274: undefined reference to `dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3278: undefined reference to `dlib::base_window::invalidate_rectangle(dlib::rectangle const&)'
/usr/include/dlib-18.18/dlib/gui_widgets/widgets.h:3283: undefined reference to `dlib::popup_menu_region::disable()'
bin/fatialfeaturedetect.o: In function `dlib::entropy_decoder_model_kernel_5<256ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:422: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:456: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:503: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:551: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_5.h:553: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
bin/fatialfeaturedetect.o: In function `dlib::entropy_decoder_model_kernel_4<256ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>::decode(unsigned long&)':
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:348: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:376: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:422: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:469: undefined reference to `dlib::entropy_decoder_kernel_2::get_target(unsigned int)'
/usr/include/dlib-18.18/dlib/image_processing/../entropy_decoder_model/entropy_decoder_model_kernel_4.h:471: undefined reference to `dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)'
collect2: error: ld returned 1 exit status
make: *** [face_frontalization] Error 1
I cant figure out what I have done in linking the library to the project. Please help.
Dlib is partially header-based and some functions need to have libdlib.a linked to a project
You have two ways how to solve your problem:
link to dlib: LDFLAGS = -ldlib (dlib should be installed or its path provided to linker)
add dlib/all/source.cpp to your project sources list(CXXFILES)
If this error is present during compilation with dLib:
/usr/bin/ld: /tmp/ccps6CPH.o: undefined reference to symbol 'pthread_create##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status make: *** [face_frontalization] Error 1
There is a good probability that X11 is missing. I dont know what it is so if somebody does, please tell me. Solution is to just add -lX11 to the LDFLAGS in order to link with it. If you dont want it, you can also specify compiler option -DDLIB_NO_GUI_SUPPORT.
(NOTE: I haven't tested it and dont know what X11 does so better include it than exclude it.)
I've used the already compiled version of openCV for Raspberry Pi. link for anyone who is interested
After trying to compile using this command line
g++ test3.cpp -o test3 -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lopencv_core -lopencv_highgui -lopencv_imgproc -lwiringPi -lpthread
I get the following error lines.
//usr/local/lib/libopencv_stitching.so.2.4: undefined reference to `cv::gpu::ensureSizeIsEnough(int, int, int, cv::gpu::GpuMat&)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody const&, double)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `typeinfo for cv::ParallelLoopBody'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::unlock()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::lock()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to cv::TLSDataContainer::getData() const
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, unsigned char&, bool, unsigned char (cv::Algorithm::)(), void (cv::Algorithm::)(unsigned char), std::basic_string, std::allocator > const&)
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to `cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, float&, bool, float (cv::Algorithm::)(), void (cv::Algorithm::)(float), std::basic_string, std::allocator > const&)'
//usr/local/lib/libopencv_features2d.so.2.4: undefined reference to `cv::AlgorithmInfo::addParam(cv::Algorithm&, char const*, short&, bool, int (cv::Algorithm::)(), void (cv::Algorithm::)(int), std::basic_string, std::allocator > const&)'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::Mutex()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to `cv::TLSDataContainer::TLSDataContainer()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::ParallelLoopBody::~ParallelLoopBody()'
//usr/local/lib/libopencv_calib3d.so.2.4: undefined reference to `cv::Mutex::~Mutex()'
//usr/local/lib/libopencv_ocl.so.2.4: undefined reference to `cv::TLSDataContainer::~TLSDataContainer()'
collect2: ld returned 1 exit status
You have not linked the executable against several libraries that are required by the program
Try using this:
g++ -lpthread `pkg-config opencv --libs` -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lwiringPi test3.cpp -o test3
I am trying to test boost python with example in official website.
But It incurs so many errors...
The below is my what i did and the errors.
Download Boost1.55 with this.
Add Eclipse library search path to "usr/includ" (boost directory place at here)
Add library flag -lpython2.7 (Python2.7 is installed)
Add include path usr/include/python2.7(at my first try, the error happen : couldn't find pyconfig.h)
And this is my test code i did, and errors, the test code was only to see if it is compiled normally with boost python.
#include <iostream>
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
int main(){
std::cout << "aaa" << std::endl;
}
.
The Error part denoted with redline in eclipse is BOOST_PYTHON_MODULE(hello_ext)
**** Build of configuration Debug for project tsetBoost ****
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/python2.7 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: tsetBoost
Invoking: GCC C++ Linker
g++ -L/usr/include -o"tsetBoost" ./main.o -lpython2.7
./main.o: In function `inithello_ext':
/home/kim/workspace/tsetBoost/Debug/../main.cpp:16: undefined reference to `boost::python::detail::init_module(char const*, void (*)())'
./main.o: In function `boost::python::type_info::name() const':
/usr/local/include/boost/python/type_id.hpp:165: undefined reference to `boost::python::detail::gcc_demangle(char const*)'
./main.o: In function `boost::python::to_python_value<char const* const&>::operator()(char const* const&) const':
/usr/local/include/boost/python/converter/builtin_converters.hpp:161: undefined reference to `boost::python::converter::do_return_to_python(char const*)'
./main.o: In function `void boost::python::def<char const* (*)()>(char const*, char const* (*)())':
/usr/local/include/boost/python/def.hpp:91: undefined reference to `boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)'
./main.o: In function `boost::python::api::object boost::python::detail::make_function_aux<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> >(char const* (*)(), boost::python::default_call_policies const&, boost::mpl::vector1<char const*> const&)':
/usr/local/include/boost/python/make_function.hpp:38: undefined reference to `boost::python::objects::function_object(boost::python::objects::py_function const&)'
./main.o: In function `py_function_impl_base':
/usr/local/include/boost/python/object/py_function.hpp:20: undefined reference to `vtable for boost::python::objects::py_function_impl_base'
./main.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[vtable for boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
./main.o: In function `~caller_py_function_impl':
/usr/local/include/boost/python/object/py_function.hpp:30: undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
./main.o:(.rodata._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[typeinfo for boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
./main.o: In function `boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype()':
/usr/local/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/local/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
collect2: ld returned 1 exit status
make: *** [tsetBoost] ERROR 1
I added two additional flags for boost and then it works !!
-lboost_python -lboost_system