[CMake] relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC

Mathieu Malaterre mathieu.malaterre at gmail.com
Thu May 31 12:57:45 EDT 2007


On 5/31/07, Karthik Krishnan <karthik.krishnan at kitware.com> wrote:
> Hi Mathieu,
>
> I had a few build errors too on my 64b machine, when linking a static
> library into a shared one such as :
>
>  /usr/bin/ld: ...: relocation R_X86_64_32 against `a local symbol' can not
> be used when making a shared object; recompile with -fPIC
>
>
> The fix I've had is to stick the following lines in the CMakeLists of the
> appropriate libraries and it seems to work. (ripped off from KDE) :
>
> # with -fPIC
> IF(UNIX AND NOT WIN32)
>   FIND_PROGRAM(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
>   IF(CMAKE_UNAME)
>     EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR)
>     SET(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL
> "processor type (i386 and x86_64)")
>      IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
>       ADD_DEFINITIONS(-fPIC)
>     ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
>   ENDIF(CMAKE_UNAME)
> ENDIF(UNIX AND NOT WIN32)

Why not use directly CMAKE_SYSTEM_PROCESSOR ?

IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
  SET_TARGET_PROPERTIES(bar PROPERTIES COMPILE_FLAGS "-fPIC")
ENDIF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )

thanks,
-Mathieu


More information about the CMake mailing list