Compiling Boost Blocking TCP Echo Client - c++

I am trying to compile The example of Blocking TCP echo client: using the Boost.build b2 command as following:
b2 linkflags=-lpthread toolset=gcc threading=multi link=static
But I am getting the following errors:
gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/lte_sim
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&)':
/home/ha/MIH/boost_1_49_0/boost/asio/detail/impl/socket_ops.ipp:2899: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `__static_initialization_and_destruction_0(int, int)':
Simulator_main.cpp:(.text+0x68f): undefined reference to `boost::system::generic_category()'
Simulator_main.cpp:(.text+0x69b): undefined reference to `boost::system::generic_category()'
Simulator_main.cpp:(.text+0x6a7): undefined reference to `boost::system::system_category()'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `boost::system::error_code::error_code()':
Simulator_main.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `boost::asio::error::get_system_category()':
Simulator_main.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::clear<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event5clearINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::clear<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::wait<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event4waitINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::wait<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::signal<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event6signalINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::signal<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::signal_and_unlock<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event17signal_and_unlockINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::signal_and_unlock<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
collect2: ld returned 1 exit status
"g++" -o "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/lte_sim" -Wl,--start-group "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o" "/home/ha/MIH/boost_1_49_0/bin.v2/libs/program_options/build/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/libboost_program_options.a" -lrt -Wl,--end-group -g -static -pthread -lpthread
...failed gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/lte_sim...
...skipped <p../../dist>lte_sim for lack of <p../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi>lte_sim...
...failed updating 1 target...
...skipped 1 target..
I already have a JamFile with the contents:
install install
: lte_sim
: <location>../../dist
;
project lte_sim
;
exe lte_sim
: Simulator_main.cpp
/boost//program_options
;
So what is the solution for the problem?
Thanks a lot.
I tried "b2 linkflags=-lboost_system toolset=gcc" and I got the following errors
gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/lte_sim
/usr/bin/ld: cannot find -lboost_system
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/Simulator_main.o: In function `boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&)':
/home/ha/MIH/boost_1_49_0/boost/asio/detail/impl/socket_ops.ipp:2899: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: ld returned 1 exit status
"g++" -o "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/lte_sim" -Wl,--start-group "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/Simulator_main.o" "/home/ha/MIH/boost_1_49_0/bin.v2/libs/program_options/build/gcc-4.6/debug/link-static/runtime-link-static/libboost_program_options.a" -Wl,--end-group -g -static -lboost_system
...failed gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/lte_sim...
...skipped lte_sim for lack of lte_sim...
...failed updating 1 target...
...skipped 1 target...
So any suggestions?

Related

Undefined reference error while compiling lzma sdk

while compiling my cpp program for pop os using 7-zip lzma sdk i encounter the following errors
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000001410
/usr/bin/ld: Aes.o: in function 'AesGenTables':
/home/hitesh/lzma2201/C/Aes.c:130: undefined reference to 'AesCbc_Decode_HW'
/usr/bin/ld: /home/hitesh/lzma2201/C/Aes.c:133: undefined reference to 'AesCbc_Encode_HW'
/usr/bin/ld: /home/hitesh/lzma2201/C/Aes.c:134: undefined reference to 'AesCtr_Code_HW'
/usr/bin/ld: /home/hitesh/lzma2201/C/Aes.c:142: undefined reference to 'AesCbc_Decode_HW_256'
/usr/bin/ld: /home/hitesh/lzma2201/C/Aes.c:144: undefined reference to 'AesCtr_Code_HW_256'
/usr/bin/ld: LzFindMt.o: in function 'BtGetMatches(_CMatchFinderMt*, unsigned int*)':
/home/hitesh/lzma2201/C/LzFindMt.c:686: undefined reference to 'GetMatchesSpecN_2(unsigned char const*, unsigned long, unsigned char const*, unsigned int*, unsigned int, unsigned int*, unsigned long, unsigned int const*, unsigned int const*, unsigned int const*, unsigned long, unsigned int, unsigned int*)'
/usr/bin/ld: Sha256.o: in function 'Sha256Prepare':
/home/hitesh/lzma2201/C/Sha256.c:481: undefined reference to 'Sha256_UpdateBlocks_HW(unsigned int*, unsigned char const*, unsigned long)'
collect2: error: ld returned 1 exit status
here is the script used to compile the program.
run2.sh
for FILE in $(ls "/home/hitesh/lzma2201/C" | egrep '\.c$');
do
g++ -Wall -std=c++14 -g -c -D_7ZIP_ST -I"/home/hitesh/lzma2201/C" "/home/hitesh/lzma2201/C/"$FILE ;
done
g++ -std=c++14 -Wall -nostartfiles -g 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o 7zFile.o 7zStream.o Aes.o AesOpt.o Alloc.o Bcj2.o Bcj2Enc.o Bra.o Bra86.o BraIA64.o CpuArch.o Delta.o DllSecur.o LzFind.o LzFindMt.o Lzma2Dec.o Lzma2DecMt.o Lzma2Enc.o Lzma86Dec.o Lzma86Enc.o LzmaDec.o LzmaEnc.o LzmaLib.o MtCoder.o MtDec.o Ppmd7.o Ppmd7Dec.o Ppmd7Enc.o Sha256.o Sort.o Threads.o Xz.o XzCrc64.o XzCrc64Opt.o XzDec.o XzEnc.o XzIn.o -o compress -L"/home/hitesh/lzma2201/C"
I have tried using another versions of lzma sdk but that was resulting in different errors. I expected the program to run as it was running when i originally wrote the script in .c file for windows

How to fix multiple definition of main building gtest project using make on ubuntu [duplicate]

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.

error using already compiled version of openCV

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

Undefined reference to boost::python::detail::init_module and friends

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

building C++ wrapper for QFS

I am absolutely horrible with compiling/linking.
I have tried everything i could find, nothing works.
websockserver.h:516: undefined reference to `qfs_init'
websockserver.h:527: undefined reference to `qfs_read'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Rmdir(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Remove(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Open(char const*, int, int, int, int, int, int, unsigned short, signed char, signed char)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Write(int, char const*, unsigned long)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Read(int, char*, unsigned long)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Rename(char const*, char const*, bool)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Tell(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Seek(int, long, int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Stat(char const*, KFS::KfsFileAttr&, bool)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Close(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Create(char const*, int, bool, int, int, int, int, bool, unsigned short, signed char, signed char)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Sync(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::IsDirectory(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::ErrorCodeToStr(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::IsFile(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Exists(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Mkdir(char const*, unsigned short)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Readdir(char const*, std::vector<std::string, std::allocator<std::string> >&)'
./cqfs//libcqfs.so: undefined reference to `KFS::Connect(std::string const&, int)'
collect2: error: ld returned 1 exit status
make: *** [w] Error 1
websockserver.h:514 to 530
long numbytes;
struct cqfs *qfs;
if(!qfs_init(&qfs, "127.0.0.1", 20000))
printf("Failed to init qfs connection\n");
int fd = qfs_open(qfs, "APP.js", O_RDONLY);
if(fd < 0)
printf("Error opening file: %s\n", qfs_error(qfs));
numbytes = (long)qfs_seek(qfs, fd, 0L, SEEK_END);
qfs_seek(qfs, fd, 0L, SEEK_SET);
ret = calloc(numbytes + 1, sizeof(char));
if(qfs_read(qfs, fd, ret, numbytes) < 0)
printf("Error reading file: %s\n", qfs_error(qfs));
qfs_close(qfs, fd);
QFS provides .so and .a of
libqfs_client
libqfs_qcdio
libqfs_io
libqfs_common
libqfs_qcrs
How do i build my wrapper (cqfs.cpp, cqfs.h)?
This is my current command:
g++ -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -shared -o libcqfs.so cqfs.cpp cqfs.h -fPIC -L./libqfs_client.so -L./libqfs_qcdio.so -lpthread -lrt -L./libqfs_io.so -L./libqfs_common.so -L./libqfs_qcdio.so -lpthread -lz -lrt -lboost_regex-mt -lcrypto -L./libqfs_qcrs.so -lc
based on the example application(not library) provided by Quantcast:
c++ -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -g CMakeFiles/qfssample.dir/qfssample_main.o -o qfssample -rdynamic ../../src/cc/libclient/libqfs_client.a ../../src/cc/qcdio/libqfs_qcdio.a -lpthread -lrt ../../src/cc/kfsio/libqfs_io.a ../../src/cc/common/libqfs_common.a ../../src/cc/qcdio/libqfs_qcdio.a -lpthread -lz -lrt -lboost_regex-mt -lcrypto ../../src/cc/qcrs/libqfs_qcrs.a
.a or .so did not make a difference
It looks like you are incorrectly using the -L argument to g++. The argument of -L should refer to the directory that contains the libraries, rather than directly referencing them.
To demonstrate, I created a simple example with a Connect and Readdir (I've omitted it for brevity, but let me know if you want to see it). Here is the c++ command I crafted to get it to compile and link correctly:
c++ -Wall -o t -I./build/release/include -L./build/release/lib t.cc -lqfs_client -lqfs_common -lqfs_io -lqfs_qcdio -lqfs_qcrs -lpthread -lboost_regex-mt -lz -lcrypto
One can then run it by specifying the LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on Max OS X):
DYLD_LIBRARY_PATH=$PWD/build/release/lib ./t
.
..
dumpster
test
test2
test3
user
Note that you'll have to LD_LIBRARY_PATH instead of DYLD_LIBRARY_PATH on Linux.
We are actually working on building C bindings for QFS in the main project. Here is the pull request. If you're not comfortable with working directly from the fork (they are very experimental), you can check it out and build with make VERBOSE=1 to see the commands that are actually used to build the components and apply that to build your own bindings.
UPDATE: The C bindings for the QFS API are now available in the master branch.
For example, here is the line that is output to build the shared library on my mac:
/usr/bin/c++ -I/opt/local/include -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -O2 -g -shared -o libqfsc.dylib -install_name /Users/sday/c/qfs/build/release/src/cc/qfsc/libqfsc.dylib CMakeFiles/qfsc-shared.dir/qfsc.o ../libclient/libqfs_client.dylib ../kfsio/libqfs_io.dylib ../common/libqfs_common.dylib -lpthread -lz ../qcdio/libqfs_qcdio.dylib /usr/local/lib/libboost_regex-mt.dylib /usr/local/lib/libboost_system-mt.dylib ../qcrs/libqfs_qcrs.dylib -lcrypto
Disclaimer: I work for Quantcast.