[gmx-developers] Re: help needed: static builds with cmake
szilard.pall at cbr.su.se
Fri Oct 29 13:16:22 CEST 2010
> On Thu, Oct 28, 2010 at 6:42 PM, Szilárd Páll <szilard.pall at cbr.su.se>
>> > 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.
OK, that makes sense. I'll post today on the CMake mailing list and
will get back with an update.
>> > 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
I'll add step 1. Just checked and it seems that on most UNIX systems
static libraries have ".a" suffix (a suffix preference list is used
internally in CMake). Can you (or anyone else) confirm that on most
common HPC *NIX systems this is the case?
Moreover, as it's not very harmful to have an exclusive check that
enables the option for all UNIX but APPLE and CYGWIN (CMake
terminology) I'll do that.
More information about the gromacs.org_gmx-developers