View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013479CMakeCMakepublic2012-08-17 05:232013-01-09 14:05
ReporterMarkus Blatt 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
Platformx86_64OSGNU/LinuxOS VersionDebian wheezy
Product VersionCMake 2.8.9 
Target VersionCMake 2.8.10Fixed in VersionCMake 2.8.10 
Summary0013479: add_library documentation does not mention POSITION_INDEPENDENT_CODE property
DescriptionI need to used the object libraries for building libs out of serveral convenient libraries.

When trying to build shared libraries by using set(BUILD_SHARED_LIBS ON) the compilation with gcc fails with

"[100%] Building CXX object CMakeFiles/a.dir/dummy.cc.o
[100%] Built target a
Linking CXX shared library libb.so
/usr/bin/ld: CMakeFiles/a.dir/dummy.cc.o: relocation R_X86_64_32 against `_ZSt4cout' can not be used when making a shared object; recompile with -fPIC
CMakeFiles/a.dir/dummy.cc.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [libb.so] Error 1
make[1]: *** [CMakeFiles/b.dir/all] Error 2
make: *** [all] Error 2
"
Steps To ReproduceSetup the attached testcase and call cmake && make
TagsNo tags attached.
Attached Filesgz file icon testcase.tar.gz [^] (564 bytes) 2012-08-17 05:23

 Relationships

  Notes
(0030688)
Brad King (manager)
2012-08-17 08:36

The BUILD_SHARED_LIBS option only affects whether add_library defaults to SHARED or STATIC. CMake has no idea what you're going to do with the object files in an OBJECT library. In CMake 2.8.9 you can set the POSITION_INDEPENDENT_CODE property:

 http://www.cmake.org/cmake/help/v2.8.9/cmake.html#prop_tgt:POSITION_INDEPENDENT_CODE [^]

on the object library to get -fPIC. Add this line to your example:

 set_property(TARGET a PROPERTY POSITION_INDEPENDENT_CODE 1)
(0030807)
Markus Blatt (reporter)
2012-08-31 06:20

I did not know this property. Thanks a lot.

Is it mentioned in the add_library documentation?

Wouldn't it be more user-friendly to honor a supplied SHARED option?
(0030809)
Brad King (manager)
2012-08-31 07:40

Re 0013479:0030807: The property was just added in CMake 2.8.9. I've updated the documentation of add_library to mention it:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4eaea3c3 [^]
(0032083)
Robert Maynard (manager)
2013-01-09 14:05

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2012-08-17 05:23 Markus Blatt New Issue
2012-08-17 05:23 Markus Blatt File Added: testcase.tar.gz
2012-08-17 08:36 Brad King Note Added: 0030688
2012-08-31 06:20 Markus Blatt Note Added: 0030807
2012-08-31 07:40 Brad King Note Added: 0030809
2012-08-31 07:40 Brad King Assigned To => Brad King
2012-08-31 07:40 Brad King Priority high => normal
2012-08-31 07:40 Brad King Severity major => minor
2012-08-31 07:40 Brad King Status new => resolved
2012-08-31 07:40 Brad King Resolution open => fixed
2012-08-31 07:40 Brad King Fixed in Version => CMake 2.8.10
2012-08-31 07:40 Brad King Target Version => CMake 2.8.10
2012-08-31 07:40 Brad King Summary buildig shared libs from object libraries fails because of missing -fPIC opion => add_library documentation does not mention POSITION_INDEPENDENT_CODE property
2013-01-09 14:05 Robert Maynard Note Added: 0032083
2013-01-09 14:05 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team