Commit 51904271 authored by Rashad Kanavath's avatar Rashad Kanavath

COMP: fix linker option for otb and other projects

GNU ld now enables -Wl,-as-needed by default. This cause issue on
our side in the final package.
ITK: we link with ITK_LIBRARIES which includes, itknetlib and was not
linked with any of OTB module. This bug was seen in windows package
testing.
https://dash.orfeo-toolbox.org/testDetails.php?test=59861738&build=287155

Shark: This is another example where wl,-as-needed is causing trouble
shark link with a couple of boost libraries but no of them are linked
into libshark.so due to default -Wl,-as-needed. With this option, the
linker will drop an lib or .so on command line if none of it's symbols
are used by the project.

In both cases (ITK and Shark), there are upstream issues. Shark should
not add boost_system to link flags if it is not used in sharklib. Maybe
this boost component is used in examples. I don't know much. It is
really an upstream issue.
Same case with ITK, if itknetlib is built by default, and is not
necessary for the activated itk modules, it should skip that.

To get back old behaviour, we have to use -Wl,no-as-needed.
The other option; Wl-no-undefined is to trigger a link error if an
undefined reference is found.

The exact behaviour of as-needed and no-undefined can be found on GNU LD
man pages (man ld).
parent 25bb0e38
......@@ -141,6 +141,14 @@ add_custom_target(OTB_DEPENDS
)
if(LINUX)
string(REGEX REPLACE
"-Wl,--no-undefined"
"-Wl,--no-undefined -Wl,-no-as-needed"
SB_CMAKE_CACHE_ARGS
"${SB_CMAKE_CACHE_ARGS}")
endif()
ExternalProject_Add(OTB
DEPENDS ${OTB_DEPENDENCIES}
PREFIX OTB
......
......@@ -158,6 +158,12 @@ if(MSVC)
endif()
endif()
if(LINUX)
list(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
list(APPEND CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined")
list(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--no-undefined")
endif()
if(DEFINED ENV{CMAKE_PREFIX_PATH})
set(SB_CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH};${SB_INSTALL_PREFIX}")
else()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment