KhronosGroup / KhronosGroup/OpenCL-SDK

missing compiler flag for position independent code (-fPIC)

Open
#128 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
777
Forks
163
Avg merge
6d 17h
Merged PRs (30d)
2

Description

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:

```cmake
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:

```cmake
set_property(TARGET my_target_name PROPERTY POSITION_INDEPENDENT_CODE ON)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the top-level CMakeLists.txt and reproduce the incremental build after updating the OpenCL SDK, using the linker error as the failing signal. Check which static libraries feed libOpenCLSDKCpp.so and verify that an existing build directory can link successfully without deleting and redownloading dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.