CMAKE creates a static executable instead of using a dynamic library

My cmake file

cmake_minimum_required(VERSION 2.8.4)
project(libtry CXX)

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

file(GLOB_RECURSE MAIN_SRC_FILES "src/*.cpp")
add_library (Try SHARED ${MAIN_SRC_FILES})


set(SOURCE_FILES main.cpp)
add_executable(${EXE_NAME} ${SOURCE_FILES})
target_link_libraries(${EXE_NAME} Try)

      

This file works and creates two files: a .so file and an executable and it works fine. The problem even after deleting the .so file, the executable works fine, which means the executable is statically linked.

Why is this happening and why isn't cmake using the .so file dynamically?

Update Startup dependencies ldd

confirm this. Ldd output is

linux-vdso.so.1 =>  (0x00007fffea5fe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3585779000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3585563000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f358519c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3584e96000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3585aa7000)

      

+3
c ++ cmake dynamic-linking static-linking


source to share


No one has answered this question yet

Check out similar questions:

402
When to use dynamic and static libraries
371
Static linking and dynamic linking
2
GCC dynamic link problem
2
How to include libraries in OSX packages with CMAKE
2
Linux runtime linker error
1
Can't use libc ++ with clang ++ - 5.0
0
Building CMake Executables Using Multiple Libraries
0
Compiling with static libraries
0
shared libraries were not found during the execution of the executable, even the shared library exists at the specified path
0
CMake Undefined symbols using external poco library



All Articles
Loading...
X
Show
Funny
Dev
Pics