I have these packages installed on my OpenSUSE 11.3:
i | libstdc++45 | Standard shared library for C++ | package
i | libstdc++45-devel | Contains files and libraries for development | package
But when i'm trying to compile this C++ code:
#include <cstdio>
#include <tr1/regex>
using namespace std;
int main() {
int test[2];
const tr1::regex pattern(".*");
test[0] = 1;
if (tr1::regex_match("anything", pattern) == false) {
printf("Pattern does not match.\n");
}
return 0;
}
using
g++ -pedantic -g -O1 -o ./main.o ./main.cpp
It outputs this errors:
/tmp/cc0g3GUE.o: In function `basic_regex':
/usr/include/c++/4.5/tr1_impl/regex:771: undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/cc0g3GUE.o: In function `bool std::tr1::regex_match<char const*, char, std::tr1::regex_traits<char> >(char const*, char const*, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)':
/usr/include/c++/4.5/tr1_impl/regex:2144: undefined reference to `bool std::tr1::regex_match<char const*, std::allocator<std::tr1::sub_match<char const*> >, char, std::tr1::regex_traits<char> >(char const*, char const*, std::tr1::match_results<char const*, std::allocator<std::tr1::sub_match<char const*> > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)'
collect2: ld returned 1 exit status
What packages should i (un)install to make the code work on my PC?
You need to look at the c++0x library support for gcc as I think Regex is not yet completed
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x
Related
I want to run a unit test of a C++ class with gtest from with a command line under Ubuntu x64. I was following a tutorial from a book, which used the following command to to this:
g++ -o tester.exe MyClass1.cpp MyClass1Test.cpp
-I googletest/googletest -I googletest/googletest/include
-I googletest/googlemock -I googletest/googlemock/include
-I usr/lib/libgtest.a -l -lpthread
Original command suggested by "Mastering C++ Programming" (Jeganathan Swaminathan):
g++ -o tester.exe src/Math.cpp test/MathTest.cpp
-I googletest/googletest -I googletest/googletest/include
-I googletest/googlemock -I googletest/googlemock/include
-I src libgtest.a -lpthread
My 3 files look like this:
"MyClass1.cpp"
#include "MyClass1.h"
bool MyClass1::checkEquality(int number1, int number2) {
int result = number1 - number2;
if(result == 0) {
return true;
}
else {
return false;
}
}
int main() {}
"MyClass1.h"
class MyClass1 {
public:
bool checkEquality(int number1, int number2);
};
"MyClass1Test.cpp"
#include "MyClass1.h"
#include <gtest/gtest.h>
TEST ( MyClass1Test, checkIntEquality) {
MyClass1 myClass;
bool expectedResult = true;
int number1 = 10;
int number2 = 10;
bool result = myClass.checkEquality(number1, number2);
EXPECT_EQ(expectedResult, result);
}
I already tried playing around with the order of the parameters as suggested when I searched for an solution, but this did not give me a different output. I also read that the lpthread library has something to do with this issue but I am unsure what to do about this.
The output I get from the command above is:
/tmp/ccJVQJv2.o: In function `MyClass1Test_checkIntEquality_Test::TestBody()':
MyClass1Test.cpp:(.text+0x72): undefined reference to `testing::Message::Message()'
MyClass1Test.cpp:(.text+0x9f): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
MyClass1Test.cpp:(.text+0xb2): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
MyClass1Test.cpp:(.text+0xbe): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
MyClass1Test.cpp:(.text+0xe7): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/tmp/ccJVQJv2.o: In function `__static_initialization_and_destruction_0(int, int)':
MyClass1Test.cpp:(.text+0x17b): undefined reference to `testing::internal::GetTestTypeId()'
MyClass1Test.cpp:(.text+0x1e9): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/tmp/ccJVQJv2.o: In function `MyClass1Test_checkIntEquality_Test::MyClass1Test_checkIntEquality_Test()':
MyClass1Test.cpp:(.text._ZN34MyClass1Test_checkIntEquality_TestC2Ev[_ZN34MyClass1Test_checkIntEquality_TestC5Ev]+0x14): undefined reference to `testing::Test::Test()'
/tmp/ccJVQJv2.o: In function `testing::internal::scoped_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::reset(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
MyClass1Test.cpp:(.text._ZN7testing8internal10scoped_ptrINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE5resetEPS7_[_ZN7testing8internal10scoped_ptrINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE5resetEPS7_]+0x24): undefined reference to `testing::internal::IsTrue(bool)'
/tmp/ccJVQJv2.o: In function `testing::internal::scoped_ptr<std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >::reset(std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)':
MyClass1Test.cpp:(.text._ZN7testing8internal10scoped_ptrINSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEEE5resetEPS7_[_ZN7testing8internal10scoped_ptrINSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEEE5resetEPS7_]+0x23): undefined reference to `testing::internal::IsTrue(bool)'
/tmp/ccJVQJv2.o: In function `testing::AssertionResult testing::internal::CmpHelperEQ<bool, bool>(char const*, char const*, bool const&, bool const&)':
MyClass1Test.cpp:(.text._ZN7testing8internal11CmpHelperEQIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal11CmpHelperEQIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x36): undefined reference to `testing::AssertionSuccess()'
/tmp/ccJVQJv2.o: In function `testing::AssertionResult testing::internal::CmpHelperEQFailure<bool, bool>(char const*, char const*, bool const&, bool const&)':
MyClass1Test.cpp:(.text._ZN7testing8internal18CmpHelperEQFailureIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal18CmpHelperEQFailureIbbEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x6c): 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)'
/tmp/ccJVQJv2.o:(.rodata._ZTV34MyClass1Test_checkIntEquality_Test[_ZTV34MyClass1Test_checkIntEquality_Test]+0x20): undefined reference to `testing::Test::SetUp()'
/tmp/ccJVQJv2.o:(.rodata._ZTV34MyClass1Test_checkIntEquality_Test[_ZTV34MyClass1Test_checkIntEquality_Test]+0x28): undefined reference to `testing::Test::TearDown()'
/tmp/ccJVQJv2.o: In function `MyClass1Test_checkIntEquality_Test::~MyClass1Test_checkIntEquality_Test()':
MyClass1Test.cpp:(.text._ZN34MyClass1Test_checkIntEquality_TestD2Ev[_ZN34MyClass1Test_checkIntEquality_TestD5Ev]+0x20): undefined reference to `testing::Test::~Test()'
/tmp/ccJVQJv2.o:(.rodata._ZTI34MyClass1Test_checkIntEquality_Test[_ZTI34MyClass1Test_checkIntEquality_Test]+0x10): undefined reference to `typeinfo for testing::Test'
collect2: error: ld returned 1 exit status
There is a strange tutorial book. .exe extension is ridiculous for Linux, remove it.
g++ -o tester MyClass1.cpp MyClass1Test.cpp -Igoogletest/googletest -Igoogletest/googletest/include -Igoogletest/googlemock -Ioogletest/googlemock/include -lgtest -lpthread
Or
g++ -o tester MyClass1.cpp MyClass1Test.cpp -Igoogletest/googletest -Igoogletest/googletest/include -Igoogletest/googlemock -Ioogletest/googlemock/include /usr/lib/libgtest.a -lpthread
For Windows you could tune a development environment for Visual Studio with help of the tutorial How to use Google Test for C++ in Visual Studio?
i am trying to build webrtc version 62 , using the following
1.git checkout -b branch62 refs/remotes/branch-heads/62
2.gn gen out_release_62/x64/Debug --args="rtc_include_tests=false rtc_use_h264=false use_rtti=true is_component_build=false enable_iterator_debugging=false enable_nacl=false target_os=\"linux\" target_cpu=\"x64\" is_debug=true"
3.ninja -C out_release_62/x64/Debug
i am linking to libwebrtc.a and libwebrtc_common.a
but wherever i try to use RTC_CHECK_EQ or RTC_DCHECK_LT i get the the following error
undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
and
out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':
i had no issue with build branch head 60 ,
i tried linking to librtc_base.a and librtc_base_approved.a but no luck.
A sample program that produces this error is
#include <iostream>
#include <string>
#include <webrtc/rtc_base/checks.h>
#include <webrtc/rtc_base/ssladapter.h>
#include <webrtc/rtc_base/logging.h>
#include <webrtc/api/peerconnectioninterface.h>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
std::string type;
std::string sdp;
webrtc::SdpParseError error;
webrtc::CreateSessionDescription(type,sdp,&error);
RTC_DCHECK(5);
RTC_CHECK_EQ(1,6);
RTC_DCHECK_LT(1,4);
return 0;
}
gcc verison 6.3 linker
g++ -L/home/test/webrtc-checkout-ankur/src/out_release_62/x64/Debug -o "testwebrtc" ./src/testwebrtc.o -lwebrtc -lwebrtc_common -lpthread -lm -ldl
this is the error that is returned
./src/testwebrtc.o: In function `main':
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:22: undefined reference to `webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:24: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:25: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
./src/testwebrtc.o: In function `rtc::CheckEqImpl(int, int, char const*)':
makefile:45: recipe for target 'testwebrtc' failed
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:179: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
collect2: error: ld returned 1 exit status
From my observation any function/method that has std::string in it is showing this behaviour.
_GLIBCXX_USE_CXX11_ABI=0 has been set, and -std=c++0x , this build is done on an ubuntu 16.04 system.
running nm on the built library i get
find -iname '.a' -exec nm -A -C {} \; | grep 'T rtc::FatalMessage::FatalMessage('
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/rtc_base/librtc_base_approved.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000001a0 T rtc::FatalMessage::FatalMessage(char const*, int)
./Debug/obj/webrtc/libwebrtc.a:checks.o:00000000000005e0 T rtc::FatalMessage::FatalMessage(char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
and
find -iname '.a' -exec nm -A -C {} \; | grep 'CreateSessionDescription('
./Debug/obj/webrtc/pc/libpeerconnection.a:jsepsessiondescription.o:0000000000000000 T webrtc::CreateSessionDescription(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, webrtc::SdpParseError*)
./Debug/obj/webrtc/libwebrtc.a:jsepsessiondescription.o:0000000000000000 T webrtc::CreateSessionDescription(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, webrtc::SdpParseError*)
please help
you have a standard lib mismatch: on one hand you use std::string, on the other hand you use std::__1::basic_string
in other words: on one hand you use libc++ on the other hand you use libstdc++
You need to use clang and pass
-stdlib=libstdc++
to the compiler command line.
__1 signifies that we are using the libc++ llvm-clang library, which is the default for webrtc builds
__1 is the inlined namespace that libc++ uses,
so as to solve this particular issue, we should either use libc++ instead of libstdc++ in our application when we link to libwebrtc,
or
build webrtc to use libstdc++,
to let gn know that we intend to use libstdc++, we pass use_custom_libcxx=false and use_custom_libcxx_for_host=false as args
I'd like to use Apache log4cxx and am running into a problem. I'm running on Debian 8 and installed log4cxx using
apt-get install liblog4cxx10-dev
I have embedded one of the code snippets in the Documentation Page into the code below:
#include <log4cxx/logger.h>
#include <math.h>
int main(int argc, char* argv[]) {
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("com.foo"));
int i = 10;
const char* region = "World";
LOG4CXX_INFO(logger, "Simple message text.")
LOG4CXX_INFO(logger, "Hello, " << region)
LOG4CXX_DEBUG(logger, L"Iteration " << i)
LOG4CXX_DEBUG(logger, "e^10 = " << std::scientific << exp(10.0))
LOG4CXX_WARN(logger, L"" << i << L" is the number of the iteration.")
return 0;
}
When compiling with Eclipse CDT (gcc 5.3.0 built from source) I get the following linker errors:
make all
Building file: ../src/tester.cxx
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/tester.d" -MT"src/tester.o" -o "src/tester.o" "../src/tester.cxx"
Finished building: ../src/tester.cxx
Building target: logtest
Invoking: GCC C++ Linker
g++ -L/usr/lib/x86_64-linux-gnu -o "logtest" ./src/tester.o -llog4cxx
./src/tester.o: In function `main':
/home/andand/workspace/logtest/Debug/../src/tester.cxx:9: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](log4cxx::helpers::CharMessageBuffer&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:9: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:10: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](log4cxx::helpers::CharMessageBuffer&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:10: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:11: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:11: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:12: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](std::ostream&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:12: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:13: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&)'
makefile:45: recipe for target 'logtest' failed
/home/andand/workspace/logtest/Debug/../src/tester.cxx:13: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, log4cxx::spi::LocationInfo const&) const'
collect2: error: ld returned 1 exit status
make: *** [logtest] Error 1
I double checked where apt installed the libraries:
root#starsim-dev:/home/andand# find / -name *log4cxx*
/usr/lib/x86_64-linux-gnu/liblog4cxx.a
/usr/lib/x86_64-linux-gnu/liblog4cxx.so.10.0.0
/usr/lib/x86_64-linux-gnu/liblog4cxx.so.10
/usr/lib/x86_64-linux-gnu/liblog4cxx.so
/usr/lib/x86_64-linux-gnu/pkgconfig/liblog4cxx.pc
/usr/include/log4cxx
/usr/include/log4cxx/private/log4cxx_private.h
/usr/include/log4cxx/log4cxx.h
/usr/share/doc/liblog4cxx10
/usr/share/doc/liblog4cxx10-dev
/usr/share/lintian/overrides/liblog4cxx10
/usr/share/lintian/overrides/liblog4cxx10-dev
/var/cache/apt/archives/liblog4cxx10-dev_0.10.0-4_amd64.deb
/var/cache/apt/archives/liblog4cxx10_0.10.0-4_amd64.deb
/var/lib/dpkg/info/liblog4cxx10:amd64.postinst
/var/lib/dpkg/info/liblog4cxx10:amd64.shlibs
/var/lib/dpkg/info/liblog4cxx10-dev.list
/var/lib/dpkg/info/liblog4cxx10:amd64.list
/var/lib/dpkg/info/liblog4cxx10:amd64.md5sums
/var/lib/dpkg/info/liblog4cxx10:amd64.postrm
/var/lib/dpkg/info/liblog4cxx10-dev.md5sums
The documentation on Apache's website isn't entirely clear what other library dependencies exist. Does anybody have some insight into what I'm missing?
I ran into the same set of linker errors trying to use log4cxx on Ubuntu 18.04. I was able to get their code snippets to work - including the one above - by adding the following additional Apache libs to my MakeFile
LIBS+= -llog4cxx -laprutil-1 -lapr-1
Make sure to list them in the above order.
I have installed Armadillo in Ubuntu 14.10. I have an example code likes below
#include <iostream>
#include <armadillo>
using namespace std;
using namespace arma;
int main(int argc, char** argv)
{
mat A = randu<mat>(4,5);
mat B = randu<mat>(4,5);
cout << A*B.t() << endl;
return 0;
}
I compiled in command line, it is always successful, I depict in captured image.
I have eclipse Luna for C++ and config in C/C++ Build Settings
As you can see, it is similar to command line but when eclipse compiles, it use -Iarmadillo instead of -larmadillo and it then occurs errors.
The errors were
make all Building file: ../src/Test.cpp Invoking: GCC C++ Compiler
g++ -std=c++0x -Iarmadillo -O0 -MMD -MP -MF"src/Test.d"
-MT"src/Test.d" -o "src/Test.o" "../src/Test.cpp" /tmp/ccy9M8WG.o: In function void arma::blas::gemv<double>(char const*, int const*, int
const*, double const*, double const*, int const*, double const*, int
const*, double const*, double*, int const*)':
Test.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[_ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_]+0x55):
undefined reference towrapper_dgemv_' /tmp/ccy9M8WG.o: In function
void arma::blas::gemm<double>(char const*, char const*, int const*,
int const*, int const*, double const*, double const*, int const*,
double const*, int const*, double const*, double*, int const*)':
Test.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[_ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_]+0x5b):
undefined reference towrapper_dgemm_' /tmp/ccy9M8WG.o: In function
void arma::blas::syrk<double>(char const*, char const*, int const*,
int const*, double const*, double const*, int const*, double const*,
double*, int const*)':
Test.cpp:(.text._ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_[_ZN4arma4blas4syrkIdEEvPKcS3_PKiS5_PKT_S8_S5_S8_PS6_S5_]+0x4e):
undefined reference towrapper_dsyrk_' /tmp/ccy9M8WG.o: In function
double arma::blas::dot<double>(unsigned int, double const*, double
const*)':
Test.cpp:(.text._ZN4arma4blas3dotIdEET_jPKS2_S4_[_ZN4arma4blas3dotIdEET_jPKS2_S4_]+0x4a):
undefined reference towrapper_ddot_' /tmp/ccy9M8WG.o: In function
TLS wrapper function for arma::arma_rng_cxx11_instance':
Test.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x5):
undefined reference toTLS init function for
arma::arma_rng_cxx11_instance'
Test.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x15):
undefined reference to `arma::arma_rng_cxx11_instance' collect2:
error: ld returned 1 exit status src/subdir.mk:18: recipe for target
'src/Test.o' failed make: *** [src/Test.o] Error 1
My questions are
How can I force eclipse use -larmadillo?
What happened to this phenomenon?
Thank you in advance
You can also create GNU Autotools projects and add following line:
bin_PROGRAMS=armadillo_example
armadillo_example_SOURCES=armadillo_example.cpp
armadillo_example_LDADD=-larmadillo
To Makefile.am file where your source code exist.
You may not be linking with Armadillo. Use -larmadillo in your link as Hamed suggested.
I am trying to use the boost regex library but I can't manage to compile my program. All related questions which involve similar error messages seem to relate to situations where regex library wasn't properly linked. I think that I am linking it, but maybe I am doing something stupid... Perhaps someone sees my mistake?
Here is my test program:
// ~/workspace/test/test.cpp
#include <string>
#include <iostream>
#include <boost/regex.hpp>
int main(){
std::string s("abaab");
boost::regex r("[ab]*");
std::cout << boost::regex_match(s,r) << std::endl;
}
Here are the boost binaries (I installed them via synaptic on Xubuntu):
/usr/lib/i386-linux-gnu$ ls libboost_regex* -al
-rw-r--r-- 1 root root 2169582 Okt 13 05:14 libboost_regex.a
lrwxrwxrwx 1 root root 24 Okt 13 05:13 libboost_regex.so -> libboost_regex.so.1.53.0
-rw-r--r-- 1 root root 1002568 Okt 13 05:14 libboost_regex.so.1.53.0
Nevertheless I'm getting quite an ugly error message when running
~/workspace/test$ g++ -L/usr/lib/i386-linux-gnu/ -lboost_regex test.cpp
Here is the complete message:
~/workspace/test$ g++ -L/usr/lib/i386-linux-gnu/ -lboost_regex test.cpp
/tmp/cc1yDf0v.o: In function `bool boost::regex_match<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)':
test.cpp:(.text._ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x4c): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match()'
/tmp/cc1yDf0v.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
test.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j]+0x22): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
/tmp/cc1yDf0v.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>)':
test.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC2ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC5ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_]+0xcd): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
collect2: error: ld returned 1 exit status
The header seems to be found, right? How else could gcc know about boost::re_detail::perl_matcher or boost::basic_regex?
I have no clue what the problem might be. Maybe it is the linking after all?
Thanks in advance!
You just needed to make sure the library comes after your own sources.
g++ -L/usr/lib/i386-linux-gnu/ test.cpp -lboost_regex
This is a FAQ:
Why does the order in which libraries are linked sometimes cause errors in GCC?
g++ linking order dependency when linking c code to c++ code
And probably quite a few more. I guess it's (sadly) one of those rites-of-passage that goes with the territory :(