# \[C-API\]: relocation against \`jl\_gc\_have\_ pending\_finalizers' in read-only section \`.text'

**URL:** https://discourse.julialang.org/t/c-api-relocation-against-jl-gc-have-pending-finalizers-in-read-only-section-text/79314
**Category:** General Usage
**Created:** [April 10, 2022, 8:52pm UTC](https://discourse.julialang.org/t/c-api-relocation-against-jl-gc-have-pending-finalizers-in-read-only-section-text/79314 "2022-04-10T20:52:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Clemapfel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clemapfel/32/32261_2.png) [@Clemapfel](https://discourse.julialang.org/u/Clemapfel)
#### Post date: [April 10, 2022, 8:52pm UTC](https://discourse.julialang.org/t/c-api-relocation-against-jl-gc-have-pending-finalizers-in-read-only-section-text/79314/1 "2022-04-10T20:52:23Z")

</div>

Hi, I have a simple C++ executable using the julia C-API:

`CMakeLists.txt`

```nohighlight
cmake_minimum_required(VERSION 3.12)
project(MyProject VERSION 0.0.0 LANGUAGES CXX)

add_executable(hello_world ${CMAKE_SOURCE_DIR}/main.cpp)
target_link_libraries(hello_world PRIVATE
    ${jluna}
    "/home/clem/Applications/julia/lib/libjulia.so"
)

target_include_directories(hello_world PRIVATE
    ${CMAKE_SOURCE_DIR}
    ${JULIA_INCLUDE_DIR}
)

```

Where `/home/clem/Applications/julia/lib/libjulia.so` is the correct location of my julia shared library, freshly downloaded just now.

`main.cpp`

```cpp
#include <julia.h>

int main()
{
    jl_init();

	auto* mutex = new jl_mutex_t();
    jl_mutex_init(mutex);
	jl_mutex_lock(mutex);
	jl_mutex_unlock(mutex);
	return 0;
}

```

There are no other files in the project.

When compiling using

```bash
cmake ..

```

It throws this linker error:

```julia
clem@birdnest:~/Desktop/MyProject/build$ cmake .. -DCMAKE_CXX_COMPILER=g++-11
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clem/Desktop/MyProject/build
clem@birdnest:~/Desktop/MyProject/build$ make
Scanning dependencies of target hello_world
[50%] Building CXX object CMakeFiles/hello_world.dir/main.cpp.o
[100%] Linking CXX executable hello_world
/usr/bin/ld: CMakeFiles/hello_world.dir/main.cpp.o: warning: relocation against `jl_gc_have_pending_finalizers' in read-only section `.text'
/usr/bin/ld: CMakeFiles/hello_world.dir/main.cpp.o: in function `jl_lock_frame_push':
main.cpp:(.text+0x153): undefined reference to `small_arraylist_grow'
/usr/bin/ld: CMakeFiles/hello_world.dir/main.cpp.o: in function `jl_mutex_unlock':
main.cpp:(.text+0x34e): undefined reference to `jl_gc_have_pending_finalizers'
/usr/bin/ld: main.cpp:(.text+0x370): undefined reference to `jl_gc_run_pending_finalizers'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/hello_world.dir/build.make:105: hello_world] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/hello_world.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

```

All other features of the julia C-API work fine, it is only the jl\_mutex related things that throw this error.  
It is compiler independent, both clang-12, g++10 and g++11 throw the same linker error.

Any ideas? Do I have to link against an additional target somehow? Again, all other functionality is available, so it is definitely linking to a correct and working `libjulia.so`.

---

<div class="post-metadata">

### Author: ![Clemapfel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clemapfel/32/32261_2.png) [@Clemapfel](https://discourse.julialang.org/u/Clemapfel)
#### Post date: [April 10, 2022, 9:03pm UTC](https://discourse.julialang.org/t/c-api-relocation-against-jl-gc-have-pending-finalizers-in-read-only-section-text/79314/2 "2022-04-10T21:03:50Z")

</div>

To positively verify it is only the mutex, the following `main.cpp`:

```cpp
#include <julia.h>

int main()
{
   jl_eval_string("println(\"hello julia\"");
   return 0;
}

```

Compiles with

```julia
clem@birdnest:~/Desktop/MyProject/build$ cmake .. -DCMAKE_CXX_COMPILER=g++-11
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clem/Desktop/MyProject/build
clem@birdnest:~/Desktop/MyProject/build$ make
Scanning dependencies of target hello_world
[50%] Building CXX object CMakeFiles/hello_world.dir/main.cpp.o
[100%] Linking CXX executable hello_world
[100%] Built target hello_world

```

and prints `hello julia`. No other files or arguments where changed, except the content of main.cpp
