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

Karthik Krishnan karthik.krishnan at kitware.com
Thu May 31 09:29:31 EDT 2007


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)

--
karthik

On 5/31/07, Mathieu Malaterre <mathieu.malaterre at gmail.com> wrote:
>
> Hello,
>
>   I have the following two targets:
>
> ADD_LIBRARY(foo STATIC ${foo_C_SRCS}) # C files
> ADD_LIBRARY(bla SHARED ${bla_CPP_SRCS}) # CXX files
> TARGET_LINK_LIBRARIES(bla foo)
>
>   When compiled with cmake on a 64bits machine I am getting:
>
> ...
> relocation R_X86_64_32 can not be used when making a shared object;
> recompile with -fPIC
> ...
>
>   Is this ok on most system, or there something against static lib
> used in a shared lib ?
>
> thanks,
>
> --
> Mathieu
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070531/ac7f6988/attachment.htm


More information about the CMake mailing list