missing compiler flag for position independent code (-fPIC)
Whenever I update the OpenCL SDK and build into an existing build directory I get a link error:
[ 74%] Linking CXX shared library libOpenCLSDKCpp.so
/usr/bin/ld: libsfml-system-s.a(Err.cpp.o): warning: relocation against `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' in read-only section `.text.unlikely'
/usr/bin/ld: libsfml-window-s.a(Window.cpp.o): relocation R_X86_64_PC32 against symbol `_ZNKSt5ctypeIcE8do_widenEc' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
Removing everything in the build directory and starting fresh does seem to "fix" the build, but this also redownloads all dependencies, etc, so it's a fairly big hammer. I think it would be better to build at least the OpenCL SDK static libraries with position independent code, instead.
For now, I've added this to the top of my OpenCL SDK CMakeLists.txt, and it seems to be working for me:
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
We could be more selective if we choose to, though, and instead enable position independent code for specific targets:
set_property(TARGET my_target_name PROPERTY POSITION_INDEPENDENT_CODE ON)
If anyone else is running into this problem, you can also enable position independent code on the command line, similar to:
cmake .. -DOPENCL_SDK_BUILD_OPENGL_SAMPLES=1 -DCMAKE_POSITION_INDEPENDENT_CODE=1