SFML Clion error CMake Error at CMakeLists.txt:8 (target_link_directories): target_link_directories called with invalid arguments

Viewed 199

I installed SFML and modified the cmakeList to be able to run an SFML project. I used Msys2 to install mingw and sfml 64bit version. My cmake looks like this:

cmake_minimum_required(VERSION 3.17)
project(PHONEBOOK)

set(CMAKE_CXX_STANDARD 11)
find_package(SFML 2.5 COMPONENTS system window graphics)

add_executable(PHONEBOOK main.cpp contact.cpp contact.h phonebook.cpp phonebook.h)
target_link_directories(PHONEBOOK sfml-system sfml-window sfml-graphics)

When I run the project I get this error: CMake Error at CMakeLists.txt:8 (target_link_directories): target_link_directories called with invalid arguments

mingw32-make: *** [Makefile:255: cmake_check_build_system] Error 1

2 Answers

You need to call target_link_libraries instead of target_link_directories. As you don't have multiple installations of the sfml library, there is no need to call target_link_directories

target_link_directories is for setting the search library path.

Specifies the paths in which the linker should search for libraries when linking a given target. Each item can be an absolute or relative path, with the latter being interpreted as relative to the current source directory. These items will be added to the link command.

It's because you're missing one of the mandatory keywords: <INTERFACE|PUBLIC|PRIVATE>. Eg: target_link_directories(PHONEBOOK PRIVATE sfml-system sfml-window sfml-graphics)

Related