CMake undefined reference issue

Viewed 43

I am trying to make a simple OpenGL program in C++. In my root program I have this CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(Playground VERSION 0.1.0)
add_subdirectory(glfw/)
add_subdirectory(glad/)
add_subdirectory(glm/)
add_subdirectory(imgui/)
add_executable(${PROJECT_NAME} main.cpp )
target_link_libraries(${PROJECT_NAME} PUBLIC glfw)
target_link_libraries(${PROJECT_NAME} PUBLIC glad)
target_link_libraries(${PROJECT_NAME} PUBLIC glm)
target_link_libraries(${PROJECT_NAME} PUBLIC imgui)
target_include_directories(${PROJECT_NAME} PUBLIC glfw)
target_include_directories(${PROJECT_NAME} PUBLIC glad)
target_include_directories(${PROJECT_NAME} PUBLIC glm)
target_include_directories(${PROJECT_NAME} PUBLIC imgui)

Now I am having issues including the imgui files. In the imgui folder I have another CMakeLists.txt:

add_library(imgui
    imgui.h
    imconfig.h
    imgui_internal.h 
    imgui_impl_glfw.h
    imgui_impl_opengl3_loader.h
    imgui_impl_opengl3.h
    imgui_impl_glfw.cpp
    imgui_impl_opengl3.cpp
    imgui.cpp
    imgui_tables.cpp
    imgui_widgets.cpp
)     
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(imgui PUBLIC glfw)

Now, when I make the file I get the following error message:

 /usr/bin/ld: CMakeFiles/Playground.dir/main.cpp.o: in function `main':
 /home/lzer/Code/C_C++/Learn OpenGL/Playground_V1.0/main.cpp:63:
 undefined reference to `ImGui::StyleColorsDark(ImGuiStyle*)' collect2:
 error: ld returned 1 exit status make[2]: ***
 [CMakeFiles/Playground.dir/build.make:103: Playground] Error 1
 make[1]: *** [CMakeFiles/Makefile2:945: CMakeFiles/Playground.dir/all]
 Error 2 make: *** [Makefile:166: all] Error 2

How can I fix this? In Visual studio code, intellisense can tell what functions I would like to use but it seems as if when compiling, maybe the files haven't been built yet? I am not very familiar with CMake.

What I Want it to do: I would like to compile all cpp files from another CMakeList.

0 Answers
Related