Reputation: 47
I want to create a shared library with 'sqlite3(SHARED)' and 'glog(STATIC)' installed.
add_library(sqlite3 SHARED IMPORTED)
add_library(glog STATIC IMPORTED)
set_target_properties(sqlite3 PROPERTIES IMPORTED_LOCATION /usr/local/lib/libsqlite3.so)
set_target_properties(glog PROPERTIES IMPORTED_LOCATION /usr/local/lib/libglog.a)
add_library(${MY_LIBRARY} SHARED ${MY_SOURCE})
target_link_libraries(${MY_LIBRARY} sqlite3 glog)
This causes following error
/usr/local/lib/libglog.a: can not be used when making a shared object; recompile with -fPIC
What is wrong in CMakeLists.txt?
Upvotes: 0
Views: 336
Reputation: 20046
Your problem isn't with CMake (though you should never have hardcoded paths... use find_package
or find_library
), it's that you're trying to do something impossible. As your compiler tells you,
/usr/local/lib/libglog.a: can not be used when making a shared object; recompile with -fPIC
libglog.a
was not compiled with position-independent code, so it cannot be used in a shared library, period. There's more information here on SO: How to recompile with -fPIC
You'll need to recompile libglog.a
with -fPIC
.
Upvotes: 1