Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Mmm, how does one statically link TBB again?

robert_jay_gould
Beginner
2,591 Views
I remember hearing that this "trick" is possible, at one's own risk of course, but wanted to statically link TBB to a little app that is just using a few containers, no scheduler.

Problem is the neither the forum search or google seem to be collaborating, so I can't find it...

So how was this done again?

Thanks
0 Kudos
16 Replies
geoffrey-burling
Employee
2,592 Views
I remember hearing that this "trick" is possible, at one's own risk of course, but wanted to statically link TBB to a little app that is just using a few containers, no scheduler.

Problem is the neither the forum search or google seem to be collaborating, so I can't find it...

So how was this done again?

Thanks

I don't know if you're still looking for the answer, but the choice of statically/dynamically linking is done through the linker you are using. If you are using the linker that comes with icl on Windows, for example, then instead of using the /MD switch use the /MT switch.

Good luck.

Geoff
0 Kudos
pvonkaenel
New Contributor III
2,592 Views

I don't know if you're still looking for the answer, but the choice of statically/dynamically linking is done through the linker you are using. If you are using the linker that comes with icl on Windows, for example, then instead of using the /MD switch use the /MT switch.

Good luck.

Geoff

Whoa, hold on a sec. Is there a source distribution of the TBB library that can be rebuilt with /mt? The version I have built into the Intel C++ Pro compiler only seems to provide stub libs and DLLs - no source code or static libraries. I guess this also makes me wonder why there are vc7.1, vc8, and vc9 versions of the libraries. If these really are stub libs, they should be compiler independent right?

Peter
0 Kudos
robert_jay_gould
Beginner
2,592 Views
Quoting - pvonkaenel

Whoa, hold on a sec. Is there a source distribution of the TBB library that can be rebuilt with /mt? The version I have built into the Intel C++ Pro compiler only seems to provide stub libs and DLLs - no source code or static libraries. I guess this also makes me wonder why there are vc7.1, vc8, and vc9 versions of the libraries. If these really are stub libs, they should be compiler independent right?

Peter

To compile from source I had to comment out some stuff, add some defines, and a few other things, but it was failing during runtime, so I gave up and used the dynamic libs. It wasn't a trivial, orsuccessfuloperation.
0 Kudos
Vladimir_P_1234567890
2,592 Views
Quoting - pvonkaenel

Whoa, hold on a sec. Is there a source distribution of the TBB library that can be rebuilt with /mt?

you can try open source version from http://www.threadingbuildingblocks.org/ver.php?fid=135

official page for commercial version is
http://www3.intel.com/cd/software/products/asmo-na/eng/294797.htm
0 Kudos
Vladimir_P_1234567890
2,592 Views
for example, then instead of using the /MD switch use the /MT switch.
/MT switch coresspond to use static runtime. there is nothing to do with tbb
0 Kudos
Vladimir_P_1234567890
2,592 Views
I remember hearing that this "trick" is possible, at one's own risk of course, but wanted to statically link TBB to a little app that is just using a few containers, no scheduler.

Problem is the neither the forum search or google seem to be collaborating, so I can't find it...

So how was this done again?

Thanks

Have you tried to use recently povided vs projects for tbb where you can building statically changing configuration type from .dll to .lib in general project option, project defaults? but as you correctly pointed there might be issues in runtime.
0 Kudos
jamiecook
Beginner
2,592 Views

Have you tried to use recently povided vs projects for tbb where you can building statically changing configuration type from .dll to .lib in general project option, project defaults? but as you correctly pointed there might be issues in runtime.

I'm trying to accomplish the same thing as OP and have been using the standard make files that come with tbb_oss. I haven't found the VS projects you are refering to but I have been able to modify the make scripts such that the compiler uses the /MT flags instead of the default /MD and have compiled tbb[_debug].dll which are approximately 10x larger than their dynamically linked counterparts, so far so good.

To do this I changed all references to /MD to /MT (in windows.cl.inc)
#MS_CRT_KEY = /MD$(if $(findstring debug,$(cfg)),d)
MS_CRT_KEY = /MT$(if $(findstring debug,$(cfg)),d)

and I also commented out the following lines to do with manifest generation
TBB.MANIFEST =
#ifneq ($(runtime),vc7.1)
#TBB.MANIFEST = tbbmanifest.exe.manifest
#endif

I'm trying to do it this way rather than by modifying my project to use dynamic linking because the output of my project is a dll which is then loaded by an application which is dynamically linked using the RELEASE versions of the CRT. By static linking my project I've been able to debug it even tho the host application is using release runtimes. When I followed the instructions of tbb to use dynamic linking I ended up with the host application loading msvc[prt]80.dll and my plugin trying to load msvc[prt]80d.dll which didn't seem to work AT ALL (understandably).

I guess I'd just like to ask if anyone has had any luck with this approach and what the impact to the scheduler is that the OP mentioned?
0 Kudos
pvonkaenel
New Contributor III
2,592 Views

That's great, thanks for the link. What are the differences between the the commercial and open source versions? Is it support, or are there any functional differences?

thanks again,
Peter
0 Kudos
robert-reed
Valued Contributor II
2,592 Views
Quoting - pvonkaenel
That's great, thanks for the link. What are the differences between the the commercial and open source versions? Is it support, or are there any functional differences?
The open source versions come out more often. That's the difference. The open source releases are divided between development (source only), stable (source plus some standard builds for supported OSes and architectures) and commercially aligned (source and binaries identical to what is put out for Intel's commercial TBB license holders). There should be no functional differences.
0 Kudos
Subodh_P_
Beginner
2,592 Views

The forum post is quite old, but still wanted to mention that now the Intel Compilers support static linking of libraries for creation of standalone binaries. One can use "-static-intel" flag to statically link libraries such as Intel TBB, this flag can be provided to icpc binary with other options. This will obviously make the binary larger in size. One can distribute this binary without the need of having the libtbb.so present at the destination system and eventually no need of LD_Config. 

Thanks,

Subodh Pachghare

0 Kudos
Alexandr_K_Intel1
2,592 Views

"-static-intel" does not statically link TBB library.

0 Kudos
Subodh_P_
Beginner
2,592 Views

Hi Alexandr,

"-static-intel" does statically linked the tbb bindings in my case. When I removed the flag, I couldn't execute the binary on system having no tbb installed. With the flag, I can execute the binary on any system. Besides here is the excerpt from the man page of icpc.

 -shared-intel

              Causes Intel-provided libraries to be linked in dynamically.

              Arguments:

              None

              Default:

              OFF               Intel(R) libraries are linked in statically, with the exception of Intel's OpenMP* runtime support library, which is linked in dynamically.

              Description:

              This option causes Intel-provided libraries to be linked in dynamically. It is the opposite of -static-intel.

              If you specify option -mcmodel=medium or -mcmodel=large, it sets option -shared-intel.

It mentions specifically "-static-intel" is opposite of "-shared-intel". 

Any comments on this?

Thanks,

Subodh Pachghare

www.thesubodh.com

0 Kudos
Vladimir_P_1234567890
2,592 Views

hello Subodh,

You are looking at Intel Compiler options and compiler runtime. Intel TBB is not a part of compiler, it is a part of Intel Parallel Studio. AFAIR the only option recognized by compiler is "-tbb". You need to check your system. Many Linux distributions include TBB libraries. Run ldd on your executable to check how you link with tbb.

--Vladimir

0 Kudos
Adel_S_
Beginner
2,592 Views

Thanks,

0 Kudos
Matthew_G_Intel1
Employee
2,592 Views

To build static TBB, add the following to build/makefile.tbb:

 

include $(tbb_root)/build/big_iron.inc

Then make clean and re-build.

0 Kudos
Jeffrey_H_Intel
Employee
2,592 Views

You don't need to change the build system at all.  Just add big_iron.inc like this:

make extra_inc=big_iron.inc

 

0 Kudos
Reply