I am trying to include NATS C client as a dependency to my project. I prefer to link statically as my project is quite small and works as a standalone service, so shipping one single executable is more convenient.
ExternalProject_Add
seems the most promising for its compatibility with a variety of build systems. But I get link errors when building with this approach:
3rd_party/nats/build/src/libnats_static.a(mutex.c.o): In function `natsMutex_Create':
mutex.c:(.text+0x36): undefined reference to `pthread_mutexattr_init'
mutex.c:(.text+0x4b): undefined reference to `pthread_mutexattr_settype'
mutex.c:(.text+0xc0): undefined reference to `pthread_mutexattr_destroy'
mutex.c:(.text+0x19d): undefined reference to `pthread_mutexattr_destroy'
3rd_party/nats/build/src/libnats_static.a(mutex.c.o): In function `natsMutex_TryLock':
mutex.c:(.text+0x1b5): undefined reference to `pthread_mutex_trylock'
...
The weird part is when I changed the link method from static to shared, the build succeeds and the program works as expected. The related codes are included in the CMakeLists.txt
.
The source code that produces the error above can be fetched by git clone https://github.com/onichandame/nats-epics.git --branch question --depth 1
The development environment is CentOS 8. I made a docker image for this environment onichandame/docker-dev