Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Want to safely build shared library that doesn't need Intel shared libraries

rcarreiro
Beginner
270 Views
The shared library I am attempting to build (supplying the "-shared" flag to icpc) apparently depends on three Intel-supplied libraries: $ ldd libTheLibrary.so linux-gate.so.1 => (0xffffe000) libimf.so => /opt/intel/Compiler/11.1/072/lib/ia32/libimf.so (0x40044000) libsvml.so => /opt/intel/Compiler/11.1/072/lib/ia32/libsvml.so (0x402aa000) libm.so.6 => /lib/tls/libm.so.6 (0x403de000) libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40400000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x404bd000) libintlc.so.5 => /opt/intel/Compiler/11.1/072/lib/ia32/libintlc.so.5 (0x404c5000) libc.so.6 => /lib/tls/libc.so.6 (0x40508000) libdl.so.2 => /lib/libdl.so.2 (0x4062c000) /lib/ld-linux.so.2 (0x80000000)

I would prefer that the shared lib not depend on Intel shared libraries so it can be used on various machines without having to also copy over the shared libraries.

Now, if I build with "-shared -static-intel" those dependencies go away, so presumably they are being linked in statically (and I see that while there is no libintlc.a, "-lintlc" is simply dropped from the generated link line when -static-intel is used) which on the surface is exactly what I want. However, as I understand it, it is bad to statically link things you did not build into a shared library since you have no idea if the objects in the static library are PIC or not, and if they are not PIC, you could have problems.

When I look in the compiler's lib directory, while I see libimf_pic.a for some libraries I do not see a libsvml.a. So is it safe to statically link against libsvml when making a shared library? And does the compiler automatically link to libimf_pic.a when using "-shared -static-intel" or is that something I need to manually do?

Hmm. Perhaps a shorter version of this is: what exactly does "-static-intel" do and is it safe to build shared libraries using it. :)

0 Kudos
4 Replies
dpeterc
Beginner
270 Views
I think Intel's engineers were smart enough to link only PIC code into library.

Also, modern linkers in linux do not include the whole library staticall but only the parts which are actually used.

I had same problems / doubts as you a couple of yars ago, but now I link my own shared libraries with
-fPIC -static-intel
and it works without any problems, libraries are not huge (do not increase by the size of intel's library), and does not introduce any new library dependencies.
0 Kudos
Yang_W_Intel
Employee
270 Views
If -static-intel is specified, Intel libraries are linked in statically, with the exception of Intel's OpenMP runtime support library, which is linked in dynamically. If you don't use OpenMP, it should be safe.
0 Kudos
rcarreiro
Beginner
270 Views
I figured that -static-intel will statically link in the Intel libs. But are all the Intel-provided libs that are capable of being statically linked 100% PIC?
0 Kudos
Yang_W_Intel
Employee
270 Views
Intel's OpenMP runtime support library is linked in dynamically. If you don't use OpenMP, it should be fine.
0 Kudos
Reply