I'm writing adapter (shared library) to some fpga API. I've got libsomelib.a and its API - somelibAPI.h. Here is a minimal example of my adapter:
somelib_adapter.h:
#include <string> namespace details { #include "somelibAPI.h" } class somelib_adapter { public: std::string foo(); }; somelib_adapter.cpp:
#include "somelib_adapter.h" using namespace details; std::string somelib_adapter::foo() { char result[64]; somelibAPI_call(result); return std::string(result); } CMakeLists.txt:
cmake_minimum_required(VERSION 3.8) project(untitled1) set(CMAKE_CXX_STANDARD 11) set(SOURCE_FILES somelib_adapter.cpp somelib_adapter.h) FIND_LIBRARY(SOMELIB_LIBRARIES NAMES libsomelib.a PATHS "${SRC_CPP_DIRECTORY}") add_library(untitled1 SHARED ${SOURCE_FILES}) set(untitled1 -Wl,--whole-archive ${SOMELIB_LIBRARIES} -Wl,--no-whole-archive) target_link_libraries(untitled1 some_other_shared_lib_used_by_somelib) cmake finds libsomelib.a but when I'm trying to nm libuntitled1.so | c++filt it does not contain symbols location of somelibAPI_call. What's more, there is an undefined reference error with executable I made to test it. What may be wrong?
EDIT: libsomelib.a is compiled with -fPIC
EDIT2: I see I misunderstood some example. Now Ive got target_link_libraries(untitled1 -Wl,--whole-archive ${SOMELIB_LIBRARIES} -Wl,--no-whole-archive some_other_shared_lib_used_by_somelib) but there is another problem: /usr/bin/ld: ../libsomelib.a(somelibAPI.o): relocation R_X86_64_32 against .rodata.str1.1 can not be used when making a shared object; recompile with -fPIC
untitled1, but never uses it. Just add needed linker flags directly totarget_link_librariescall.libsomelib.ahas not actually built with-fPIC. BTW, withmake VERBOSE=1you may see actual compilation and linking commands used in build process. You may check these commands for containing required flags.