开发者

Statically linking against LAPACK

I'm attempting to do a release of some software开发者_C百科 and am currently working through a script for the build process. I'm stuck on something I never thought I would be, statically linking LAPACK on x86_64 linux. During configuration AC_SEARCH_LIB([main],[lapack]) works, but compilation of the lapack units do not work, for example undefiend reference to 'dsyev_' --no lapack/blas routine goes unnoticed.

I've confirmed I have the libraries installed and even compiled them myself with the appropriate options to make them static with the same results.

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

The two methods I'm using to compile are the following,

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


Your linking order is wrong. 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

That should resolve the linkage problems.


To answer the subsequent question why this works, the GNU ld documentation say this:

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o' searches libraryz' after file foo.o but before bar.o. If bar.o refers to functions in `z', those functions may not be loaded.

........

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.

ie. the linker is going to make one pass through a file looking for unresolved symbols, and it follows files in the order you provide them (ie. "left to right"). If you have not yet specified a dependency when a file is read, the linker will not be able to satisfy the dependency. Every object in the link list is parsed only once.

Note also that GNU ld can do reordering in cases where circular dependencies are detected when linking shared libraries or object files. But static libraries are only parsed for unknown symbols once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜