Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML+CLION +CMAKE (Windows10) configuration  (Read 15631 times)

0 Members and 2 Guests are viewing this topic.

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
SFML+CLION +CMAKE (Windows10) configuration
« on: August 13, 2017, 06:04:28 pm »
Hello everybody,
in the last two days i tried to set the sfml with Cmake in CLion, asking google or looking for answers in the forum when problems occurred.
Now i have to ask u direcly for help, because i don't understand other topics or they don't fit (i guess) my problem.
I had to set the path to FindSFML.cmake (understood),
to let him find the sfml  components (the last error message told:  Could NOT find SFML (missing: SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY   SFML_GRAPHICS_LIBRARY SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY) ) and after some attempts the message changed and i thought I found the solution of that problem)

This is what i wrote until now following tutorials and wiki
cmake_minimum_required(VERSION 3.7)
project(SFMLprova1)

set(CMAKE_CXX_STANDARD 11)


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

set(CMAKE_MODULE_PATH "C:/Code/Librerie/SFML-2.4.2/cmake/Modules")

find_package(SFML 2 REQUIRED network audio graphics window system)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()

this is what i see now in the debug window:
"C:\Users\Ludovico\AppData\Roaming\JetBrains\CLion 2017.1.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Ludovico\CLionProjects\SFMLprova1
-- Found SFML 2.4.2 in C:/Code/Librerie/SFML-2.4.2/include
CMake Error at CMakeLists.txt:15 (target_link_libraries):
  Cannot specify link libraries for target "debug" which is not built by this
  project.


-- Configuring incomplete, errors occurred!
See also "C:/Users/Ludovico/CLionProjects/SFMLprova1/cmake-build-debug/CMakeFiles/CMakeOutput.log".

arnavb

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #1 on: August 13, 2017, 06:57:33 pm »
Correct me if I am wrong, but you do not need to link the dependencies unless you are linking SFML statically, which you are not.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #2 on: August 13, 2017, 08:44:47 pm »
If SFML isn't installed in a common library search path, you need to set SFML_ROOT to tell CMake where to look for the libraries.

When you use the FindSFML.cmake script, you can always link against SFML_DEPENDENCIES, as the script will just leave it empty when linking SFML dynamically.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #3 on: August 14, 2017, 12:55:24 am »
So should i set the sfml root as

set(SFML_ROOT "C:Code/Librerie/SFML-2.4.2") #this is the directory which contains lib and bin

then... should i edit something inside the FindSFML.cmake or edit the value of SFML_DEPENDENCIES? It's not rly clear for me sorry, i'm still a newbie

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #4 on: August 14, 2017, 06:59:59 am »
So should i set the sfml root as

set(SFML_ROOT "C:Code/Librerie/SFML-2.4.2") #this is the directory which contains lib and bin
Ideally, since the SFML root and the module path can change, you'd not set them in your CMake file, but specify them in the CMake cache.
For being lazy and only aiming the CMake file for your own setup, you can however just add them to your CMake file as you suggested.

then... should i edit something inside the FindSFML.cmake or edit the value of SFML_DEPENDENCIES? It's not rly clear for me sorry, i'm still a newbie
As I said, you have to do nothing, everything is taken care of.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

seyuup

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #5 on: August 16, 2017, 09:04:56 pm »
I have Windows 8.1 and am currently using CLion with SFML. So, I'll see if I can help you with you problem.

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #6 on: August 18, 2017, 11:18:14 am »
ok, I added the edit of SFML_ROOT and then I deleted the target link libraries line and, looking in the main file, it seems to find the library, but when i try to compile, i recieve a lot of error message of that kind

CMakeFiles\SFMLprova1.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:5: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:5: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:6: undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:7: undefined reference to `_imp___ZN2sf5Color5GreenE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:7: undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:9: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:11: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:13: undefined reference to `_imp___ZN2sf6Window5closeEv'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:16: undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:16: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:17: undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:17: undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:18: undefined reference to `_imp___ZN2sf6Window7displayEv'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:/Users/Ludovico/CLionProjects/SFMLprova1/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
CMakeFiles\SFMLprova1.dir/objects.a(main.cpp.obj): In function `ZN2sf11CircleShapeD1Ev':
C:/Code/Librerie/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
C:/Code/Librerie/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
C:/Code/Librerie/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [SFMLprova1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/SFMLprova1.dir/all] Error 2
CMakeFiles\SFMLprova1.dir\build.make:96: recipe for target 'SFMLprova1.exe' failed
mingw32-make.exe[1]: *** [CMakeFiles/SFMLprova1.dir/rule] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/SFMLprova1.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/SFMLprova1.dir/rule' failed
Makefile:117: recipe for target 'SFMLprova1' failed
mingw32-make.exe: *** [SFMLprova1] Error 2

This is the Cmake:

cmake_minimum_required(VERSION 3.7)
project(SFMLprova1)

set(CMAKE_CXX_STANDARD 11)


set(SOURCE_FILES main.cpp)
add_executable(SFMLprova1 ${SOURCE_FILES})
set(SFML_ROOT "C:Code/Librerie/SFML-2.4.2")

set(CMAKE_MODULE_PATH "C:/Code/Librerie/SFML-2.4.2/cmake/Modules")


find_package(SFML 2 REQUIRED network audio graphics window system)
include_directories(${SFML_INCLUDE_DIR})


 

and this is the main:

#include <iostream>
#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #7 on: August 18, 2017, 11:46:31 am »
then I deleted the target link libraries line
Why? Now you're not linking the libraries at all, thus the undefined references.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #8 on: August 18, 2017, 12:06:27 pm »
sorry, i did not understand what i have to do, but even if i edit the sfml root, i still have this error:

Make Error at CMakeLists.txt:16 (target_link_libraries):
  Cannot specify link libraries for target "debug" which is not built by this
  project.

there is something else wrong i have to change, or i missed something?

cmake_minimum_required(VERSION 3.7)
project(SFMLprova1)

set(CMAKE_CXX_STANDARD 11)


set(SOURCE_FILES main.cpp)
add_executable(SFMLprova1 ${SOURCE_FILES})
set(SFML_ROOT "C:Code/Librerie/SFML-2.4.2")

set(CMAKE_MODULE_PATH "C:/Code/Librerie/SFML-2.4.2/cmake/Modules")


find_package(SFML 2 REQUIRED network audio graphics window system)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #9 on: August 18, 2017, 12:46:21 pm »
"C:Code/Librerie/SFML-2.4.2" is an invalid path, not sure if that is the issue though
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #10 on: August 18, 2017, 04:29:01 pm »
why is it invalid? what is an example of valid path?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #11 on: August 18, 2017, 05:08:46 pm »
C:Code misses a / between C: and Code
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #12 on: August 18, 2017, 07:44:49 pm »
oh...right...
I corrected it, but it didn't solve the problem

DiverDante

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #13 on: August 22, 2017, 11:23:39 am »
hi guys
i trying to solve this problem but i got nothing

i have the sfml in this path
C:\Code\Librerie\SFML-2.4.2

i have downloaded the 64bit sfml, mingw.

If i don't set the SFML ROOT i have the "undefined reference" problem
If i do, i have the same error until i edit the target link libraries
then i have this
CMake Error at CMakeLists.txt:17 (target_link_libraries):
  Cannot specify link libraries for target "debug" which is not built by this
  project.

cmake_minimum_required(VERSION 3.7)
project(SFMLprova1)

set(CMAKE_CXX_STANDARD 11)


set(SFML_ROOT "C:/Code/Librerie/SFML-2.4.2")

set(CMAKE_MODULE_PATH "C:/Code/Librerie/SFML-2.4.2/cmake/Modules" ${CMAKE_MODULE_PATH})


find_package(SFML COMPONENTS network audio graphics window system REQUIRED)
include_directories(${SFML_INCLUDE_DIR})

set(SOURCE_FILES main.cpp)
add_executable(SFMLprova1 ${SOURCE_FILES})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

could be that i downloaded the wrong lib? how can i check it?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML+CLION +CMAKE (Windows10) configuration
« Reply #14 on: August 22, 2017, 01:21:41 pm »
Don't use ${EXECUTABLE_NAME} as it doesn't just contain the project name.
Instead you can just use SFMLprova1 or ${CMAKE_PROJECT_NAME}.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/