Link error with gcc 11.2.1
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 270
- Forks
- 60
- PR merge metrics
- No merged PRs in 30d
Description
I'm seeing the following link error when building locally using the following commands:
$ mkdir build
$ cd build
$ cmake ..
$ make
[ 59%] Linking C shared library libuvwasi.so
/usr/bin/ld: _deps/libuv-build/libuv_a.a(random.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
...
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/uvwasi.dir/build.make:210: libuvwasi.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:196: CMakeFiles/uvwasi.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
This can be avoided around by setting CMAKE_POSITION_INDEPENDENT_CODE to True:
$ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=True ..
This could also be set in CMakeLists.txt:
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
GCC version:
$ gcc --version
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
I'm not sure if this is an issue with my local environment, as the CI servers are obviously working as expected. But I wanted to create this issue just in case anyone else runs into it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported build with GCC 11.2.1 using the commands in the issue, then inspect CMakeLists.txt and the configuration of the libuv dependency. Confirm whether enabling position-independent code in the project resolves the shared-library link error, and verify that the normal CMake build completes without the relocation failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cmake
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100