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.
Related
I am using armadillo in C++ and have a very simple issue - can someone please explain to me why I am unable to calculate XtX? I am multiplying a 2x3 and a 3x2 matrix and as soon as I add the last line, the code does not build.
mat X(3,2);
X="1 3; 1 2; 1 5";
mat Xt;
Xt=X.t();
mat XtX(2,2);
XtX=Xt*X;
This is the error I get:
[build] CMakeFiles\MoE.dir/objects.a(main.cpp.obj): 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*)':
[build] C:/Users/.../include/armadillo_bits/wrapper_blas.hpp:42: undefined reference to `wrapper_dgemv_'
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 have downloaded the latest Armadillo package (3.920) and I am trying to use it on my machine (Ubuntu 12.04). I am following the steps mentioned in the readme.txt file for the installation (cmake ., make, sudo make install). I have lapack and blas on my system. When I try to run the example provided in the examples directory using:
g++ example1.cpp -O2 -larmadillo
I get the error:
/usr/lib/liblapack.so.3gf: undefined reference to ATL_zptgemm'
/usr/lib/liblapack.so.3gf: undefined reference toATL_scopy'
etc
If I try to run the example with
g++ example1.cpp -O2 -llpack -lblas -lgfortran
I get the error:
/tmp/ccOsKhfg.o: In function double arma::blas::dot<double>(unsigned int, double const*, double const*)':
example1.cpp:(.text._ZN4arma4blas3dotIdEET_jPKS2_S4_[double arma::blas::dot<double>(unsigned int, double const*, double const*)]+0x36): undefined reference towrapper_ddot_'
/tmp/ccOsKhfg.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*)':
example1.cpp:(.text._ZN4arma4blas4gemvIdEEvPKcPKiS5_PKT_S8_S5_S8_S5_S8_PS6_S5_[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*)]+0x53): undefined reference towrapper_dgemv_'
/tmp/ccOsKhfg.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*)':
example1.cpp:(.text._ZN4arma4blas4gemmIdEEvPKcS3_PKiS5_S5_PKT_S8_S5_S8_S5_S8_PS6_S5_[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*)]+0x61): undefined reference towrapper_dgemm_'
Note that if I comment lines '#define ARMA_USE_LAPACK','#define ARMA_USE_BLAS'in config.hpp I am able to run example 1 but not example 2 as it requires lapack.
Can you please guide me in solving the problem.
Thanks.
Salil
By seeing your question,
i think you should type -llapack instead of -llpack.
Without -lgfortan it can work so try that too.
g++ main.cpp -o main -o1 -larmadillo -llapack -lblas
How would I make wxWidgets 2.9.4 work with Code::Blocks + MinGW? I have built the libraries (release only) and coded some code. When I build it without event tables it works fine, but with them, it throws errors.
Here is a dump of the build messages when there are event tables:
obj\Debug\main.o||In function `_ZN21wxEventTableEntryBaseC2EiiP14wxEventFunctorP8wxObject':|
C:\wxWidgets\include\wx\event.h|2870|undefined reference to `_wxTheAssertHandler'|
C:\wxWidgets\include\wx\event.h|2871|undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'|
obj\Debug\main.o||In function `_ZN20wxEventFunctorMethodI14wxEventTypeTagI14wxCommandEventE12wxEvtHandler7wxEventS3_EC1EMS3_FvRS4_EPS3_':|
C:\wxWidgets\include\wx\event.h|374|undefined reference to `_wxTheAssertHandler'|
C:\wxWidgets\include\wx\event.h|374|undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'|
obj\Debug\main.o||In function `_ZN20wxEventFunctorMethodI14wxEventTypeTagI14wxCommandEventE12wxEvtHandler7wxEventS3_EclEPS3_RS4_':|
C:\wxWidgets\include\wx\event.h|392|undefined reference to `_wxTheAssertHandler'|
C:\wxWidgets\include\wx\event.h|392|undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'|
||=== Build finished: 6 errors, 0 warnings ===|
and another of the build log:
-------------- Build: Debug in G1BC ---------------
Compiling: main.cpp
Linking executable: bin\Debug\G1BC.exe
obj\Debug\main.o: In function `_ZN21wxEventTableEntryBaseC2EiiP14wxEventFunctorP8wxObject':
C:/wxWidgets/include/wx/event.h:2870: undefined reference to `_wxTheAssertHandler'
C:/wxWidgets/include/wx/event.h:2871: undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'
obj\Debug\main.o: In function `_ZN20wxEventFunctorMethodI14wxEventTypeTagI14wxCommandEventE12wxEvtHandler7wxEventS3_EC1EMS3_FvRS4_EPS3_':
C:/wxWidgets/include/wx/event.h:374: undefined reference to `_wxTheAssertHandler'
C:/wxWidgets/include/wx/event.h:374: undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'
obj\Debug\main.o: In function `_ZN20wxEventFunctorMethodI14wxEventTypeTagI14wxCommandEventE12wxEvtHandler7wxEventS3_EclEPS3_RS4_':
C:/wxWidgets/include/wx/event.h:392: undefined reference to `_wxTheAssertHandler'
C:/wxWidgets/include/wx/event.h:392: undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 4 seconds)
6 errors, 0 warnings
Code::Blocks says this bit of code is the problem:
Hope you can help, thanks in advance!
You need to always leave DEBUG_FLAG=1 as that, otherwise asserts won't compile.
This is what it says in MSW's install.txt:
Specifies the level of debug support in wxWidgets. Notice that this
is independent from both BUILD and DEBUG_INFO options. By default always set to 1 meaning that > debug support is enabled: asserts are
compiled into the code (they are inactive by default in release
builds of the application but can be enabled), wxLogDebug() and
wxLogTrace() are available and WXDEBUG is defined. Setting it to
0 completely disables all debugging code in wxWidgets while setting
it to 2 enables even the time consuming assertions and checks which
are deemed to be unsuitable for production environment.
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