.rodata can not be used when making a PIE object

Hi,

I am building Slicer in ubuntu 18.04. I followed every step in https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions#Linux. But now I run into a build error: /usr/bin/ld: CMakeFiles/vtkParseJava.dir/vtkParseJava.c.o: relocation R_X86_64_32 against .rodata can not be used when making a PIE object; recompile with -fPIC.
/usr/bin/ld: …/…/lib/libvtkWrappingTools-8.2.a(vtkParseMain.c.o): relocation R_X86_64_32 against `.rodata’ can not be used when making a PIE object; recompile with -fPIC

My environment is:
gcc/g++ 7.3, qt5.12, cmake 3.14, python 2.17.

My cmake command is
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DQt5_DIR:PATH=/home/me/Qt/5.12.0/gcc_64/lib/cmake/Qt5 -DSlicer_USE_SYSTEM_QT:BOOL=1 -DQT_QMAKE_EXECUTABLE=/home/me/Qt/5.12.0/gcc_64/bin/qmake …/Slicer

Could anyone please help me out? I tried to add -fPIC in CMakeLists.txt as this post, https://stackoverflow.com/questions/19364969/compilation-fails-with-relocation-r-x86-64-32-against-rodata-str1-8-can-not. But it still doesn’t work.

Thanks a lot.

Hi @Zhiy,

I would try first with a clean build directory.
the errors show libvtkWrappingTools-8.2.a, which is a static library, when the default option in Slicer is to BUILD_SHARED_LIBS:BOOL=ON but that doesn’t correspond to the CMake options you posted.

Also, QT_QMAKE_EXECUTABLE is a Qt4 option, so you don’t need it.

Clean the build folder (the whole folder, not only the subfolder Slicer-build)
And then try with:

cmake -DCMAKE_BUILD_TYPE:STRING=Debug \
-DQt5_DIR:PATH=/home/me/Qt/5.12.0/gcc_64/lib/cmake/Qt5 \
-DSlicer_USE_SYSTEM_QT:BOOL=1 \
../Slicer

This is just a first aid intuition. Let us know if you still hit the problem after that!

It solves my problem, except that I also followed the solution of makedev problem in this post: Building failure on Ubuntu. Thank you a lot.