[CMake] What combinations must be set for *_LINKER_FLAGS?
Brad King
brad.king at kitware.com
Thu Jul 27 10:01:32 EDT 2006
Alan W. Irwin wrote:
> One of our PLplot developers with access to Mac OS X ran into the following
> error message for the shared libraries for that platform:
>
> ld: common symbols not allowed with MH_DYLIB output format with the -
> multi_module option
>
> I have no idea what constraints there are for Mac OS X linking, but
> fortunately, he was able to make an inspired guess and get around the
> problem by setting CMAKE_SHARED_LINKER_FLAGS to "-single_module". I don't
> know for sure, but I assume he did that with a -D option.
>
> To make this a permanent fix I am thinking of doing the following:
>
> if(APPLE)
> set(CMAKE_SHARED_LINKER_FLAGS "-single_module" CACHE INTERNAL "")
> endif(APPLE)
>
> Is 'CACHE INTERNAL ""' the correct way to set this variable?
If you don't want users to be able to change it this is the right way.
The standard way to do this is to put the line
set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/User.cmake)
at the VERY TOP of your top level CMakeLists.txt file before the PROJECT
command. Then put the lines
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "-single_module" CACHE STRING "Flags
used to link a shared library.")
endif(APPLE)
in the file User.cmake.
The above will change the default flags stored in that variable when a
new build tree is created. CMake will not touch the value after that so
users can still edit it. Without this override CMake would store its
own default value in the variable.
> What about all the related *_LINKER_FLAGS variables that show up in
> CMakeCache.txt? Is it necessary to set all of DEBUG, MINSIZEREL, RELEASE,
> and RELWITHDEBINFO variations as well or is CMAKE_SHARED_LINKER_FLAGS a
> "master switch" for all those variations? We don't want to lose the
> ability
> to link on Mac OS X just when we make a release.
CMAKE_SHARED_LINKER_FLAGS will be used for all configurations. The
variables with per-configuration names are appended to the main
variable's value for their respective configuration.
-Brad
More information about the CMake
mailing list