Here i am creating a project . i am using cmake . i am not able to link cmake created shared library with my main application ??? My CMakeLists.txt file are as follows :
//tree -stucture of my project
├── CMakeLists.txt
├── include
│ ├── Account.h
│ ├── bankingSystem.h
│ ├── bankStruct.h
│ └── stdheader.h
├── main.cpp
└── src
├── Account.cpp
├── bankingSystem.cpp
└── main.cpp
//CMakeLists.txt
cmake_minimum_required(VERSION 3.17.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -DPC_BUILD")
include_directories(
./include
)
link_directories(
/usr/local/lib)
#create a shared library to be linked with test application
add_library(
BANK SHARED
src/bankingSystem.cpp
src/Account.cpp
)
add_executable(
main main.cpp
)
message("BANK")
But i am getting Undefined Reference :
[ 60%] Built target BANK
[ 80%] Linking CXX executable main
CMakeFiles/main.dir/main.cpp.o: In function `main':
/home/pankaj/BANK/main.cpp:8: undefined reference to `BankingSystem::BankingSystem()'
/home/pankaj/BANK/main.cpp:19: undefined reference to `BankingSystem::Create_new_Account()'
...
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:103: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:124: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:103: recipe for target 'all' failed
make: *** [all] Error 2