Search code examples
c++cmakeclionglfw

CMAKE GLFW linking problems


I wanto add glfw dependency by cmake in CLion but i get weird error, this is the CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(hello_gl)

set(CMAKE_CXX_STANDARD 14)

find_package(glfw3 3.3 REQUIRED)

target_link_libraries(hello_gl glfw)


add_executable(hello_gl main.cpp)
CMake Error at CMakeLists.txt:8 (target_link_libraries):
Cannot specify link libraries for target "hello_gl" which is not built by
this project.

This is the error I get? How it comes that cmake cannot find my app?


Solution

  • It worked when I tried to link glfw lib after adding the executable

    cmake_minimum_required(VERSION 3.17)
    project(hello_gl)
    
    set(CMAKE_CXX_STANDARD 14)
    
    add_executable(hello_gl main.cpp)
    
    find_package(glfw3 3.3 REQUIRED)
    
    target_link_libraries(hello_gl glfw)
    

    Here is the right CMakeLists.txt