Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

link dynamic and static libraries

fipellac
Beginner
2,303 Views
Hi Folks,

I want to link static and dynamic libraries. I want to do it using ifort.

For example we have several source code test1.F and test2.F and we compile by the meaning of:

/opt/intel/Compiler/11.1/069/bin/intel64/ifort -fpic -assume 2underscore -I/ansys_inc/v121/CFX/include -I/home/user/lib -o linux-amd64//test1.o -c test1.F
/opt/intel/Compiler/11.1/069/bin/intel64/ifort -fpic -assume 2underscore -I/ansys_inc/v121/CFX/include -I/home/user/lib -o linux-amd64//test2.o -c test2.F

Once these are compiled I want to link them with static libraries, in this case PVM libraries (libfpvm3.a, libpvm3.a, libpvmtrc.a, libgpvm3.a):

ifort -shared -L/usr/lib -lpvm3 -lgpvm3 -lfpvm3 -lpvmtrc -o ./linux-amd64//libtest.so linux-amd64//test1.o linux-amd64//test2.o

This was doesn't seem to work since the needed functions remained like undefined symbol.

Thanks in advance.

FP
0 Kudos
2 Replies
Kevin_D_Intel
Employee
2,303 Views

Probably the static libraries need to be searched multiple times. 'ld' only makes one pass by default. To force multiple passes try adding the highlighted start-group/end-group options:

ifort -shared -L/usr/lib -Wl,--start-group -lpvm3 -lgpvm3 -lfpvm3 -lpvmtrc -Wl,--end-group-o ./linux-amd64//libtest.so linux-amd64//test1.o linux-amd64//test2.o

There's an alternative syntax using -Xlinker, that would be something like:

ifort -shared -L/usr/lib -Xlinker --start-group -Xlinker $(LIBS) -Xlinker --end-group-o ./linux-amd64//libtest.so linux-amd64//test1.o linux-amd64//test2.o

Where you would need to define $(LIBS) inside a makefile or script to be the list of libraries. Outside of a makefile/script,youwould specify each library with a leading -Xlinker option.

0 Kudos
TimP
Honored Contributor III
2,303 Views
If your pvm libraries are set up to support linking without --start-group ... --end-group, it will be necessary (with gnu ld linker) to specify them in order. For example, the Fortran wrapper library probably requires base library functions, but not vice versa.
0 Kudos
Reply