I am using netbeans to develop a simple c++ program that uses boost serialization.
However when i try to compile the program i get a bunch of exceptions and errors:
CLEAN SUCCESSFUL (total time: 203ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/bernd/NetBeansProjects/LVAManager'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/lvamanager
make[2]: Entering directory `/home/bernd/NetBeansProjects/LVAManager'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/LVA.o.d
g++ -c -g -I/usr/include/boost -MMD -MP -MF build/Debug/GNU-Linux-x86/LVA.o.d -o build/Debug/GNU-Linux-x86/LVA.o LVA.cpp
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/Manager.o.d
g++ -c -g -I/usr/include/boost -MMD -MP -MF build/Debug/GNU-Linux-x86/Manager.o.d -o build/Debug/GNU-Linux-x86/Manager.o Manager.cpp
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -I/usr/include/boost -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/lvamanager build/Debug/GNU-Linux-x86/LVA.o build/Debug/GNU-Linux-x86/Manager.o build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::text_oarchive::text_oarchive(std::ostream&, unsigned int)':
/usr/include/boost/archive/text_oarchive.hpp:100: undefined reference to `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::ostream&, unsigned int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl()':
/usr/include/boost/archive/text_oarchive.hpp:85: undefined reference to `boost::archive::basic_text_oprimitive<std::ostream>::~basic_text_oprimitive()'
/usr/include/boost/archive/text_oarchive.hpp:85: undefined reference to `boost::archive::basic_text_oprimitive<std::ostream>::~basic_text_oprimitive()'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::~common_oarchive()':
/usr/include/boost/archive/detail/common_oarchive.hpp:35: undefined reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
build/Debug/GNU-Linux-x86/main.o:(.rodata._ZTIN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEEE[_ZTIN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEEE]+0x18): undefined reference to `typeinfo for boost::archive::detail::basic_oarchive'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::version_type>(boost::archive::text_oarchive&, boost::archive::version_type const&)':
/usr/include/boost/archive/detail/oserializer.hpp:87: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::object_id_type>(boost::archive::text_oarchive&, boost::archive::object_id_type const&)':
/usr/include/boost/archive/detail/oserializer.hpp:87: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::object_reference_type>(boost::archive::text_oarchive&, boost::archive::object_reference_type const&)':
/usr/include/boost/archive/detail/oserializer.hpp:87: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::class_id_type>(boost::archive::text_oarchive&, boost::archive::class_id_type const&)':
/usr/include/boost/archive/detail/oserializer.hpp:87: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::class_id_reference_type>(boost::archive::text_oarchive&, boost::archive::class_id_reference_type const&)':
/usr/include/boost/archive/detail/oserializer.hpp:87: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
build/Debug/GNU-Linux-x86/main.o:/usr/include/boost/archive/detail/oserializer.hpp:87: more undefined references to `boost::archive::detail::basic_oarchive::end_preamble()' follow
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::object_id_type>(boost::archive::object_id_type const&)':
/usr/include/boost/archive/text_oarchive.hpp:60: undefined reference to `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::object_reference_type>(boost::archive::object_reference_type const&)':
/usr/include/boost/archive/text_oarchive.hpp:60: undefined reference to `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::class_id_type>(boost::archive::class_id_type const&)':
/usr/include/boost/archive/text_oarchive.hpp:60: undefined reference to `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)':
/usr/include/boost/archive/text_oarchive.hpp:60: undefined reference to `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)':
/usr/include/boost/archive/text_oarchive.hpp:60: undefined reference to `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
build/Debug/GNU-Linux-x86/main.o:/usr/include/boost/archive/text_oarchive.hpp:60: more undefined references to `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()' follow
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::object_id_type>(boost::archive::object_id_type const&)':
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::object_reference_type>(boost::archive::object_reference_type const&)':
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::class_id_type>(boost::archive::class_id_type const&)':
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)':
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, std::string>(boost::archive::text_oarchive&, std::string const&)':
/usr/include/boost/archive/detail/oserializer.hpp:87: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
/usr/include/boost/archive/detail/oserializer.hpp:88: undefined reference to `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::string const&)'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)':
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::archive::basic_text_oprimitive<std::ostream>::save<unsigned int>(unsigned int const&)':
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to `boost::archive::archive_exception::~archive_exception()'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception const&)':
/usr/include/boost/archive/archive_exception.hpp:43: undefined reference to `vtable for boost::archive::archive_exception'
/usr/include/boost/archive/archive_exception.hpp:43: undefined reference to `vtable for boost::archive::archive_exception'
build/Debug/GNU-Linux-x86/main.o: In function `void boost::serialization::throw_exception<boost::archive::archive_exception>(boost::archive::archive_exception const&)':
/usr/include/boost/serialization/throw_exception.hpp:36: undefined reference to `boost::archive::archive_exception::~archive_exception()'
/usr/include/boost/serialization/throw_exception.hpp:36: undefined reference to `typeinfo for boost::archive::archive_exception'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/lvamanager] Error 1
make[2]: Leaving directory `/home/bernd/NetBeansProjects/LVAManager'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/bernd/NetBeansProjects/LVAManager'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 4s)
I read that boost serialization is no header-only library.
Has this something to do with this? Netbeans knows the boost library and gives me code assistance etc... But do i need to link it anyway?
How can i link the library in Netbeans? where can i find it.
I have a debian system and libboost-all-dev installed.
You need to add -lboost_serialization to you linker command.
It is a long time since I used netbeans but as far as I can remember it was something like Build->Linker->Libraries.
You don't need to add -l I think netbeans does this for you.
Related
This question already has an answer here:
Linking issue with GCC 4.6.1
(1 answer)
Closed 1 year ago.
I wanted to build a gtest project on linux using just a makefile, ie not using cmake. I followed along the tutorial here:
http://www.yolinux.com/TUTORIALS/Cpp-GoogleTest.html
But getting multiple definition of main errors - see below.
I am on ubuntu v20.04
angus#angus-VirtualBox:~/Documents/code/gtest_make_only/test/src$ uname -a
Linux angus-VirtualBox 5.11.0-38-generic #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
I installed gtest like this:
git clone https://github.com/google/googletest.git
mkdir build
cd build
sudo snap install cmake --classic
cmake .. -DBUILD_GMOCK=OFF
make
sudo make install
If I now look on my system I have
/usr/local/include - with gtest directory with header files
/usr/local/lib - contains libgtest.a and libgtest_main.a
I modified the Makefile in the example to be like this:
CXX = g++
CXXFLAGS = -g -L/usr/local/lib -lgtest -lgtest_main -lpthread
INCS = -I./ -I../../src -I/usr/local/include
OBJS = ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o
testAll: $(OBJS)
$(CXX) $(CXXFLAGS) $(INCS) -o testAll Main_TestAll.cpp $(OBJS)
.cpp.o:
$(CXX) $(CXXFLAGS) -c $< -o $# $(INCS)
clean:
rm testAll *.o testAll.xml
I also had to tidy up the code sample - eg where in code has Addition.h - have to change to Addition.hpp which is the filename.
The build error below. How to fix this?
I did try by removing -lgtest_main from the Makefile, but then get error:
/home/angus/Documents/code/gtest_make_only/test/src/Main_TestAll.cpp:5: undefined reference to `testing::InitGoogleTest(int*, char**)'
build error:
angus#angus-VirtualBox:~/Documents/code/gtest_make_only/test/src$ make
g++ -g -L/usr/local/lib -lgtest -lgtest_main -lpthread -c Multiply_Test.cpp -o Multiply_Test.o -I./ -I../../src -I/usr/local/include
g++ -g -L/usr/local/lib -lgtest -lgtest_main -lpthread -I./ -I../../src -I/usr/local/include -o testAll Main_TestAll.cpp ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o
/usr/bin/ld: /tmp/cc4xkhF1.o: in function `RUN_ALL_TESTS()':
/home/angus/Documents/code/gtest_make_only/test/src/Main_TestAll.cpp:4: multiple definition of `main'; /usr/local/lib/libgtest_main.a(gtest_main.cc.o):gtest_main.cc:(.text+0x0): first defined here
/usr/bin/ld: /usr/local/lib/libgtest_main.a(gtest_main.cc.o): in function `main':
gtest_main.cc:(.text+0x3a): undefined reference to `testing::InitGoogleTest(int*, char**)'
/usr/bin/ld: /usr/local/lib/libgtest_main.a(gtest_main.cc.o): in function `RUN_ALL_TESTS()':
gtest_main.cc:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x9): undefined reference to `testing::UnitTest::GetInstance()'
/usr/bin/ld: gtest_main.cc:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x11): undefined reference to `testing::UnitTest::Run()'
/usr/bin/ld: /tmp/cc4xkhF1.o: in function `main':
/home/angus/Documents/code/gtest_make_only/test/src/Main_TestAll.cpp:5: undefined reference to `testing::InitGoogleTest(int*, char**)'
/usr/bin/ld: Addition_Test.o: in function `AdditionTest_twoValues_Test::TestBody()':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:20: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:21: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: Addition_Test.o: in function `__static_initialization_and_destruction_0(int, int)':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:16: undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/usr/bin/ld: Addition_Test.o: in function `testing::internal::SuiteApiResolver<AdditionTest>::GetSetUpCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Addition_Test.o: in function `testing::internal::SuiteApiResolver<AdditionTest>::GetTearDownCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Addition_Test.o: in function `testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)':
/usr/local/include/gtest/gtest.h:1549: undefined reference to `testing::AssertionSuccess()'
/usr/bin/ld: Addition_Test.o: in function `testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&)':
/usr/local/include/gtest/gtest.h:1532: undefined reference to `testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/bin/ld: Addition_Test.o: in function `AdditionTest::~AdditionTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:5: undefined reference to `testing::Test::~Test()'
/usr/bin/ld: Addition_Test.o:(.data.rel.ro._ZTI12AdditionTest[_ZTI12AdditionTest]+0x10): undefined reference to `typeinfo for testing::Test'
/usr/bin/ld: Addition_Test.o: in function `AdditionTest::AdditionTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Addition_Test.cpp:5: undefined reference to `testing::Test::Test()'
/usr/bin/ld: Multiply_Test.o: in function `MultiplyTest_twoValues_Test::TestBody()':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:18: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:19: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: Multiply_Test.o: in function `__static_initialization_and_destruction_0(int, int)':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:14: undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/usr/bin/ld: Multiply_Test.o: in function `testing::internal::SuiteApiResolver<MultiplyTest>::GetSetUpCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:527: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Multiply_Test.o: in function `testing::internal::SuiteApiResolver<MultiplyTest>::GetTearDownCaseOrSuite(char const*, int)':
/usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/local/include/gtest/internal/gtest-internal.h:548: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: Multiply_Test.o: in function `MultiplyTest::~MultiplyTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:5: undefined reference to `testing::Test::~Test()'
/usr/bin/ld: Multiply_Test.o:(.data.rel.ro._ZTI12MultiplyTest[_ZTI12MultiplyTest]+0x10): undefined reference to `typeinfo for testing::Test'
/usr/bin/ld: Multiply_Test.o: in function `MultiplyTest::MultiplyTest()':
/home/angus/Documents/code/gtest_make_only/test/src/Multiply_Test.cpp:5: undefined reference to `testing::Test::Test()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:7: testAll] Error 1
Your command lines are all wrong.
Library specification should follow sources and object files. Correct line should look like this:
g++ -g -I./ -I../../src -o testAll Main_TestAll.cpp ../../src/Addition.o Addition_Test.o ../../src/Multiply.o Multiply_Test.o -lgtest_main -lgtest -lpthread
See this blog post for explanation.
I've just installed Poco on Ubuntu (by compiling from the code on the git master branch at release 1.9.0). And now I'm trying to compile my HelloWorld.cpp.
This is what I've tried:
g++ -L/usr/local/lib -lPocoFoundation -lPocoUtil -lPocoNet -lPocoNetd -lPocoData -lPocoXML ./helloworld.cpp
This is the helloworld.cpp content:
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Util/ServerApplication.h"
#include <iostream>
using namespace Poco;
using namespace Poco::Net;
using namespace Poco::Util;
class HelloRequestHandler: public HTTPRequestHandler
{
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
app.logger().information("Request from %s", request.clientAddress().toString());
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
response.send()
<< "<html>"
<< "<head><title>Hello</title></head>"
<< "<body><h1>Hello from the POCO Web Server</h1></body>"
<< "</html>";
}
};
class HelloRequestHandlerFactory: public HTTPRequestHandlerFactory
{
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest&)
{
return new HelloRequestHandler;
}
};
class WebServerApp: public ServerApplication
{
void initialize(Application& self)
{
loadConfiguration();
ServerApplication::initialize(self);
}
int main(const std::vector<std::string>&)
{
UInt16 port = static_cast<UInt16>(config().getUInt("port", 8080));
HTTPServer srv(new HelloRequestHandlerFactory, port);
srv.start();
logger().information("HTTP Server started on port %hu.", port);
waitForTerminationRequest();
logger().information("Stopping HTTP Server...");
srv.stop();
return Application::EXIT_OK;
}
};
POCO_SERVER_MAIN(WebServerApp)
I expect by keeping adding the libraries I link in the g++ command line it should eventually allow me to compile the program.
But it seems no matter how many libraries I tried to link I'm still getting the following errors (without eliminating any of the errors with how many libraries I add on the way):
kennyyu#kennyyu-ubuntu:~/poco/myexample$ g++ -L/usr/local/lib -lPocoFoundation -lPocoUtil -lPocoNet -lPocoNetd -lPocoData -lPocoXML ./helloworld.cpp
/tmp/ccWTd1HS.o: In function `main':
helloworld.cpp:(.text+0x53): undefined reference to `Poco::Util::ServerApplication::run(int, char**)'
helloworld.cpp:(.text+0xd1): undefined reference to `Poco::Exception::displayText[abi:cxx11]() const'
/tmp/ccWTd1HS.o: In function `Poco::Net::Impl::IPv4SocketAddressImpl::host() const':
helloworld.cpp:(.text._ZNK4Poco3Net4Impl21IPv4SocketAddressImpl4hostEv[_ZNK4Poco3Net4Impl21IPv4SocketAddressImpl4hostEv]+0x28): undefined reference to `Poco::Net::IPAddress::IPAddress(void const*, unsigned int)'
/tmp/ccWTd1HS.o: In function `Poco::Net::Impl::IPv6SocketAddressImpl::host() const':
helloworld.cpp:(.text._ZNK4Poco3Net4Impl21IPv6SocketAddressImpl4hostEv[_ZNK4Poco3Net4Impl21IPv6SocketAddressImpl4hostEv]+0x2e): undefined reference to `Poco::Net::IPAddress::IPAddress(void const*, unsigned int, unsigned int)'
/tmp/ccWTd1HS.o: In function `Poco::ReferenceCounter::ReferenceCounter()':
helloworld.cpp:(.text._ZN4Poco16ReferenceCounterC2Ev[_ZN4Poco16ReferenceCounterC5Ev]+0x19): undefined reference to `Poco::AtomicCounter::AtomicCounter(int)'
/tmp/ccWTd1HS.o: In function `Poco::Logger::log(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Poco::Message::Priority)':
helloworld.cpp:(.text._ZN4Poco6Logger3logERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_7Message8PriorityE[_ZN4Poco6Logger3logERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_7Message8PriorityE]+0xa0): undefined reference to `Poco::Message::Message(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Poco::Message::Priority)'
helloworld.cpp:(.text._ZN4Poco6Logger3logERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_7Message8PriorityE[_ZN4Poco6Logger3logERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_7Message8PriorityE]+0xbe): undefined reference to `Poco::Message::~Message()'
helloworld.cpp:(.text._ZN4Poco6Logger3logERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_7Message8PriorityE[_ZN4Poco6Logger3logERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_7Message8PriorityE]+0xd2): undefined reference to `Poco::Message::~Message()'
/tmp/ccWTd1HS.o: In function `Poco::Logger::information(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Poco::Any const&)':
helloworld.cpp:(.text._ZN4Poco6Logger11informationERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3AnyE[_ZN4Poco6Logger11informationERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3AnyE]+0x37): undefined reference to `Poco::format(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Poco::Any const&)'
/tmp/ccWTd1HS.o: In function `Poco::Util::Application::logger() const':
helloworld.cpp:(.text._ZNK4Poco4Util11Application6loggerEv[_ZNK4Poco4Util11Application6loggerEv]+0x30): undefined reference to `Poco::Bugcheck::nullPointer(char const*, char const*, int)'
/tmp/ccWTd1HS.o: In function `Poco::Util::Application::instance()':
helloworld.cpp:(.text._ZN4Poco4Util11Application8instanceEv[_ZN4Poco4Util11Application8instanceEv]+0x7): undefined reference to `Poco::Util::Application::_pInstance'
helloworld.cpp:(.text._ZN4Poco4Util11Application8instanceEv[_ZN4Poco4Util11Application8instanceEv]+0x24): undefined reference to `Poco::Bugcheck::nullPointer(char const*, char const*, int)'
helloworld.cpp:(.text._ZN4Poco4Util11Application8instanceEv[_ZN4Poco4Util11Application8instanceEv]+0x2b): undefined reference to `Poco::Util::Application::_pInstance'
/tmp/ccWTd1HS.o: In function `HelloRequestHandler::handleRequest(Poco::Net::HTTPServerRequest&, Poco::Net::HTTPServerResponse&)':
helloworld.cpp:(.text._ZN19HelloRequestHandler13handleRequestERN4Poco3Net17HTTPServerRequestERNS1_18HTTPServerResponseE[_ZN19HelloRequestHandler13handleRequestERN4Poco3Net17HTTPServerRequestERNS1_18HTTPServerResponseE]+0x73): undefined reference to `Poco::Net::SocketAddress::toString[abi:cxx11]() const'
helloworld.cpp:(.text._ZN19HelloRequestHandler13handleRequestERN4Poco3Net17HTTPServerRequestERNS1_18HTTPServerResponseE[_ZN19HelloRequestHandler13handleRequestERN4Poco3Net17HTTPServerRequestERNS1_18HTTPServerResponseE]+0x100): undefined reference to `Poco::Net::HTTPMessage::setChunkedTransferEncoding(bool)'
helloworld.cpp:(.text._ZN19HelloRequestHandler13handleRequestERN4Poco3Net17HTTPServerRequestERNS1_18HTTPServerResponseE[_ZN19HelloRequestHandler13handleRequestERN4Poco3Net17HTTPServerRequestERNS1_18HTTPServerResponseE]+0x139): undefined reference to `Poco::Net::HTTPMessage::setContentType(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccWTd1HS.o: In function `HelloRequestHandler::HelloRequestHandler()':
helloworld.cpp:(.text._ZN19HelloRequestHandlerC2Ev[_ZN19HelloRequestHandlerC5Ev]+0x14): undefined reference to `Poco::Net::HTTPRequestHandler::HTTPRequestHandler()'
/tmp/ccWTd1HS.o: In function `WebServerApp::initialize(Poco::Util::Application&)':
helloworld.cpp:(.text._ZN12WebServerApp10initializeERN4Poco4Util11ApplicationE[_ZN12WebServerApp10initializeERN4Poco4Util11ApplicationE]+0x1d): undefined reference to `Poco::Util::Application::loadConfiguration(int)'
helloworld.cpp:(.text._ZN12WebServerApp10initializeERN4Poco4Util11ApplicationE[_ZN12WebServerApp10initializeERN4Poco4Util11ApplicationE]+0x30): undefined reference to `Poco::Util::Application::initialize(Poco::Util::Application&)'
/tmp/ccWTd1HS.o: In function `HelloRequestHandlerFactory::HelloRequestHandlerFactory()':
helloworld.cpp:(.text._ZN26HelloRequestHandlerFactoryC2Ev[_ZN26HelloRequestHandlerFactoryC5Ev]+0x14): undefined reference to `Poco::Net::HTTPRequestHandlerFactory::HTTPRequestHandlerFactory()'
/tmp/ccWTd1HS.o: In function `WebServerApp::main(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)':
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x7c): undefined reference to `Poco::Util::AbstractConfiguration::getUInt(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int) const'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0xb6): undefined reference to `Poco::Net::HTTPServerParams::HTTPServerParams()'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x11d): undefined reference to `Poco::Net::HTTPServer::HTTPServer(Poco::SharedPtr<Poco::Net::HTTPRequestHandlerFactory, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Net::HTTPRequestHandlerFactory> >, unsigned short, Poco::AutoPtr<Poco::Net::HTTPServerParams>)'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x14a): undefined reference to `Poco::Net::TCPServer::start()'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x1f6): undefined reference to `Poco::Util::ServerApplication::waitForTerminationRequest()'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x273): undefined reference to `Poco::Net::TCPServer::stop()'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x287): undefined reference to `Poco::Net::HTTPServer::~HTTPServer()'
helloworld.cpp:(.text._ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE[_ZN12WebServerApp4mainERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE]+0x3a4): undefined reference to `Poco::Net::HTTPServer::~HTTPServer()'
/tmp/ccWTd1HS.o: In function `WebServerApp::WebServerApp()':
helloworld.cpp:(.text._ZN12WebServerAppC2Ev[_ZN12WebServerAppC5Ev]+0x14): undefined reference to `Poco::Util::ServerApplication::ServerApplication()'
/tmp/ccWTd1HS.o: In function `Poco::ReferenceCounter::~ReferenceCounter()':
helloworld.cpp:(.text._ZN4Poco16ReferenceCounterD2Ev[_ZN4Poco16ReferenceCounterD5Ev]+0x14): undefined reference to `Poco::AtomicCounter::~AtomicCounter()'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTV12WebServerApp[_ZTV12WebServerApp]+0x20): undefined reference to `Poco::Util::Application::name() const'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTV12WebServerApp[_ZTV12WebServerApp]+0x30): undefined reference to `Poco::Util::Application::uninitialize()'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTV12WebServerApp[_ZTV12WebServerApp]+0x38): undefined reference to `Poco::Util::Application::reinitialize(Poco::Util::Application&)'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTV12WebServerApp[_ZTV12WebServerApp]+0x40): undefined reference to `Poco::Util::ServerApplication::defineOptions(Poco::Util::OptionSet&)'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTV12WebServerApp[_ZTV12WebServerApp]+0x48): undefined reference to `Poco::Util::ServerApplication::run()'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTV12WebServerApp[_ZTV12WebServerApp]+0x50): undefined reference to `Poco::Util::Application::handleOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccWTd1HS.o: In function `WebServerApp::~WebServerApp()':
helloworld.cpp:(.text._ZN12WebServerAppD2Ev[_ZN12WebServerAppD5Ev]+0x22): undefined reference to `Poco::Util::ServerApplication::~ServerApplication()'
/tmp/ccWTd1HS.o: In function `HelloRequestHandlerFactory::~HelloRequestHandlerFactory()':
helloworld.cpp:(.text._ZN26HelloRequestHandlerFactoryD2Ev[_ZN26HelloRequestHandlerFactoryD5Ev]+0x22): undefined reference to `Poco::Net::HTTPRequestHandlerFactory::~HTTPRequestHandlerFactory()'
/tmp/ccWTd1HS.o: In function `HelloRequestHandler::~HelloRequestHandler()':
helloworld.cpp:(.text._ZN19HelloRequestHandlerD2Ev[_ZN19HelloRequestHandlerD5Ev]+0x22): undefined reference to `Poco::Net::HTTPRequestHandler::~HTTPRequestHandler()'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTVN4Poco3Net4Impl21IPv6SocketAddressImplE[_ZTVN4Poco3Net4Impl21IPv6SocketAddressImplE]+0x50): undefined reference to `Poco::Net::Impl::IPv6SocketAddressImpl::toString[abi:cxx11]() const'
/tmp/ccWTd1HS.o: In function `Poco::Net::Impl::IPv6SocketAddressImpl::~IPv6SocketAddressImpl()':
helloworld.cpp:(.text._ZN4Poco3Net4Impl21IPv6SocketAddressImplD2Ev[_ZN4Poco3Net4Impl21IPv6SocketAddressImplD5Ev]+0x22): undefined reference to `Poco::Net::Impl::SocketAddressImpl::~SocketAddressImpl()'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTVN4Poco3Net4Impl21IPv4SocketAddressImplE[_ZTVN4Poco3Net4Impl21IPv4SocketAddressImplE]+0x50): undefined reference to `Poco::Net::Impl::IPv4SocketAddressImpl::toString[abi:cxx11]() const'
/tmp/ccWTd1HS.o: In function `Poco::Net::Impl::IPv4SocketAddressImpl::~IPv4SocketAddressImpl()':
helloworld.cpp:(.text._ZN4Poco3Net4Impl21IPv4SocketAddressImplD2Ev[_ZN4Poco3Net4Impl21IPv4SocketAddressImplD5Ev]+0x22): undefined reference to `Poco::Net::Impl::SocketAddressImpl::~SocketAddressImpl()'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTI12WebServerApp[_ZTI12WebServerApp]+0x10): undefined reference to `typeinfo for Poco::Util::ServerApplication'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTI26HelloRequestHandlerFactory[_ZTI26HelloRequestHandlerFactory]+0x10): undefined reference to `typeinfo for Poco::Net::HTTPRequestHandlerFactory'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTI19HelloRequestHandler[_ZTI19HelloRequestHandler]+0x10): undefined reference to `typeinfo for Poco::Net::HTTPRequestHandler'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTIN4Poco3Net4Impl21IPv6SocketAddressImplE[_ZTIN4Poco3Net4Impl21IPv6SocketAddressImplE]+0x10): undefined reference to `typeinfo for Poco::Net::Impl::SocketAddressImpl'
/tmp/ccWTd1HS.o:(.data.rel.ro._ZTIN4Poco3Net4Impl21IPv4SocketAddressImplE[_ZTIN4Poco3Net4Impl21IPv4SocketAddressImplE]+0x10): undefined reference to `typeinfo for Poco::Net::Impl::SocketAddressImpl'
/tmp/ccWTd1HS.o:(.data.rel.local.DW.ref._ZTIN4Poco9ExceptionE[DW.ref._ZTIN4Poco9ExceptionE]+0x0): undefined reference to `typeinfo for Poco::Exception'
collect2: error: ld returned 1 exit status
kennyyu#kennyyu-ubuntu:~/poco/myexample$
kennyyu#kennyyu-ubuntu:~/poco/myexample$ ls /usr/local/lib/libPoco*.so
/usr/local/lib/libPocoCppParserd.so /usr/local/lib/libPocoDataMySQL.so /usr/local/lib/libPocoDataSQLited.so /usr/local/lib/libPocoFoundationd.so /usr/local/lib/libPocoMongoDBd.so /usr/local/lib/libPocoPDFd.so /usr/local/lib/libPocoUtild.so /usr/local/lib/libPocoZipd.so
/usr/local/lib/libPocoCppParser.so /usr/local/lib/libPocoDataODBCd.so /usr/local/lib/libPocoDataSQLite.so /usr/local/lib/libPocoFoundation.so /usr/local/lib/libPocoMongoDB.so /usr/local/lib/libPocoPDF.so /usr/local/lib/libPocoUtil.so /usr/local/lib/libPocoZip.so
/usr/local/lib/libPocoDatad.so /usr/local/lib/libPocoDataODBC.so /usr/local/lib/libPocoEncodingsd.so /usr/local/lib/libPocoJSONd.so /usr/local/lib/libPocoNetd.so /usr/local/lib/libPocoRedisd.so /usr/local/lib/libPocoXMLd.so
/usr/local/lib/libPocoDataMySQLd.so /usr/local/lib/libPocoData.so /usr/local/lib/libPocoEncodings.so /usr/local/lib/libPocoJSON.so /usr/local/lib/libPocoNet.so /usr/local/lib/libPocoRedis.so /usr/local/lib/libPocoXML.so
kennyyu#kennyyu-ubuntu:~/poco/myexample$
Can someone please shed me some light?
This worked for me in Ubuntu 19.10.
sudo apt install libpoco-dev
(All of the Poco libraries get installed with that.)
Create helloworld.cpp with contents from OP.
Compile with:
g++ helloworld.cpp -o helloworld.o -lPocoFoundation -lPocoNet -lPocoUtil
If that still doesn't work, you can include the location where the Poco .h files are with the -I option, and where the Poco .so files are with the -L option.
Find where the Poco .so files are located:
sudo find / -name "libPoco*.so" 2>/dev/null
/usr/lib/x86_64-linux-gnu/libPocoFoundation.so
...
sudo find / -name "ServerSocket.h" 2>/dev/null
/usr/include/Poco/Net/ServerSocket.h
The compile statement then becomes:
g++ -I/usr/include/Poco/ helloworld.cpp -o helloworld.o -L/usr/lib/x86_64-linux-gnu/ -lPocoFoundation -lPocoNet -lPocoUtil
I'm trying to configure and build a sample of node.js addon. The sample was taken from node.js documentation and the source code can be found here
https://github.com/nodejs/node-addon-examples/tree/master/8_passing_wrapped/node_0.12
When I try to compile this in CLion (on Ubuntu 14.04) or when I use node-gyp to build it I've got some errors:
/home/smorzhov/Documents/clion-2016.1/bin/cmake/bin/cmake --build /home/smorzhov/.CLion2016.1/system/cmake/generated/test4-94ee4803/94ee4803/Debug --target all -- -j 4
[ 25%] Linking CXX executable test4
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::Init(v8::Isolate*)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:26: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&), v8::Local<v8::Value>, v8::Local<v8::Signature>, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::FunctionTemplate::SetClassName(v8::Local<v8::String>)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::FunctionTemplate::InstanceTemplate()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::ObjectTemplate::SetInternalFieldCount(int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `v8::FunctionTemplate::GetFunction()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Function>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `Reset<v8::Function>':
/usr/include/node/v8.h:7235: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:38: undefined reference to `v8::Value::NumberValue() const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::PersistentBase<v8::Function> const&)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:47: undefined reference to `v8::Function::NewInstance(int, v8::Local<v8::Value>*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::PersistentBase<v8::Function> const&)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::NewInstance(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:57: undefined reference to `v8::Function::NewInstance(int, v8::Local<v8::Value>*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak<void>':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::Wrap(v8::Local<v8::Object>)':
/usr/include/node/node_object_wrap.h:56: undefined reference to `v8::Object::InternalFieldCount()'
/usr/include/node/node_object_wrap.h:57: undefined reference to `v8::Object::SetAlignedPointerInInternalField(int, void*)'
/usr/include/node/node_object_wrap.h:58: undefined reference to `v8::Isolate::GetCurrent()'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `SetWeak<v8::Object, node::ObjectWrap>':
/usr/include/node/v8.h:7257: undefined reference to `v8::V8::MakeWeak(v8::internal::Object**, void*, void (*)(v8::WeakCallbackData<v8::Value, void> const&))'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak<void>':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData<v8::Object, node::ObjectWrap> const&)':
/usr/include/node/node_object_wrap.h:101: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Object>::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData<v8::Object, node::ObjectWrap> const&)':
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::Add(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:27: undefined reference to `v8::Number::New(v8::Isolate*, double)'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::InitAll(v8::Local<v8::Object>)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:31: undefined reference to `v8::Object::GetIsolate()'
CMakeFiles/test4.dir/addon.cpp.o: In function `_register_addon':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:37: undefined reference to `node_module_register'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Value::ToObject() const':
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrentContext()'
/usr/include/node/v8.h:7779: undefined reference to `v8::Value::ToObject(v8::Local<v8::Context>) const'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::MyObject* node::ObjectWrap::Unwrap<demo::MyObject>(v8::Local<v8::Object>)':
/usr/include/node/node_object_wrap.h:29: undefined reference to `v8::Object::InternalFieldCount()'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Object::GetAlignedPointerFromInternalField(int)':
/usr/include/node/v8.h:7636: undefined reference to `v8::Object::SlowGetAlignedPointerFromInternalField(int)'
CMakeFiles/test4.dir/addon.cpp.o: In function `void node::NODE_SET_METHOD<v8::Local<v8::Object> >(v8::Local<v8::Object> const&, char const*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&))':
/usr/include/node/node.h:239: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/node.h:240: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
/usr/include/node/node.h:242: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&), v8::Local<v8::Value>, v8::Local<v8::Signature>, int)'
/usr/include/node/node.h:243: undefined reference to `v8::FunctionTemplate::GetFunction()'
/usr/include/node/node.h:244: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/usr/include/node/node.h:245: undefined reference to `v8::Function::SetName(v8::Local<v8::String>)'
/usr/include/node/node.h:246: undefined reference to `v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
collect2: error: ld returned 1 exit status
make[2]: *** [test4] Error 1
make[1]: *** [CMakeFiles/test4.dir/all] Error 2
make: *** [all] Error 2
Maybe it is important, the IDE don't understand
#include node.h
and I have to change it to #include node/node.h
It seems, that compiler sees only node and v8 headers and cannot find their sources.
Can somebody help me to fix that? How to make compiler to see node and v8 sources?
PS. My CmakeLists.txt file
cmake_minimum_required(VERSION 3.3)
project(test4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES addon.cpp main.cpp myobject.cpp myobject.h)
add_executable(test4 ${SOURCE_FILES})
If you follow the README and use node-gyp with the -v flag, you can see that compilation looks like this:
g++ '-DNODE_GYP_MODULE_NAME=addon' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/home/yannick/.node-gyp/5.9.0/include/node -I/home/yannick/.node-gyp/5.9.0/src -I/home/yannick/.node-gyp/5.9.0/deps/uv/include -I/home/yannick/.node-gyp/5.9.0/deps/v8/include -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/addon/myobject.o.d.raw -c -o Release/obj.target/addon/myobject.o ../myobject.cc
So it's a tad more complex that just specifying a few sources : there are several include dirs to be used, that seems specific to the node version you are running, and include an external dependency (libuv)
Why don't you use the build methods suggested by the README ?
When I start compiling the code with clang, it seems like libmongoclient doesn't exist. However, I compile the legacy version of mongo-cxx-client on this ubuntu machine. This code is working correctly on my Mac.
clang -lstdc++ -stdlib=libc++ -lcurl -lpthread -ljsoncpp -lboost_system -lboost_regex -lmongoclient -L/usr/lib main.o qqlogin.o fetcher.o -o qq_crawler
this is the code for linking. It didn't make any difference with or without the parameter -lmongoclient. I have already make sure it is under the correct path and the compile are able to search it.
main.o: In function `main':
main.cpp:(.text+0x3b): undefined reference to `mongo::client::Options::Options()'
main.cpp:(.text+0x4b): undefined reference to `mongo::client::GlobalInstance::GlobalInstance(mongo::client::Options const&)'
main.cpp:(.text+0x2d4): undefined reference to `mongo::client::GlobalInstance::~GlobalInstance()'
main.cpp:(.text+0x310): undefined reference to `mongo::client::GlobalInstance::~GlobalInstance()'
main.o: In function `thread_main(threadtool::Threadsafe_queue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*)':
main.cpp:(.text+0x343): undefined reference to `mongo::DBClientConnection::DBClientConnection(bool, mongo::DBClientReplicaSet*, double)'
main.o: In function `GCC_except_table14':
main.cpp:(.gcc_except_table+0x258): undefined reference to `typeinfo for mongo::DBException'
main.o: In function `mongo::DBClientConnection::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
main.cpp:(.text._ZN5mongo18DBClientConnection7connectERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo18DBClientConnection7connectERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x116): undefined reference to `mongo::HostAndPort::HostAndPort(mongo::StringData const&)'
main.o: In function `mongo::DBClientConnection::~DBClientConnection()':
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x12): undefined reference to `vtable for mongo::DBClientConnection'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x1d): undefined reference to `vtable for mongo::DBClientConnection'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x22): undefined reference to `mongo::DBClientConnection::_numConnections'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0xc4): undefined reference to `mongo::DBClientBase::~DBClientBase()'
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x15d): undefined reference to `mongo::DBClientBase::~DBClientBase()'
main.o: In function `mongo::DBException::~DBException()':
main.cpp:(.text._ZN5mongo11DBExceptionD2Ev[_ZN5mongo11DBExceptionD2Ev]+0xc): undefined reference to `vtable for mongo::DBException'
main.o: In function `mongo::UserException::UserException(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
main.cpp:(.text._ZN5mongo13UserExceptionC2EiRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo13UserExceptionC2EiRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x30): undefined reference to `vtable for mongo::UserException'
main.o: In function `mongo::DBException::addContext(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
main.cpp:(.text._ZN5mongo11DBException10addContextERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo11DBException10addContextERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x51): undefined reference to `mongo::causedBy(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
main.o: In function `mongo::DBException::DBException(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)':
main.cpp:(.text._ZN5mongo11DBExceptionC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi[_ZN5mongo11DBExceptionC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi]+0xf): undefined reference to `vtable for mongo::DBException'
main.o:(.rodata._ZTIN5mongo16ConnectExceptionE[_ZTIN5mongo16ConnectExceptionE]+0x10): undefined reference to `typeinfo for mongo::UserException'
main.o:(.rodata._ZTVN5mongo16ConnectExceptionE[_ZTVN5mongo16ConnectExceptionE]+0x30): undefined reference to `mongo::UserException::appendPrefix(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const'
main.o:(.rodata._ZTVN5mongo16ConnectExceptionE[_ZTVN5mongo16ConnectExceptionE]+0x40): undefined reference to `mongo::DBException::toString() const'
main.o:(.rodata._ZTVN5mongo18AssertionExceptionE[_ZTVN5mongo18AssertionExceptionE]+0x40): undefined reference to `mongo::DBException::toString() const'
main.o:(.rodata._ZTIN5mongo18AssertionExceptionE[_ZTIN5mongo18AssertionExceptionE]+0x10): undefined reference to `typeinfo for mongo::DBException'
fetcher.o: In function `fetch::Fetcher::parsed_json(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)':
fetcher.cpp:(.text+0x1e8c): undefined reference to `Json::Reader::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Json::Value&, bool)'
fetcher.o: In function `mongo::BSONObjBuilder::BSONObjBuilder(int)':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilderC2Ei[_ZN5mongo14BSONObjBuilderC2Ei]+0x4e): undefined reference to `mongo::BSONObjBuilderValueStream::BSONObjBuilderValueStream(mongo::BSONObjBuilder*)'
fetcher.o: In function `mongo::BSONObjBuilder::append(mongo::StringData const&, mongo::Date_t)':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder6appendERKNS_10StringDataENS_6Date_tE[_ZN5mongo14BSONObjBuilder6appendERKNS_10StringDataENS_6Date_tE]+0x29): undefined reference to `mongo::BSONObjBuilder::appendDate(mongo::StringData const&, mongo::Date_t)'
fetcher.o: In function `mongo::BSONObjBuilder::obj()':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder3objEv[_ZN5mongo14BSONObjBuilder3objEv]+0x4c): undefined reference to `mongo::msgasserted(int, char const*)'
fetcher.o: In function `mongo::BSONObjBuilder::_done()':
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder5_doneEv[_ZN5mongo14BSONObjBuilder5_doneEv]+0x62): undefined reference to `mongo::BSONObjBuilderValueStream::endField(mongo::StringData const&)'
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::claimReservedBytes(int)':
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE18claimReservedBytesEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE18claimReservedBytesEi]+0x52): undefined reference to `mongo::invariantFailed(char const*, char const*, unsigned int)'
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::grow_reallocate(int)':
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi]+0x663): undefined reference to `mongo::msgasserted(int, char const*)'
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi]+0x6ed): undefined reference to `mongo::msgasserted(int, char const*)'
fetcher.o: In function `mongo::checkFieldName(mongo::StringData)':
fetcher.cpp:(.text._ZN5mongo14checkFieldNameENS_10StringDataE[_ZN5mongo14checkFieldNameENS_10StringDataE]+0x56): undefined reference to `mongo::uasserted(int, char const*)'
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::_BufBuilder(int)':
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEEC2Ei[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEEC2Ei]+0x5e): undefined reference to `mongo::msgasserted(int, char const*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [qq_crawler] Error 1
Put your object files before the libraries:
clang -stdlib=libc++ main.o qqlogin.o fetcher.o -L/usr/lib -lcurl -lpthread
-ljsoncpp -lboost_system -lboost_regex -lmongoclient -o qq_crawler
I'm trying to work with the Boost Serialization libraries for some experimenting on upcoming projects
I know that the Boost Serialization library must be compiled separately from the rest of the projects/headers. I've installed a package for this on Ubuntu 10.04 including boost1.40-dev and the Serialization library, libboost-serialization1.40.0.
In my new Net Beans project, I tried a simple example to see if I could get things running. Here's the example:
/*
* File: main.C
* Author: Doug Swain
*
* Created on January 20, 2011, 11:05 AM
*/
#include <fstream>
#include <iostream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
int main() {
std::ofstream ofs("filename.xml");
boost::archive::xml_oarchive oa(ofs);
return 0;
}
And then here are the compiler errors:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/doug/BoostSerialization'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/boostserialization
make[2]: Entering directory `/home/doug/BoostSerialization'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -I/usr/include/boost/serialization -I/usr/include/boost -I/usr/include/boost/archive -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.C
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/boostserialization build/Debug/GNU-Linux-x86/main.o -L/usr/include/boost/serialization -L/usr/include/boost -L/usr/include/boost/archive
build/Debug/GNU-Linux-x86/main.o: In function `xml_oarchive':
/usr/include/boost/archive/xml_oarchive.hpp:100: undefined reference to `boost::archive::xml_oarchive_impl<boost::archive::xml_oarchive>::xml_oarchive_impl(std::basic_ostream<char, std::char_traits<char> >&, unsigned int)'
build/Debug/GNU-Linux-x86/main.o: In function `~xml_oarchive_impl':
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::~basic_xml_oarchive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::~basic_xml_oarchive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::~basic_xml_oarchive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
build/Debug/GNU-Linux-x86/main.o:(.rodata._ZTIN5boost7archive6detail15common_oarchiveINS0_12xml_oarchiveEEE[typeinfo for boost::archive::detail::common_oarchive<boost::archive::xml_oarchive>]+0x10): undefined reference to `typeinfo for boost::archive::detail::basic_oarchive'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::version_type const>(boost::archive::version_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::version_type const&, int)'
make[2]: Leaving directory `/home/doug/BoostSerialization'
make[1]: Leaving directory `/home/doug/BoostSerialization'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::object_id_type const>(boost::archive::object_id_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::object_id_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::object_reference_type const>(boost::archive::object_reference_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::object_reference_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_id_type const>(boost::archive::class_id_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_id_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_id_optional_type const>(boost::archive::class_id_optional_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_id_optional_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_id_reference_type const>(boost::archive::class_id_reference_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_id_reference_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_name_type const>(boost::archive::class_name_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_name_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::tracking_type const>(boost::archive::tracking_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::tracking_type const&, int)'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/boostserialization] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
I've verified that the headers do in fact exist (and NetBeans can find it prior to trying to build them). I've also made sure to update the include directories and the library directories to the best of my knowledge:
These are not compiler errors, but linker errors. You need to link in the Boost serialization library, probably called libboost_serialization.a or something along those lines.
More than including headers file from boost, you have to link to boost libraries to be able to use its functions.