<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello!<div>I hope someone could finally help me. I spent about two days to find solution for my problem, but with no luck.</div><div><br></div><div>Here is my problem:</div><div><br></div><div>I want to create a shared library (dll on Windows, .so on Linux, .dylib on OS X) that contains some functions. This library should export only these functions and nothing else. I guarantee that these function are pure C functions, so no C++ STL is needed to call them.</div><div><br></div><div>Then I want to create an application that call functions from the shared library mentioned above. I mean that the application should not have these functions inside. I want OS linker to link the application with the library at runtime, when it initializes the application. I know, how to do this on Windows with Visual Studio: create DLL project, write functions and compile, then there will be two files: .dll and .lib, link the .lib file with the application and at runtime Windows will find the .dll. But how can I do so with CMake?</div><div><br></div><div>Here is my CMakeLists.txt:</div><div><br></div><div><pre style="font-family: Menlo;">cmake_minimum_required(VERSION 3.3)
project(untitled19)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(LIBRARY_SRC library.cpp)

add_library(libra SHARED ${LIBRARY_SRC})

set(SOURCE_FILES main.cpp)
add_executable(untitled19 ${SOURCE_FILES})
target_link_libraries(untitled19 libra)</pre><pre style="font-family: Menlo;"><br></pre><pre style="font-family: Menlo;">This works and both library and executable are compiled. Unfortunately library seems to be linked into the executable: ‘nm’ command shows that the executable itself exports needed functions!</pre><pre style="font-family: Menlo;">I think there should be a solution for this, but I cannot find it. Can anyone help me?</pre><pre style="font-family: Menlo;">For more clarification: I’m using OS X El Capitan.</pre><pre style="font-family: Menlo;">——</pre><pre style="font-family: Menlo;">Best regards, Ivan.</pre><pre style="font-family: Menlo;"><br></pre><pre style="font-family: Menlo;"><br></pre></div></body></html>