简体   繁体   中英

Why can't CMAKE find my SFML libraries in CLion?

I am trying to run SFML on CLion with CMAKE , and I keep getting the following error:

Error:Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)

This is my CMakeLists.txt file:

cmake_minimum_required(VERSION 2.6)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()

project(Polymorphism)

set(SOURCE_FILES main.cpp)
add_executable(Polymorphism ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Modules" ${CMAKE_MODULE_PATH})
find_package(SFML REQUIRED system window graphics network audio)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${main.cpp} ${SFML_LIBRARIES})
endif()

Any help?

Impossible to tell, since we don't know your environment.

However, this should usually help:

Add a new CMake variable SFML_ROOT and let it point to the directory where SFML is installed.

Just add the variable to your CMakeCache.txt or pass it the first time you run CMake, eg:

cmake -DSFML_ROOT=/code/SFML path/to/source

Also you've got a problem further down below:

target_link_libraries(${main.cpp} ${SFML_LIBRARIES})

The first parameter is supposed to be the target, in your case Polymorphism . Also you should add SFML_DEPENDENCIES just in case someone tries to link SFML statically. In the end this line should look like this:

target_link_libraries(Polymorphism ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM