I have started to learn CMake framework to build cmake recently and started a dummy project to understand how it works.
My project structure is as shown in the image. The CMakeLists.txt at the root level (myapp->CMakeLists.txt) is shown below:
cmake_minimum_required(VERSION 3.20)
project(dummyCMake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "-o0")
add_subdirectory(libs)
include_directories(includes)
file(GLOB SOURCES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
get_filename_component(parent_dir ../ ABSOLUTE)
target_link_libraries(${PROJECT_NAME} PUBLIC uiolibs)
target_link_libraries(${PROJECT_NAME} PUBLIC mathlibs)
target_include_directories(${PROJECT_NAME} PUBLIC
"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/libs/uiolibs/includes"
"${PROJECT_SOURCE_DIR}/libs/mathlibs/includes"
)
sub directories CMakeLists.txt is as follows:
file(GLOB sources "src/*cpp")
message(${sources}) #for debugging
add_library(uiolibs STATIC ${sources})
Getting linking error undefined reference to `mathlibs::AddInit(int, int)
undefined reference to `userinput::getInit()
Any suggestion to fix this issue (or in general on cmake framework) will be appreciated.
The project code folder: github link