[gmx-developers] Re: help needed: static builds with cmake

Roland Schulz roland at utk.edu
Fri Oct 29 01:32:24 CEST 2010


On Thu, Oct 28, 2010 at 6:42 PM, Szilárd Páll <szilard.pall at cbr.su.se>wrote:

> Hi,
>
> >  Too me this looks like a bug in cmake. It has
> > (in Modules/Platform/Linux.cmake) LINK_STATIC_C_FLAGS "-Wl,-Bstatic". But
> I
> > think it should include the -static for gcc. It might have been
> sufficient
> > to have the Wl,-Bstatic but at least now gcc requires also the static
> > option. If you agree we should file a cmake bug report.
>
> I'm not sure it's a bug. The man page of ld clearly states that
> -Bstatic, -static, -dn, and -non_shared are equivalent. It's just that
> while gcc -Bstatic gets simply passed down to the linker, -static
> actually does something and this something makes things work -- I
> guess. Also, asking on the CMake mailing list first might might be a
> good idea.
>
Yes their are equivalent for ld. But not for gcc. Gcc adds the required
libraries (e.g. libc,  crt1.o, ...) before calling ld. And if you use
dynamic libraries the required libraries include libgcc_s. Thus you get this
error. But since this is a compiler argument, I think it is wrong that cmake
adds -Wl,-Bstatic without -static. "-Wl,-static" would be as wrong as
"-Wl,Bstatic". Only -static (without the "-Wl") is OK (optionally togehter
with the other flags). Because it is not enough to tell the linker without
telling the compiler to generate the correct list of required libs.

s
> > Does step 1 apply to the gromacs internal libraries (libmd, libgmx, ..)?
> If
> > so, I think step 1 by itself is good enough.
>
> No, for the gramcs internal libs there is the BUILD_SHARED_LIBS
> option. This is for the external libraries (fftw3, libxml2, etc).

Yes. Just realized that.

I suggest to add step 1 and wait on step 2. Step 1 by itself is very useful.
It reduces the number of required libraries (often probably enough). And it
allows to compile a fully static library relatively easily. One only needs
to add the static flag correctly for the compiler (e.g. -static for GCC).
And one won't get error messages like "attempted static link of dynamic
object".

Roland



-- 
ORNL/UT Center for Molecular Biophysics cmb.ornl.gov
865-241-1537, ORNL PO BOX 2008 MS6309
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.sys.kth.se/pipermail/gromacs.org_gmx-developers/attachments/20101028/a02bbf54/attachment.html>


More information about the gromacs.org_gmx-developers mailing list