| View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||
| 0014968 | CMake | CMake | public | 2014-06-11 12:08 | 2015-01-05 08:38 | ||||
| Reporter | Nico Schlömer | ||||||||
| Assigned To | |||||||||
| Priority | normal | Severity | major | Reproducibility | always | ||||
| Status | closed | Resolution | won't fix | ||||||
| Platform | OS | OS Version | |||||||
| Product Version | |||||||||
| Target Version | Fixed in Version | ||||||||
| Summary | 0014968: -fPIC not properly forwarded through OBJECT libraries | ||||||||
| Description | When compiling a project that includes an OBJECT library, e.g., ``` project(mytest C) add_library(test2 OBJECT test2.c) add_library(test test.c $<TARGET_OBJECTS:test2>) ``` and if BUILD_SHARED_LIBS is set to ON, the compile switch `-fPIC` will be correctly added to the sources of `test`, but not to the sources of `test2`. The library fails to link. | ||||||||
| Additional Information | The attachment contains a minimal failing example. | ||||||||
| Tags | No tags attached. | ||||||||
| Attached Files | |||||||||
| Relationships | |
| Relationships |
| Notes | |
|
(0036159) Brad King (manager) 2014-06-11 13:08 |
This is by design. The compilation of an OBJECT library is not influenced by its consumers. You can set the POSITION_INDEPENDENT_CODE target property on the OBJECT library. |
|
(0036160) Nico Schlömer (reporter) 2014-06-11 14:29 |
Hm, too bad. It's been quite comfortable not having to deal with specific flags needed for shared library objects. Would you recommend to do ``` IF(BUILD_SHARED_LIBS) SET(CMAKE_POSITION_INDEPENDENT_CODE ON) ENDIF() ``` or is there an even better way to handle things? |
|
(0036161) Brad King (manager) 2014-06-11 15:07 |
Re 0014968:0036160: That will work but it will also enable -fPIC on libraries that are explicitly marked STATIC. You could set it directly on the object library:add_library(test2 OBJECT test2.c) if(BUILD_SHARED_LIBS) # These objects will be consumed by a shared library. set_property(TARGET test2 PROPERTY POSITION_INDEPENDENT_CODE ON) endif() |
|
(0036162) Nico Schlömer (reporter) 2014-06-11 15:17 |
Ideally I'd want CMake to add `-fPIC` whenever it is necessary, but I guess I live with setting PIC globally ON. Feel free to close. |
|
(0037564) Robert Maynard (manager) 2015-01-05 08:38 |
Closing resolved issues that have not been updated in more than 4 months. |
| Notes |
| Issue History | |||
| Date Modified | Username | Field | Change |
| 2014-06-11 12:08 | Nico Schlömer | New Issue | |
| 2014-06-11 12:08 | Nico Schlömer | File Added: 2014-06-11-fpic-object-lib.tar.bz2 | |
| 2014-06-11 13:08 | Brad King | Note Added: 0036159 | |
| 2014-06-11 14:29 | Nico Schlömer | Note Added: 0036160 | |
| 2014-06-11 15:07 | Brad King | Note Added: 0036161 | |
| 2014-06-11 15:17 | Nico Schlömer | Note Added: 0036162 | |
| 2014-06-11 15:44 | Brad King | Status | new => resolved |
| 2014-06-11 15:44 | Brad King | Resolution | open => won't fix |
| 2015-01-05 08:38 | Robert Maynard | Note Added: 0037564 | |
| 2015-01-05 08:38 | Robert Maynard | Status | resolved => closed |
| Issue History |
| Copyright © 2000 - 2018 MantisBT Team |