Static Link with LAPACK

I am trying to release some software and am currently working through a script for the build process. I was stuck on something that I never thought I'd be statically linking LAPACK to x86_64 linux. During configuration, AC_SEARCH_LIB([main],[lapack]) works, but compilation of shortcut units does not work, for example, undefiend reference to 'dsyev_' - the lapack / blas procedure is not executed.

I confirmed that I have installed libraries and even compiled them with the appropriate parameters to make them static with the same results.

Here is an example that I used in my first experience with LAPACK several years ago, which works dynamically, but not statically: http://pastebin.com/cMm3wcwF

The two methods I use to compile are the following:

 gcc -llapack -o eigen eigen.c gcc -static -llapack -o eigen eigen.c 
+4
source share
1 answer

Your link order is incorrect. Link libraries after the code that requires them, not before. Like this:

 gcc -o eigen eigen.c -llapack gcc -static -o eigen eigen.c -llapack 

This should solve the binding problems.


To answer the following question why this works, the GNU ld documentation says the following:

It matters when you write this option in a command; the linker searches and processes libraries and object files in the order they are specified. So foo.o -lz bar.o' searches library z' after the file foo.o, but before bar.o. If bar.o refers to functions in `z ', these functions may not load.

........

Typically, files found this way are library files β€” archive files of which the object files are members. The compiler processes the archive file and scans through it for members that identify characters that have so far been specified but not defined. But if the found file is a regular object file, it is linked in the usual way.

That is, the linker is about to make one pass through the file looking for unresolved characters, and it follows the files in the order in which you provide them (ie, "from left to right"). If you have not yet specified the dependency when reading the file, the linker will not be able to satisfy the dependency. Each object in the list of links is analyzed only once.

Note also that GNU ld can perform reordering in cases where cyclic dependencies are detected when linking shared libraries or object files. But static libraries are only parsed for unknown characters only.

+5
source

All Articles