cmake create a shared object
Cmake builds on separate build directories by default (I did not test this example):
PROJECT(myproject)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(mylibSRCS lib.c)
SET(myprogSRCS client.c)
ADD_LIBRARY(mylib ${mylibSRCS})
ADD_EXECUTABLE(myprog ${myprogSRCS})
TARGET_LINK_LIBRARIES(myprog mylib)
You do:
mkdir build
cd build
cmake ..
make
Everything would be under build.
Update: As mentioned by @chryss below, if you want the .so file to be generated, the command should be:
ADD_LIBRARY(mylib SHARED ${mylibSRCS})
This solution will not create a .so
file, but a cmake equivalent for further inclusion with cmake.
I am searching for a solution with will provide the equivalent to this:
g++ -shared -Wl,-soname,plugin_lib.so.1 -o plugin_lib.so plugin_lib.o
Which will generate a plugin_lib.so
that can be loaded dynamically with dlopen at runtime.
The solution is missing the "SHARED" option like so:
ADD_LIBRARY(mylib SHARED ${mylibSRCS})