I'm trying to include shared library in my main using CMake.
I used this example Trying to build shared library in CLion/CMake and C++ Link two Shared Library to main.cpp but its not working. I am getting undefined reference to all the function call.
My directory tree is like that:
**folder**
| **project folder**
| |
| |_main.cpp
|_
| |_CMakeLists.txt
| |
| **lib**
|_**lib1**
|_CMakeLists.txt
|_liblib1.so
|_**src**
|_lib1.cpp
|_**include**
|_lib1.h
This is my CMakeLists.txt
of the project:
cmake_minimum_required(VERSION 3.14)
project(DAL_project)
set(CMAKE_CXX_STANDARD 17)
set(GCC_COVERAGE_COMPILE_FLAGS "-lpq")
set(GCC_COVERAGE_LINK_FLAGS "-lpq")
include_directories(/usr/include)
include_directories(-I/home/yaodav/Desktop/git_repo/lib/internal/conn2/include/)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
SET(SOURCE_FILES main.cpp SymbolInfo.cpp SymbolInfo.h SymbolDAL.cpp SymbolDAL.h AppSettingDAL.cpp AppSettingDAL.h AppSetting.cpp AppSetting.h)
add_executable(DAL_project ${SOURCE_FILES} )
I am trying to add those lines to the CMakeLists.txt
but it is not working:
target_link_libraries(DAL_project conlibcon.so)
add_library(libconnlib SHARED IMPORTED -L../lib/internal/conn1)