Linking OpenBLAS and Armadillo with CodeBlocks project - c++

I am using Armadillo along with OpenBLAS for linear algebraic operations. For a sample code I am linking these libraries using following commands:
g++ sample.cpp -I "path\armadillo\include" -I "path\OpenBLAS\include" -L "path\OpenBLAS\lib" -llibopenblas
The code is compiled and runs successfully. Therefore, to link these libraries with CodeBlocks I used Linker setting and Search Directories option to specify location for libraries. But I am getting following errors:
path\OpenBLAS\lib\libopenblas.a(dormqr.o):dormqr.f|| undefined reference to `_gfortran_concat_string'|
Is this related with linking libraries or with compiler?

Related

boost.regex fails to link with MinGW and GCC compiler

On Windows 10 I installed MinGW, and use Eclipse to write C++ programs together with Boost libraries 1.71.0 (for example boost/algorithm/string.hpp).
I can successfully create the executable using boost::replace_all(doc, "#", "_"); in my source code.
The compiler is GCC version 8.2.0
As I also want use the Boost.regex library I built the Boost libraries suffing following commands commands in a Command Prompt window
bootstrap.bat
.\b2 --prefix=C:\Users\makkun\Documents\boost_1_71_0\build install
I then changed to the Boost root directory and invoked b2 as follows:
b2 --build-dir=C:\Users\makkun\Documents\boost_1_71_0\build toolset=gcc --build-type=complete stage
The directory C:\Users\makkun\Documents\boost_1_71_0\stage\lib was created and I can see the regex related files
libboost_regex-mgw82-mt-d-x32-1_71.a
libboost_regex-mgw82-mt-d-x32-1_71.dll.a
libboost_regex-mgw82-mt-sd-x32-1_71.a
libboost_regex-mgw82-mt-s-x32-1_71.a
libboost_regex-mgw82-mt-x32-1_71.a
libboost_regex-mgw82-mt-x32-1_71.dll.a
libboost_regex-mgw82-mt-d-x32-1_71.dll
libboost_regex-mgw82-mt-x32-1_71.dll
In Eclipse I added in MinGW C++ Linker > Libraries > Library search path (-L) the library folder "C:\Users\makkun\Documents\boost_1_71_0\stage\lib"
In my source code I have
#include <boost/regex.hpp>
...
boost::regex e("(\\d{4}[- ]){3}\\d{4}");
The compilation is OK, but the linking with command
g++ "-LC:\\Users\\makkun\\Documents\\boost_1_71_0\\stage\\lib" "-LC:\\Users\\makkun\\Documents\\boost_1_71_0\\libs" -o LastDoc.exe "src\\LastDoc.o"
fails with 46 errors of the type undefined reference to:
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: src\LastDoc.o: in function `ZN5boost16re_detail_10710027cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE':
C:/Users/makkun/Documents/boost_1_71_0/boost/regex/v4/cpp_regex_traits.hpp:370: undefined reference to `boost::re_detail_107100::cpp_regex_traits_char_layer<char>::init()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: src\LastDoc.o: in function `ZN5boost16re_detail_10710011raw_storage6extendEj':
C:/Users/makkun/Documents/boost_1_71_0/boost/regex/v4/regex_raw_buffer.hpp:131: undefined reference to `boost::re_detail_107100::raw_storage::resize(unsigned int)
...'
I also tried to add in MinGW C++ Linker > Libraries > Libraries (-l) string "boost-regex" but the linker does find it
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lboost_regex
Can anybody suggest where the problem is, please?

OpenBlas and g++

I have installed OpenBlas in TX1 and the time_dgemm example compiles fine with the gcc. However, I need to be able to link the rest of my code with OpenBlas using g++. When I try to compile the time_dgemm example with g++ it fails, giving the linking error "...undefined reference to 'dgemm_(......". The only change is using the g++ instead of gcc.
I have tried to compile the OpenBLAS library with g++ (make CC=g++), as other people suggested in the past, but the compilation fails when it tries to compile some part of BLAS.
Any ideas?
If some people have the same issue, I was able to compile with the following command:
g++ openBlasExample.cpp -I /usr/include/openblas -lopenblas
You can find your openblas include folder by using on Linux:
locate openblas
More info here:
https://gist.github.com/xianyi/6930656

Executing cross-compiled C++ program using Boost on Raspberry Pi

I have built a GCC cross toolchain for the RPi and can cross-compile C++ source and successfully run it after copying the executable to the RPi.
Next I built the Boost libraries targeting ARM, using the cross toolchain. I can successfully build and link C++ source to those Boost libraries using the cross toolchain on my PC.
I then copied the program, dynamically linked to Boost, to the RPi and copied all built libraries into /usr/local/lib on the Pi. However, executing fails:
$ ./my_program
./my_program: error while loading shared libraries: libboost_system.so.1.60.0: cannot open shared object file: No such file or directory
Again, this library, libboost_system.so.1.60.0, exists in /usr/local/lib.
I also tried
export LD_LIBRARY_PATH='/usr/local/lib'
but that doesn't change anything. What am I doing wrong?
EDIT:
I build all source files like this (rpi-g++ is a symlink to my cross-compiler):
rpi-g++ -c -std=c++1y -Wall -Wextra -pedantic -O2 -I /path/to/cross/boost/include *.cpp
rpi-g++ -o myprog *.o -L /path/to/cross/boost/lib/ -lboost_system -pthread
EDIT 2:
When linked with
rpi-g++ -o myprog *.o -L /path/to/cross/boost/lib/ -rdynamic -lboost_system -pthread
the problem remains the same. I have checked and verified everything suggested by Technaton as well. Strangely, ldd insists that the created executable is "not a dynamic executable" (checked that on my PC and on the RPi), which doesn't make sense to me.
There are several things you can check. I've posted a complete check list here, but judging from your linker command line, number 5 is probably the culprit.
Check that your library and your program are correctly build for the target architecture. You can verify that by using file ./myprog and file libboost_system.so.1.60.0.
Make sure that you have copied the actual shared object, and not a link to it.
Ensure that the shared object file's permissions are sane (0755).
Run ldconfig -v and check that your shared object file is picked up. Normally, /usr/local/lib is in the standard library search path, and LD_LIBRARY_PATH is not required.
Make sure that your program is actually dynamically linked by running ldd ./myprog. Judging from your linker command line, that is the problem: You're missing -rdynamic.
Check the paths returned from ldd: If you have linked with rpath, the library search path might be screwed up. Try again without -rpath.

Statically linking matio library using g++

How do you statically link matio, a library for reading mat-files, mainly used by matlab and octave into an executable?
If the file main.cpp holds matio functionality the compiler call
g++ -o main main.cpp -Imatio/include matio/lib/libmatio.a
fails with a bunch of error messages like: undefined reference to `inflateEnd'. This can be resolved by also adding zlib to the compiler call:
g++ -o main main.cpp -Imatio/include matio/lib/libmatio.a -lz
Now the error messages differ with something like undefined reference to `__intel_sse2_strlen'. So it appears that the zlib library is necessary for the comilation.
I now have the following questions:
What do you need to do to statically link the matio library in an executable?
Why do I need to add the zlib library even though I configured and compiled matio with ./configure --without-libz?
To build matio without zlib you apparently need to invoke configure with
./configure --with-zlib=no
(Checked this from configure.ac and config/matio_zlib.m4.)
In case you want to build matio with icc, Intel's developer pages tell that __intel_sse2_strlen is defined in libirc.a on Linux and libirc.lib on Windows.
To compile matio with the gcc do
./configure --with-zlib=no CC=gcc
afterwards, the matio library is statically linkable with the call posted in the question

Boost installation and library paths

I have been using Boost (the header only library part) for sometime now. I recently started on a project that required the compiled libraries (filesystem etc).
I followed the instructions given in the documentation, and was under the impression that the libraries to installed (directly) in the usr/local folder. After a lot of trial and error, I found that the correct (*.a) files to use were in:
/usr/local/boost_1_45_0/stage/lib/
Is this the correct folder to use for linking the boost built shlibs (shared libraries)?
An example for linking regex static(*.a) lib:
g++ -I /usr/local/boost_1_45_0 -c your_regex_prog
g++ -static -o static_regex your_regex_prog.o -lboost_regex