You are not logged in.

#1 2016-09-20 11:48:35

mhf2
Member
Registered: 2016-09-20
Posts: 5

Compile c++ program statically linked with openmp

I wan to compile a c++ program that must be linked statically.

I get this error when I compile it with g++:

usr/bin/ld: cannot find -lomp
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)

I know this problem occurs because I do not have static libraries for openmp.

How can I install them in arch?

Offline

#2 2016-09-20 11:57:19

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,787
Website

Re: Compile c++ program statically linked with openmp

Static libraries are stripped out of (most) Arch packages by default. You will need to recompile the packages with the staticlibs option. See 'man PKGBUILD' for more information.

Why do you need to compile this program with static libs?


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2016-09-20 12:00:00

mhf2
Member
Registered: 2016-09-20
Posts: 5

Re: Compile c++ program statically linked with openmp

WorMzy wrote:

Static libraries are stripped out of (most) Arch packages by default. You will need to recompile the packages with the staticlibs option. See 'man PKGBUILD' for more information.

Why do you need to compile this program with static libs?

Thanks for the prompt response. I need to run the program on the server that does not have compiling tools.

I am new to arch linux. How can I use "PKGBUILD -staticlibs" to recompile packages?

I am getting confuse when I checked this:
https://wiki.archlinux.org/index.php/PKGBUILD

Last edited by mhf2 (2016-09-20 12:06:09)

Offline

#4 2016-09-20 12:05:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: Compile c++ program statically linked with openmp

mhf2 wrote:

Thanks for the prompt response. I need to run the program on the server that does not have compiling tools.

This does not mean you need to compile statically.  You just need to either build against the same version of libs that are on the server, then the binary will run fine.  Alternatively, you can build against arch's current libs and copy the so's over to the server too (and maybe use a little LD_PRELOAD magic).

Either of these will likely be much easier than static linking in arch.  What WorMzy didn't specify above is that yes, you can keep the static libs of your dependencies by just rebuilding them.  But this becomes a living hell when you realize you need to rebuild static versions of all your dependencies dependencies recursively.  If you want to do this, fire up a VM of Stali*, or another distro designed for static linking.  It will save a lot of hassle.

*note: I have no experience with Stali, I'm not actually sure how well it specifically would work.  This was just an example.  But if you are going to fire up a VM anyways, just use a compatible distro to the one on the server, install the build tools, build in the VM, then deploy the binary.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2016-09-20 12:10:29

mhf2
Member
Registered: 2016-09-20
Posts: 5

Re: Compile c++ program statically linked with openmp

Trilby wrote:
mhf2 wrote:

Thanks for the prompt response. I need to run the program on the server that does not have compiling tools.

This does not mean you need to compile statically.  You just need to either build against the same version of libs that are on the server, then the binary will run fine.  Alternatively, you can build against arch's current libs and copy the so's over to the server too (and maybe use a little LD_PRELOAD magic).

Either of these will likely be much easier than static linking in arch.  What WorMzy didn't specify above is that yes, you can keep the static libs of your dependencies by just rebuilding them.  But this becomes a living hell when you realize you need to rebuild static versions of all your dependencies dependencies recursively.  If you want to do this, fire up a VM of Stali*, or another distro designed for static linking.  It will save a lot of hassle.

*note: I have no experience with Stali, I'm not actually sure how well it specifically would work.  This was just an example.  But if you are going to fire up a VM anyways, just use a compatible distro to the one on the server, install the build tools, build in the VM, then deploy the binary.


Thanks. How can build the code using the lib version on the server?

Last edited by mhf2 (2016-09-20 12:10:47)

Offline

#6 2016-09-20 12:43:45

Starfish
Member
From: Germany
Registered: 2015-10-21
Posts: 134

Re: Compile c++ program statically linked with openmp

Could you post the output of

pacman -Ql openmp

on your computer as well as your server? If the server has no Arch, then look for the equivalent command in apt-get or whatever.

FYI: If you compile with an option of the structure

-lname

the compiler looks by default for a dynamic library called

/usr/lib/libname.so

which is sometimes a symblic link to a library of a particular version

/usr/lib/libname.so.x

that then can be invoked at runtime. The ".x" is denotes the version number. If you want to compare the omp versions of the server and your pc, these are the files you should look at.

I hope this helps.


"Yesterday is history, tomorrow is a mystery, but today is a gift. That is why it is called the present." - Master Oogway

Offline

#7 2016-09-20 13:12:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,449
Website

Re: Compile c++ program statically linked with openmp

mhf2 wrote:

How can build the code using the lib version on the server?

Trilby wrote:

use a compatible distro to the one on the server, install the build tools, build in the VM, then deploy the binary.

As an alternative to a VM you may be able to use a systemd-nspawn container.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2016-09-21 00:04:55

mhf2
Member
Registered: 2016-09-20
Posts: 5

Re: Compile c++ program statically linked with openmp

Thank you. I solved the problem by installing ubuntu in VM.

Offline

Board footer

Powered by FluxBB