How to link Armadillo with Eclipse - eclipse

I want to use Armadillo with Eclipse. However all the instructions to link Armadillo is given for Visual Studio. Now I followed the instructions outlined in the ReadMe file of the Armadillo library. I added the Armadillo include folder in project(right click)->properties->C/C++ Build->Settings->Cross G++ Compiler->Includes->Inlcude paths(-I) and then I added the libraries folder (The library folder contain lapack and blas .lib and .dll files) in project(right click)->properties->C/C++ Build->Settings->Cross G++ Linker->Libraries->Library search path (-L).
However when I compile the code in the Eclipse I get the error
.....armadillo_bits/lapack_wrapper.hpp:37: undefined reference to `dgetrf_'.
Shouldn't it simply search for .lib files in the library folder and include them during compiling? I would appreciate any help regarding this matter.
Regards,
TM

Linking the Armadillo library to an Eclipse project can be done and you were about to do it ! It's pretty much the same as for any other library.
In the properties of the project :
GCC C++ Compiler -> Includes : add the path to the file armadillo (where namespace arma is declared) to the include search path (option -I). Example : /home/alpha/soft/armadillo-4.400.1/include
GCC C++ Linker -> Libraries : add the path to the file libarmadillo.so... in the library search path (option -L) Example : /home/alpha/soft/armadillo-4.400.1 . Add armadillo, lapack, blas and m as libraries (option -l). m is for math.
Here are the calls to the compiler and the linker as produced by eclipse :
make all
Building file: ../src/armaeclip.cpp
Invoking: GCC C++ Compiler
g++ -I/home/alpha/soft/armadillo-4.100.1/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/armaeclip.d" -MT"src/armaeclip.d" -o "src/armaeclip.o" "../src/armaeclip.cpp"
Finished building: ../src/armaeclip.cpp
Building target: armaeclip
Invoking: GCC C++ Linker
g++ -L/home/alpha/soft/armadillo-4.100.1 -o "armaeclip" ./src/armaeclip.o -larmadillo -lblas -lm -llapack
Finished building target: armaeclip
**** Build Finished ****
As you run the code, you might get something like :
error: det(): use of ATLAS or LAPACK needs to be enabled
terminate called after throwing an instance of 'std::logic_error'
what(): det(): use of ATLAS or LAPACK needs to be enabled
Abandon (core dumped)
To avoid this problem, follow the advise of the faq of Armadillo : uncomment #define ARMA_USE_LAPACK in file /home/alpha/soft/armadillo-4.100.1/include/config.hpp and rebuild your project.

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.

If you don't require optimized BLAS libraries, you can use the BLAS and LAPACK libraries that come with Armadillo.
Project properties > C/C++ Build > Settings > GCC C++ Compiler >
Includes > Include paths (-l): C:\armadillo-x.xxx.x\include
Then in Environment Variables > System variables, modify the Path
variable and add: C:\armadillo-x.xxx.x\examples\lib_win64\
Project properties > C/C++ General > Paths and Symbols > Libraries:
blas_win64_MT and lapack_win64_MT (it is important to add them
this way, with no path or .lib/.dll)
Then in Environment Variables > System variables, modify the Path
variable and add: C:\armadillo-x.xxx.x\examples\lib_win64\
And your Armadillo library in Eclipse is good to go.
I've used Eclipse 4.14.0 and Armadillo 9.850.1.

Related

How to link to pistache in Eclipse C++

I fail to link the pistache library in Eclipse C++ on my Ubuntu machine. I already make this reference:
Properties > C/C++ Build > Settings > Tool Settings
Under GCC C++ Linker > Libraries > Library search path
Under GCC C++ Compiler > Includes > Include paths
Add /usr/local/include/pistache to each
It throws a bunch of errors like this:
.... undefined reference to `Pistache::Ipv4::any()'
Why does this fail? The autocomplete is able to see the reference when I try rewrite the whole line, but it still errors out.
You have to let the linker use shared libraries and pass the -fpic option to the compiler:
a. First step -shared, see this image
b. Last Step Position Independent Code -fPic, see this image
Update
Another way to solve this is:
a. Add support for pthread to the linker
b.Add pistache to libraries in the linker

Compiling with icc and MAGMAmic cannot find "complex" system file

I am trying to compile a source file with icc compiler and MAGMAmic library. However I get the following error:
icc -c -o direct.o direct.c -O3 -openmp -DADD_ -Wall -DHAVE_MIC -I/opt/intel/mic/coi/include -I/usr/include/intel-coi -I/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/include:/opt/intel/compilers_and_libraries_2017.2.174/linux/ipp/include:/opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/include:/opt/intel/compilers_and_libraries_2017.2.174/linux/tbb/include:/opt/intel/compilers_and_libraries_2017.2.174/linux/daal/include -I/home/dslavchev/install/magmamic-1.4.0/include -I/home/dslavchev/install/magmamic-1.4.0/contol
icc: command line remark #10411: option '-openmp' is deprecated and will be removed in a future release. Please use the replacement option '-qopenmp'
In file included from /home/dslavchev/install/magmamic-1.4.0/include/magma_types.h(134),
from /home/dslavchev/install/magmamic-1.4.0/include/magmablas_z.h(17),
from /home/dslavchev/install/magmamic-1.4.0/include/magmablas.h(12),
from /home/dslavchev/install/magmamic-1.4.0/include/magma.h(17),
from direct.c(21):
/opt/intel/compilers_and_libraries_2017.2.174/linux/compiler/include/complex(30): catastrophic error: cannot open source file "complex"
#include_next <complex>
^
The MAGMAmic library has compiled correctly and I can run it's test ok.
I have looked at the way testing_dgesv_mic.cpp example compiles and used the same includes and link, however in my case I get the above error.
I have added the following in my .bashrc file in order to get the Intel compilers' and libraries' enviromental variables:
#for MAGMA mic
export MAGMA_PATH=/home/dslavchev/install/magmamic-1.4.0
source /opt/intel/bin/compilervars.sh intel64
source /opt/intel/mkl/bin/mklvars.sh intel64
Any ideas what might cause icc to be unable to include the "complex" file?
The file complex really exists in "/opt/intel/compilers_and_libraries_2017.2.174/linux/compiler/include/complex"
icc vesrion is:
[dslavchev#sl051 results]$ icc -v
icc version 17.0.2 (gcc version 4.4.7 compatibility)
magmamic version is magmamic-1.4.0
EDIT: Removed unnecessary code comment
EDIT2: Added version info.
MAGMAmic is a C++ library and it cannot be used with C code directly.
When icc detects that you want to compile .c++ file it automatically switches to icpc (Intel C++ compiler) which in turn results in the above error.
Solution: Either switch to icpc or rename your files to .c++
This question was answered by mark on the MAGMA forums. Link:
http://icl.cs.utk.edu/magma/forum/viewtopic.php?f=2&t=1587&p=4442#p4442

STM32 Eclipse + ARM GNU toolchain error linker

I use Eclipse + ARM plugin to build my projects. When I needed to use in my project the StemWin library, I configured my IDE to use external library.
I set
Preferences -> C/C++ General -> Paths and Symbols
I added in "Library Paths" the link to my folder includes library.
I also added the name of my library in tab "Library".
I checked the settings in the compiler tab and I ascertained all should be good.
When I tried to build my project I got an error from linker:
cannot find -lMyLib.a Hello C/C++ Problem
I double checked the name of my library and link, all are correct. This is the output of my linker:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib"
-T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,
-Map=output.map -Wl,--gc-sections -o "Hello.elf" #"objects.list" -lMyLib.a
What should I do from here?
I faced the same problem before.
-l:STemWin526_CM4_GCC.a
-L"C:\Edu_Workspace\STM32F4\stm32f4_bsp_template\Drivers\Middlewares\ST\STemWin\Lib"
Above are my working settings.
With -l:<archive file name> the colon : is important for archive file linking.
And -L will contain library path.
Also for stemwin make sure to compile with hardware floating point
-mfloat-abi=hard -mfpu=fpv4-sp-d16
the convention for the -l option of the linker (say you give -lMyLib.a as a linker option) is to search for a library file with "lib" prepended to the given name and .a (or .so) appended, i.e. your command line searches for a file libMyLib.a.{a,so} which is probably not how it's named.
Either you rename your library according to this convention or give it to the linker command line omitting -l (provided your IDE allows you to do so).
Looks like the problem is in -lMyLib.a which means you're trying to link a static library as a dynamic one.
To link a static lib you have to use its path as with ordinary .o files: ... /path/to/MyLib.a
and the resulting command line should look something like
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib" -T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "Hello.elf" #"objects.list" /path/to/MyLib.a
UPDATE:
Although it might fix the issue, turns out it's not true:
-llibrary
-l library
...
Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.
(https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)

Eclipse linker not finding my libraries

I am having problems getting NSight Eclipse to link in my libraries:
Building target: SA_V1
Invoking: NVCC Linker
nvcc -L/home/streaming/VidApp_V1.0/src/AudioPreconditioning6Ch/dist/Release/GNU-Linux-x86 -L/home/streaming/cuda-workspace/libConfig/Debug -L/usr/lib32 -link -o "SA_V1" ./V1.1/DeckLinkAPIDispatch.o ./V1.1/DeckLinkAPIDispatch_v7_6.o ./V1.1/audio.o ./V1.1/capture.o ./V1.1/cudaEngine.o ./V1.1/decklink.o ./V1.1/engine.o ./V1.1/filter.o ./V1.1/filterKernel.o ./V1.1/initialize.o ./V1.1/main.o ./V1.1/playback.o ./V1.1/utils.o ./V1.1/videoFuncThread.o ./V1.1/vif.o ./V1.1/vof.o -llibAudioPreconditioning6Ch.so -lliblibConfig.so -llibtiff.so.4.3.2
/usr/bin/ld: cannot find -llibAudioPreconditioning6Ch.so
==> searching for the library I get:
/home/streaming/VidApp_V1.0/src/AudioPreconditioning6Ch/dist/Debug/GNU-Linux-x86/libAudioPreconditioning6Ch.so
/home/streaming/VidApp_V1.0/src/AudioPreconditioning6Ch/dist/Release/GNU-Linux-x86/libAudioPreconditioning6Ch.so
/home/streaming/dist/lib64/libAudioPreconditioning6Ch.so
What am I doing wrong?
Library names in Linux are not the same as in Windows. in VS, i was linking libConfig.lib, so when eclipse asked for the name of the library i typed in: liblibConfig.so which is the name of the file. Uh uh. In Linux the prefix lib is understood as a prefix and the suffix .so is also not part of the name. so entering: libConfig as the library to load (which gets inserted into make as: -llibConfig) solves the problem

Configuring LAPACK in Eclipse-Photran for fortran compiler on Windows

Update
Thank you Vladimir for the usefull insights in libraries. I took another approach, developping first in ubuntu (which was a lot easier then messing around with Eclipse/Cygwin/... and now I'm trying to port to windows, which goes rather ok, however I have some questions about that too, posted here: Problems with porting a fortran program from ubuntu to windows
Question
I currently have the following setup and can't get the lapack library configured so that my fortran code can compile:
Windows 7
Cygwin installation (for GNU fortran), added to the windows PATH
lapack and liblapack-devel installed with cygwin
resulting in liblapack.a and libblas.a in the folder C:/cygwin/lib
In my program I call the lapack library using the following code
program myProgram
!use lapack (stays commented now)
...
In Eclipse I used the following setup (with the Photran package):
Fortran Project: executable GNU fortran on Windows (GCC toolchain)
GNU fortran compiler: gfortran ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
GNU fortran linker: gfortran ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
I compiled the libraries libblas.a and liblapack.a, to use as a static library, for windows and they are located in the C:/cygwin/lib folder. In the GNU fortran linker properties, the libraries were called lapackand blasin the folder C:/cygwin/lib. This results in a part -L"C:/cygwin/lib" -llapack -lblas in the {$COMMAND} section of the compiler and linker. (thanx to #vladimir-f for the help)
In the output there are no error messages left anymore. Only I got now the following error in Eclipse and no final .exe or bins:
Errors occured during the build.
Errors running builder 'CDT Builder' on project 'Hamfem'
Internal error building project Hamfem configuration
Release
java.lang.NullPointerException
Internal error building project Hamfem configuration
Release
java.lang.NullPointerException
However, the result of the build is still an executable, in this case called Hamfem.exe. Running this file results in the error message (instead of the routine): The program can't start because cyglapack-0.dll is missing from your computer. Try reinstalling the program to fix this problem.
That file is currently located in C:/cygwin/lib/lapack/ but I want that this file isn't needed to run the program, so I can run it on different computers. Can someone collaborate on this?
Second, when copy-pasting the .dll file in the folder where the .exe is located, it runs for a brief second, generating a stackdump file. I can't use the debugger in Eclipse-Photran due to the 'Building Workspace' error. Eclipse gives the message Binary not found when I want to run it in Eclipse as a local Fortran program. Any ideas how to resolve this problem?
The problem is here
L/lib/lapack –llapack
try to change it for
-L/lib/lapack –llapack
probably it is in you Makefile.
i.e.
gfortran -funderscoring -O3 -Wall -c -fmessage-length=0 -L/lib/lapack -llapack -o
And make sure lapack.mod is really in /lib/lapack which is probably C:\cygwin\lib\lapack on Cygwin.