Statically linking libgomp

1,020 views
Skip to first unread message

Rodrigo Queiro

unread,
Oct 18, 2017, 6:52:06 AM10/18/17
to bazel-discuss
Hey bazel-discuss@,

I'm building something depends on libgomp as it compiles with -fopenmp. I'd like to statically link this in to make the binary more portable. I don't want to build a fully-static library, as this breaks getaddrinfo().

This can be done with gcc using -static-libstdc++ or -Wl,-Bstatic -lgomp -Wl,-Bdynamic. -static-libstdc++ doesn't work with Bazel because of #2840. The latter doesn't work, as the "-lgomp" is removed and put in the params file.

I could check in libgomp.a into the repo, or work out where to load it from the local system, but those both seem messy.

Can anyone suggest what the best way to do this would be?

Thanks,
Rodrigo


-- 
Google Germany GmbH | Erika-Mann-Strasse | 80636 Muenchen | Germany

AG Hamburg, HRB 86891 | Sitz der Gesellschaft: Hamburg | Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

musiccom...@gmail.com

unread,
Oct 26, 2017, 12:53:31 PM10/26/17
to bazel-discuss
On Wednesday, October 18, 2017 at 3:52:06 AM UTC-7, Rodrigo Queiro wrote:
> Hey bazel-discuss@,
>
>
> I'm building something depends on libgomp as it compiles with -fopenmp. I'd like to statically link this in to make the binary more portable. I don't want to build a fully-static library, as this breaks getaddrinfo().
>
>
> This can be done with gcc using -static-libstdc++ or -Wl,-Bstatic -lgomp -Wl,-Bdynamic. -static-libstdc++ doesn't work with Bazel because of #2840. The latter doesn't work, as the "-lgomp" is removed and put in the params file.
>
>
> I could check in libgomp.a into the repo, or work out where to load it from the local system, but those both seem messy.
>
>
> Can anyone suggest what the best way to do this would be?

A somewhat-hacky way to accomplish this is to use syntax like -l:libgomp.a to force the linker to search for only the static library.

rodr...@google.com

unread,
Oct 27, 2017, 5:28:06 AM10/27/17
to bazel-discuss
On Thursday, October 26, 2017 at 6:53:31 PM UTC+2, musiccom...@gmail.com wrote:
> A somewhat-hacky way to accomplish this is to use syntax like -l:libgomp.a to force the linker to search for only the static library.

Thanks for the suggestion. In the end, I added it to the container, which seemed more in the spirit of "mostly-static".

https://github.com/GoogleCloudPlatform/distroless/commit/5366dba4c963356e21a3f23144a3b3307287bc54

Reply all
Reply to author
Forward
0 new messages