View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0002233 | CMake | CMake | public | 2005-09-14 14:12 | 2005-11-28 15:21 | ||||
Reporter | Mathieu Malaterre | ||||||||
Assigned To | Bill Hoffman | ||||||||
Priority | low | Severity | minor | Reproducibility | always | ||||
Status | closed | Resolution | no change required | ||||||
Platform | OS | OS Version | |||||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0002233: -fPIC flags are required to build static lib on Linux/AMD64 | ||||||||
Description | I cannot build properly ITK in static lib unless I explicitely set the C/CXX flags to use -fPIC. It would be nicer if cmake was aware of this. OS: Linux gentoo, AMD64. gcc 3.4.4 | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
Relationships | |
Relationships |
Notes | |
(0003022) Mathieu Malaterre (developer) 2005-09-14 14:49 |
---- Shared libraries must be compiled with -fPIC. i386 and other ports tolerate shared libraries that are not compiled with -fPIC. On x86-64 this leads to a crash when accessing external symbols to the shared library (e.g. symbols declared in the main program) because only 32bit relocations are used for referencing them. The shared library is loaded more than 32bits away from the main program. The 32bit relocations sometimes work between shared libraries when they are loaded at startup because then the shared libraries are within reach of 32bit, but it may fail for shared libraries that are loaded later with dlopen() for example. How to check: Run readelf -r and nm on the shared library. Relocations showing as 'U' in nm must have an corresponding entry in the GOT table shown as the '.rela.got'. ---- http://www.x86-64.org/lists/discuss/msg02621.html [^] |
(0003026) Bill Hoffman (manager) 2005-09-15 13:23 |
I don't understand why building itk static would be a problem with shared libraries? |
(0003027) Mathieu Malaterre (developer) 2005-09-15 13:46 |
Steps to reproduce: 1. Build ITK with static lib (don't change default cmake values) 2. Build InsightApplications shared libs on: Linking CXX shared library ITKFilterLib/libExample_ITKFilterLib.so /usr/lib/gcc/x86_64-pc-linux-gnu/3.4.4/../../../../x86_64-pc-linux-gnu/bin/ld: /home/mathieu/Dashboards/MyTests/Insight-static/bin/libITKCommon.a(itkDataObject.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /home/mathieu/Dashboards/MyTests/Insight-static/bin/libITKCommon.a: could not read symbols: Bad value collect2: ld returned 1 exit status make[2]: *** [ITKFilterLib/libExample_ITKFilterLib.so] Error 1 make[1]: *** [ITKFilterLib/Example_ITKFilterLib.dir/all] Error 2 make: *** [all] Error 2 You need to build ITK in static lib but have to explicitely specify -fPIC for CFLAGS/CXXFLAGS. A simple TRY_COMPILE can find out if -fPIC is needed. |
(0003049) Bill Hoffman (manager) 2005-09-23 15:25 |
In general is not valid to link shared libraries to static ones. This would also have a problem on SUN where PIC is required for shared libraries. I am inclined to say that ITK should have to match ITK applications in BUILD_SHARED flags. I don't think cmake should force -fPIC on all projects as people using only static stuff will not want it. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |