Skip to content

Link error with gcc 11.2.1 #175

@danbev

Description

@danbev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions