I am trying to build an executable which should be linked with the
- mosquitto (
libmosquitto.a
) - json-c (
libjson-c.a
)
Also, there is a custom C API built as a static library as well: myCAPI.a
My linux is Ubuntu 18.04 running under virtual machine. Also, I am using cmake
tool.So, when I'm trying to build an executable I am getting the following linking errors:
myCAPI.a(some_client.c.o): relocation R_X86_64_32S against symbol 'valueTypes' can not be used when making a PIE object; recompile with -fPIClibmosquitto.a(connect.c.o): relocation R_X86_64_32 against '.rodata' can not be used when making a PIE object; recompile with -fPIC// etc.libjson-c.a(strerror_override.c.o): relocation R_X86_64_32S against '.data' can not be used when making a PIE object; recompile with -fPIC// etc.
I have a googled a lot and find some articles where it is said that the issue is connected to gcc's version (either PIE or PIC is selected as an option). So, I tried to build my environment as follows:
cmake -no-pie ../
Also in this way as well:
cmake -fPIC ../
Here is my CMakelists.txt
cmake_minimum_required(VERSION 3.10)set(EXAMPLE_NAME "PublishValues")project(${EXAMPLE_NAME})file(GLOB SOURCES "src/*.c")include_directories(include ../../include )set(PROJECT_LINK_LIBS libtvcmiclient.a libmosquitto.a libcares.a libjson-c.a libssl.a libcrypto.a libpthread.so libdl.so)link_directories(../../3rdparties ../../libs)add_executable(${EXAMPLE_NAME} ${SOURCES})target_link_libraries(${EXAMPLE_NAME} ${PROJECT_LINK_LIBS})
Unfortunately, the linking errors still there.