JNI missing symbol in library built on Linux - c++

My JNI project links against 3 shared libraries: libogg, libvorbis and libtheora.
On Windows everything works fine, and on Linux there are no errors when building my shared library. However, I'm getting a missing symbol: oggpack_readinit.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(theoraplayer)
set(CMAKE_CXX_STANDARD 14)
include_directories(include)
include_directories(jnihelpers)
link_directories(lib)
if(ANDROID)
set(CMAKE_C_CFLAGS "${CMAKE_C_FLAGS} -D__GXX_EXPERIMENTAL_CXX0X__")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
else()
find_package(JNI REQUIRED)
endif(ANDROID)
include_directories(${JNI_INCLUDE_DIRS})
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
else()
message(STATUS "JNI Not found")
endif()
file(GLOB libJniHelpers_SOURCES jnihelpers/*.cpp)
file(GLOB libJniHelpers_HEADERS jnihelpers/*.h)
add_library(theoraplayer SHARED TheoraPlayer.h TheoraPlayer.cpp theoraplay/theoraplay.c ${libJniHelpers_SOURCES} ${libJniHelpers_HEADERS} NativeLogger.h NativeLogger.cpp VideoFrame.h VideoFrame.cpp TheoraDecoder.h TheoraDecoder.cpp MediaInfo.h MediaInfo.cpp AudioPacket.h AudioPacket.cpp)
set_target_properties(theoraplayer PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
set_target_properties(theoraplayer PROPERTIES INSTALL_RPATH "./")
target_link_libraries(theoraplayer ogg vorbis theora)
if(${UNIX})
set(CMAKE_CXX_FLAGS "-fPIC -O2 -Wl,--no-as-needed")
elseif(${WINDOWS})
set(CMAKE_CXX_FLAGS "/MP /EHsc /O2 /GL")
endif(${UNIX})
When I run ldd on the built library, none of the 3 libraries show up:
ldd libtheoraplayer.so
linux-vdso.so.1 (0x00007fffadd8c000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fdfc9ed0000)
libm.so.6 => /lib64/libm.so.6 (0x00007fdfc9d88000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fdfc9d68000)
libc.so.6 => /lib64/libc.so.6 (0x00007fdfc9b98000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdfca138000)

Related

GTest cannot load imported share library

I am trying to use a few imported shared libraries in a project which is to be tested through GTest. If I create test executables manually (e.g. without GTest), everything works fine. However, when enabling executables that rely on GTest, the build crashes with the following error:
<path to build dir>/test_gtest: error while loading shared libraries: ./libDependencyL2.so: >cannot open shared object file: No such file or directory
CMake Error at /usr/share/cmake-3.24/Modules/GoogleTestAddTests.cmake:112 (message):
Error running test executable.
Path: '<path to build dir>/test_gtest/test_gtest'
Result: 127
Output:
Call Stack (most recent call first):
/usr/share/cmake-3.24/Modules/GoogleTestAddTests.cmake:225 (gtest_discover_tests_impl)
I am using CMake as the build system. Compilation and running take place on a x86 Ubuntu 20.04.
Project structure
My directory structure is:
test_project/
CMakeLists.txt
src/
test_handcrafted/
CMakeLists.txt
test_handcrafted.cpp
test_gtest/
CMakeLists.txt
test_gtest.cpp
test_utils
CMakeLists.txt
test_utils.cpp
test_utils.hpp
lib/
libTarget.so
Target.hpp
libDependencyLevel1.so
DependencyLevel1.hpp
libDependencyLevel2.so
DependencyLevel2.hpp
build/
libTarget.so contains the functionalities to be verified. libDependencyLevel1.so contains utils for visualizing test outputs and it depends on libDependencyLevel2.so. test_utils contains all functions and classes that are actually called by the tests.
For instance, the command $ldd libDependencyLevel1.so returns:
linux-vdso.so.1 (0x00007fff17bb6000)
libDependencyLevel2.so => not found
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe5f3357000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe5f333c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe5f314a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe5f2ffb000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe5f358d000)
Build system
test_project/CMakeLists.txt
project(MY_TEST)
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(ExternalProject)
add_library(libTarget SHARED IMPORTED)
set_target_properties(libTarget PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libTarget.so"
)
add_library(libDependencyLevel2 SHARED IMPORTED)
set_target_properties(libDependencyLevel2 PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libDependencyLevel2.so"
)
add_library(libDependencyLevel1 SHARED IMPORTED)
set_target_properties(libDependencyLevel2 PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib/libDependencyLevel2.so"
)
add_dependencies(libDependencyLevel1 libDependencyLevel2)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
set(MY_LIBRARIES_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/test_utils)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/test_handcrafted)
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/test_gtest) # UNCOMMENTING THIS LINE CAUSES BUILD ERROR
src/test_utils/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(test_utils test_utils.cpp)
target_include_directories(test_utils PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
MY_LIBRARIES_HEADERS_DIR
)
target_link_libraries(test_utils PUBLIC libTarget libDependencyLevel1 libDependencyLevel2)
src/test_handcrafted/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(test_handcrafted test_handcrafted.cpp)
target_link_libraries(test_handcrafted PRIVATE libTarget test_utils)
src/test_gtest/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(test_gtest test_gtest.cpp)
target_link_libraries(test_gtest PRIVATE libTarget test_utils GTest::gtest_main)
include(GoogleTest)
gtest_discover_tests(test_gtest)
Finally, when building test_handcrafted.cpp we can also check its dependencies ldd test_handcrafted:
linux-vdso.so.1 (0x00007ffdaa561000)
libTarget.so => <path to repo dir>/lib/libTarget.so (0x00007ff7ab7ab000)
../lib/libDependencyLevel1.so (0x00007ff7ab76d000)
../lib/libDependencyLevel2.so (0x00007ff7ab612000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff7ab3e5000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff7ab294000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff7ab279000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff7ab087000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff7ab064000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff7ab05e000)
./libDependencyLevel2.so => not found
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff7ab040000)
libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007ff7aafbb000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff7ac01b000)
Unsuccessful solution attempts
Here is a list of things I have tried without success to solve the issue:
target_link_libraries on test_project/CMakeLists.txt
target_link_libraries(libDependencyLevel1 PUBLIC libDependencyLevel2) # INTERFACE and PRIVATE specifiers were also evaluated
link_directories on test_project/CMakeLists.txt
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
Reasoning and questions
According to the error message shown in the beginning of this post, the build system is not finding the shared libraries needed when GTest is used. But why is this happening? And why not using GTest solves the linking error, even if the IMPORTED SHARED libraries are imported in the same way for building both executables?
Finally, what can I do to solve the building issue when using GTest?

C++ How to link mongoc and mongocxx static library using CMakeList.txt

I follow the official tutorial for the installation : https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
I've enabled the flag --enable-static=yes with the ./configure before doing make && sudo make install and I got the libmongoc-1.0.a and the libbson-1.0.a which are static. I have given
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/your/cxxdriver/prefix
-DLIBMONGOC_DIR=/your/cdriver/prefix
-DLIBBSON_DIR=/your/cdriver/prefix ..
Then make && sudo make install is also done. So this far, everything it's alright.
when I check libraries which are linked to my final executable file are
ldd ./prabhandhak
linux-vdso.so.1 => (0x00007fff6d1f0000)
libbsoncxx.so._noabi => /usr/local/lib/libbsoncxx.so._noabi (0x00007f021cffb000)
libmongocxx.so._noabi => /usr/local/lib/libmongocxx.so._noabi (0x00007f021cda4000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f021ca06000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f021c6fd000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f021c4e6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f021c11c000)
libbson-1.0.so.0 => /usr/local/lib/libbson-1.0.so.0 (0x00007f021bee5000)
libmongoc-1.0.so.0 => /usr/local/lib/libmongoc-1.0.so.0 (0x00007f021bc6e000)
/lib64/ld-linux-x86-64.so.2 (0x000055ef6575a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f021ba51000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f021b848000)
libsnappy.so.0 => /usr/local/lib/libsnappy.so.0 (0x00007f021b631000)
Here i want to link mongo static libraries
this is my cmakelist.txt
cmake_minimum_required (VERSION 3.5)
# -------------------------------------------------------------------------------------
## Checking if an env variable for "3rd party includes" is set.
## If not, we throw an error and exit.
#Message("Checking for environment variable" "IAM_EXT_INCLUDES")
#if (DEFINED ENV{IAM_EXT_INCLUDES})
# Message ("found:" $ENV{IAM_EXT_INCLUDES})
#else()
# Message(FATAL_ERROR "I need the environment variable IAM_EXT_INCLUDES to continue.")
#endif()
# -------------------------------------------------------------------------------------
project(mango VERSION 0.1.0)
# search for CPP_HOME. If found use this as the install_root dir.
# else, use /usr/local
message (STATUS "Searching for environment var CPP_HOME ...")
if (DEFINED ENV{CPP_HOME})
message (STATUS "Found CPP_HOME: " $ENV{CPP_HOME})
set (CPP_HOME $ENV{CPP_HOME})
else()
message (STATUS "Could not find. Treating /usr/local as CPP_HOME...")
set (CPP_HOME /usr/local)
endif()
set(Boost_USE_STATIC_LIBS ON)
set(BOOST_LIBRARYDIR /usr/lib/x86_64-linux-gnu/)
# link_directories(/usr/lib/x86_64-linux-gnu/)
find_package(Boost REQUIRED COMPONENTS system date_time)
set(Boost_USE_STATIC_LIBS ON)
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
include_directories(${dbconn_SOURCE_DIR}/Implementation/mongo)
include_directories(${BOOST_INCLUDE_DIRS})
set (CMAKE_CXX_STANDARD 11)
if(libmongocxx_FOUND)
message("include path:" ${LIBMONGOCXX_INCLUDE_DIRS})
endif()
add_library(mongodbapi mongo_db_api.cpp)
# include third party lib headers (such as plog)
include_directories(/Volumes/second/nvi/github/externals/)
include_directories(../../../Interface/)
include_directories(./include/ext/)
include_directories(../../../../../utils/)
include_directories(${CPP_HOME}/externals/plog/include)
include_directories(${include_directories} ${LIBMONGOCXX_INCLUDE_DIRS})
include_directories(${include_directories} ${LIBBSONCXX_INCLUDE_DIRS})
target_link_libraries(mongodbapi ${LIBMONGOCXX_LIBRARIES})
target_link_libraries(mongodbapi ${LIBMONGOCXX_LIBRARIES})
target_link_libraries(mongodbapi ${Boost_LIBRARIES})
set (inst_dir_prefix mango-v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
install (TARGETS mongodbapi DESTINATION ${inst_dir_prefix}/lib)
FILE(GLOB inc_files "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
install (FILES ${inc_files} DESTINATION ${inst_dir_prefix}/include)
FILE(GLOB utils_includes "../../../../../utils/*.hpp")
#install (FILES ${inc_files} DESTINATION ${inst_dir_prefix}/include)
INSTALL(FILES ${utils_includes} DESTINATION "${CPP_HOME}/utils")
Please Help me to link static libraries to cmakefile.txt
Looks like there's relevant option in mongocxx's CMakeLists.txt. So
--- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
+++ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=False -DCMAKE_INSTALL_PREFIX=/usr/local ..
(this is from Step 4 of your tutorial)

CMAKE Linking dynamic library to module, but not showing as link dependency

Point me in the right direction if this has been asked before. I have lib1 and mod2, which must be linked together. This project is spread to a couple of folders and a couple of CMakeLists.txt files. The cmake commands that I am using are as such:
cmake file 1 (base dir):
# Set C/C++ compile and linking flags
set(GCC_COVERAGE_COMPILE_FLAGS "-fpic -Wno-as-needed")
set(GXX_COVERAGE_COMPILE_FLAGS "-std=c++11")
set(GXX_COVERAGE_LINK_FLAGS "-Wl,--no-undefined -Wno-as-needed")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${GXX_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER__FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
cmake file 2 (lib1 dir):
pybind11_add_module(elka_comm__common
SHARED
pyelka_common.cpp
elka.cpp
elka_comm.cpp
)
set_target_properties(elka_comm__common PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${ELKA_BINARY_DIR}/python
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${GXX_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER__FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
add_dependencies(elka_comm__common msg_gen)
cmake file 3 (mod2 dir):
#FIXME ldd not showing elka_comm__common as a link dependency
# -> CommPort undefined symbol upon module import
target_link_libraries(
elka_comm__gnd_station
PUBLIC
elka_comm__common
)
set_target_properties(elka_comm__gnd_station PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${ELKA_BINARY_DIR}/python
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${GXX_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER__FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
add_dependencies(elka_comm__gnd_station
elka_comm__common
msg_gen
)
A few of my steps are redundant as sanity checks (e.g. setting flags w/CMAKE variables).
The following is the partial output of ldd -r <path-to-mod2.so>/mod2.so:
linux-vdso.so.1 => (0x00007fff777fe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fadfe690000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fadfe479000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fadfe0b0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fadfddaa000)
/lib64/ld-linux-x86-64.so.2 (0x000055f1e6b2c000)
undefined symbol: _ZTIN4elka8CommPortE (build_elka_data_collection/python/elka_comm__gnd_station.so)
lib1 is called elka_comm__common.so, and so it should show up as a library dependency in ldd, right?
Partial output of cmake/make commands:
[100%] Linking CXX shared module ../../../python/elka_comm__gnd_station.so
cd /home/Programs/elka/elka_data_collection/build_elka_data_collection/src/elka_comm/gnd_station && /opt/cmake-3.4.3-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/elka_comm__gnd_station.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -fpic -Wno-as-needed -std=c++11 -fpic -Wno-as-needed -std=c++11 -g -shared -o ../../../python/elka_comm__gnd_station.so CMakeFiles/elka_comm__gnd_station.dir/pyelka_gnd_station.cpp.o CMakeFiles/elka_comm__gnd_station.dir/elka_devices.cpp.o `CMakeFiles/elka_comm__gnd_station.dir/inet_comm.cpp.o -L/home/Programs/elka/elka_data_collection/build_elka_data_collection/src/elka_comm/common -L/home/Programs/elka/elka_data_collection/build_elka_data_collection/src/elka_comm/gnd_station -L/home/Programs/elka/elka_data_collection/build_elka_data_collection/python -L/home/Programs/elka/elka_data_collection/python ../../../python/elka_comm__common.so -Wl,-rpath,/home/Programs/elka/elka_data_collection/build_elka_data_collection/src/elka_comm/common:/home/Programs/elka/elka_data_collection/build_elka_data_collection/src/elka_comm/gnd_station:/home/Programs/elka/elka_data_collection/build_elka_data_collection/python:/home/Programs/elka/elka_data_collection/python`
From this, it seems to me that linking is done correctly. My best intuition is that the ordering in the cmake generated link command is incorrect, but I can't justify this other than knowing that link commands are particular about ordering.
Solved by adding -Wl,--no-as-needed to CMAKE_CXX_FLAGS. Be mindful that adding to CMAKE_SHARED_LINKER_FLAGS|CMAKE_MODULE_LINKER_FLAGS doesn't work, and neither does adding -Wno-as-needed to CMAKE_CXX_FLAGS.
Other issues persist, though. If anyone is experienced w/binding c++ code to python pm me.

CMAKE, SDL2 and OPENGL: Program binary is too big

I use CMAKE to link a program to SDL2, OpenGL and I compile tinyxml2 as a shared library. The resulting program binary is 1.4 mb but there's barely 1k lines of code in the program. I suspect some library is statically linked. I'd prefer they are linked as shared libraries. I tried with debug symbols on and off with:
cmake -DCMAKE_BUILD_TYPE=Debug .
and off:
cmake .
and resulting binaries are still 1.4 mb each, which is weird because debug should be bigger. Here is my CMakeLists.txt:
project(ProjectName)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake-find-scripts")
aux_source_directory(. SRC_ROOT)
aux_source_directory(./extlib SRC_EXTLIB)
aux_source_directory(./engine SRC_ENGINE)
aux_source_directory(./utils SRC_UTILS)
include_directories(./extlib)
include_directories(./engine)
include_directories(./utils)
include_directories(${SDL2_INCLUDE_DIR})
include_directories(${OPENGL_INCLUDE_DIRS})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
set(LONE_HEADERS ./engine/stc_config.h)
add_executable(${PROJECT_NAME} ${SRC_ROOT} ${SRC_ENGINE} ${SRC_UTILS} ${LONE_HEADERS})
find_package(SDL2 REQUIRED)
find_package(SDL2IMAGE REQUIRED)
find_package(OpenGL REQUIRED)
add_library(tinyxml2 SHARED ./extlib/tinyxml2.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${SDL2IMAGE_LIBRARIES} tinyxml2)
Edit: I've checked which library files the binary is linked with using ldd command and the output confirms they are all shared libraries:
linux-vdso.so.1 (0x00007fff9dbf0000)
libSDL2-2.0.so.0 => /usr/lib/libSDL2-2.0.so.0 (0x00007f3accff7000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f3accdda000)
libGLU.so.1 => /usr/lib/libGLU.so.1 (0x00007f3accb59000)
libGL.so.1 => /usr/lib/libGL.so.1 (0x00007f3acc7fb000)
libSDL2_image-2.0.so.0 => /usr/lib/libSDL2_image-2.0.so.0 (0x00007f3acc5d5000)
libtinyxml2.so => /home/hacow/OGLTEST/libtinyxml2.so (0x00007f3acc3bd000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f3acc0ae000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f3acbda9000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f3acbb93000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f3acb7f0000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f3acb5ec000)
librt.so.1 => /usr/lib/librt.so.1 (0x00007f3acb3e4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3acd2fa000)
libnvidia-tls.so.349.16 => /usr/lib/libnvidia-tls.so.349.16 (0x00007f3acb1e1000)
libnvidia-glcore.so.349.16 => /usr/lib/libnvidia-glcore.so.349.16 (0x00007f3ac8472000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f3ac8130000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f3ac7f1e000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f3ac7cfc000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f3ac7af8000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f3ac78f2000)
Building with cmake . uses the same CMAKE_BUILD_TYPE as the most recent build in that directory. Use cmake -DCMAKE_BUILD_TYPE=Release . to build in release mode. If you built debug first then release, using the procedure you described, it would just rebuild your debug binary.

CMAKE building static executable instead of using dynamic library

My cmake file is
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 the two files: a .so file and an executable and it works perfectly. The problem is even after removing the .so file, the executable is working normally which means that the executable is statically linked.
Why this is happening and why cmake is not dynamically using the .so file?
Update
The dependencies by running ldd confirms this. Output of ldd 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)