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

Author Topic: setting SFML on Clion  (Read 19184 times)

0 Members and 1 Guest are viewing this topic.

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
setting SFML on Clion
« on: November 17, 2019, 06:15:33 pm »
I have read many other topics about this, but they didn't solve my problem. I have followed this: https://github.com/perebalsach/sfml_clion_template. What should i do to make this program work? Managing the cMakeFiles is not my cup of tea Please don't answer by only linking an other answer. Sorry for my english
Code: [Select]
//main.cpp
#include <SFML/Graphics.hpp>

int main() {

    sf::RenderWindow window(sf::VideoMode(640,480,32),"Hello SFML");

    sf::Font font;
    font.loadFromFile("resources/fonts/Pacifico.ttf");

    sf::Text text("Hello World",font,11);
    text.setCharacterSize(32);
    text.setPosition(window.getSize().x/2 - text.getGlobalBounds().width/2,
                     window.getSize().y/2 - text.getGlobalBounds().height/2);


    while(window.isOpen()){

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

            window.clear(sf::Color::Black);
            window.draw(text);
            window.display();
        }
    }
    return 0;
}
Code: [Select]
//CMakeList.txt
cmake_minimum_required(VERSION 3.10)
# set the projectX name to the name of your project
project(sfml_clion_template-master)

set(CMAKE_CXX_STANDARD 11)
# set(SOURCE_FILES main.cpp)

add_executable(sfml_clion_template-master main.cpp)
#add_executable(Game ${SOURCE_FILES})

set(SFML_ROOT "D:/Libraries/SFML")
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
endif()









"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\cristina\Desktop\sfml_clion_template-master\sfml_clion_template-master
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:14 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable SFML_ROOT is set to:

    D:/Libraries/SFML

  For compatibility, CMake is ignoring the variable.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found SFML 2.5.1 in D:/Libraries/SFML/include
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/cmake-build-debug

[Finished]




====================[ Build | sfml_clion_template-master | Debug ]==============
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\cristina\Desktop\sfml_clion_template-master\sfml_clion_template-master\cmake-build-debug --target sfml_clion_template-master -- -j 2
Scanning dependencies of target sfml_clion_template-master
[ 50%] Building CXX object CMakeFiles/sfml_clion_template-master.dir/main.cpp.obj
[100%] Linking CXX executable sfml_clion_template-master.exe
CMakeFiles\sfml_clion_template-master.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:6: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:6: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:6: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:8: undefined reference to `_imp___ZN2sf4FontC1Ev'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:9: undefined reference to `_imp___ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:11: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:11: undefined reference to `_imp___ZN2sf4TextC1ERKNS_6StringERKNS_4FontEj'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:12: undefined reference to `_imp___ZN2sf4Text16setCharacterSizeEj'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:14: undefined reference to `_imp___ZNK2sf12RenderWindow7getSizeEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:14: undefined reference to `_imp___ZNK2sf4Text15getGlobalBoundsEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:13: undefined reference to `_imp___ZNK2sf12RenderWindow7getSizeEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:13: undefined reference to `_imp___ZNK2sf4Text15getGlobalBoundsEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:14: undefined reference to `_imp___ZN2sf13Transformable11setPositionEff'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:17: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:20: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:22: undefined reference to `_imp___ZN2sf6Window5closeEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:25: undefined reference to `_imp___ZN2sf5Color5BlackE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:25: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:26: undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:26: undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:27: undefined reference to `_imp___ZN2sf6Window7displayEv'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:8: undefined reference to `_imp___ZN2sf4FontD1Ev'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:6: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:8: undefined reference to `_imp___ZN2sf4FontD1Ev'
C:/Users/cristina/Desktop/sfml_clion_template-master/sfml_clion_template-master/main.cpp:6: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
CMakeFiles\sfml_clion_template-master.dir/objects.a(main.cpp.obj): In function `ZN2sf8DrawableD2Ev':
D:/Libraries/SFML/include/SFML/Graphics/Drawable.hpp:52: undefined reference to `_imp___ZTVN2sf8DrawableE'
CMakeFiles\sfml_clion_template-master.dir/objects.a(main.cpp.obj): In function `ZN2sf11VertexArrayD1Ev':
D:/Libraries/SFML/include/SFML/Graphics/VertexArray.hpp:45: undefined reference to `_imp___ZTVN2sf11VertexArrayE'
CMakeFiles\sfml_clion_template-master.dir/objects.a(main.cpp.obj): In function `ZN2sf4TextD1Ev':
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `_imp___ZTVN2sf4TextE'
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `_imp___ZTVN2sf4TextE'
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `_imp___ZN2sf13TransformableD2Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [sfml_clion_template-master.exe] Error 1
CMakeFiles\sfml_clion_template-master.dir\build.make:90: recipe for target 'sfml_clion_template-master.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/sfml_clion_template-master.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/sfml_clion_template-master.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/sfml_clion_template-master.dir/rule] Error 2
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/sfml_clion_template-master.dir/rule' failed
mingw32-make.exe: *** [sfml_clion_template-master] Error 2
Makefile:117: recipe for target 'sfml_clion_template-master' failed
« Last Edit: November 22, 2019, 03:41:24 pm by vrige »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #1 on: November 17, 2019, 07:46:57 pm »
Your order of SFML modules is wrong, should be listed as X depends on Y, thus X comes before Y.

Also this uses old CMake and won't necessarily work with SFML 2.5. See this thread: https://en.sfml-dev.org/forums/index.php?topic=24070.0

I recommend you spend some more time on learning CMake and understanding how the linker works.

(I removed your duplicate topic)
(Cross post: https://stackoverflow.com/questions/58902447/setting-sfml-on-clion)
« Last Edit: November 17, 2019, 08:02:45 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #2 on: November 18, 2019, 04:15:27 pm »
it still doesn't work. Can you help me a little bit more? I don't really know what to do.

Code: [Select]
//CMakeList.txt
cmake_minimum_required(VERSION 3.15)
project(prova1)

set(CMAKE_CXX_STANDARD 14)


## If you want to link SFML statically
set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
set(SFML_DIR "D:/Libraries/SFML/lib/cmake/SFML")

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(prova1 main.cpp)
target_link_libraries(prova1 sfml-graphics sfml-audio)


//main.cpp
#include <SFML/Graphics.hpp>


int main() {

    sf::RenderWindow window(sf::VideoMode(640,480,32),"Hello SFML");

    sf::Font font;
    font.loadFromFile("resources/fonts/Pacifico.ttf");

    sf::Text text("Hello World",font,11);
    text.setCharacterSize(32);
    text.setPosition(window.getSize().x/2 - text.getGlobalBounds().width/2,
                     window.getSize().y/2 - text.getGlobalBounds().height/2);


    while(window.isOpen()){

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

            window.clear(sf::Color::Black);
            window.draw(text);
            window.display();
        }
    }
    return 0;
}




//cMake
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\cristina\CLionProjects\prova1
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SFML 2.5.1 in D:/Libraries/SFML/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/cristina/CLionProjects/prova1/cmake-build-debug

[Finished]




====================[ Build | prova1 | Debug ]==================================
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\cristina\CLionProjects\prova1\cmake-build-debug --target prova1 -- -j 2
Scanning dependencies of target prova1
[ 50%] Building CXX object CMakeFiles/prova1.dir/main.cpp.obj
[100%] Linking CXX executable prova1.exe
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:8: undefined reference to `sf::Font::Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:9: undefined reference to `sf::Font::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::String::String(char const*, std::locale const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Text::Text(sf::String const&, sf::Font const&, unsigned int)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:12: undefined reference to `sf::Text::setCharacterSize(unsigned int)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:14: undefined reference to `sf::RenderWindow::getSize() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:14: undefined reference to `sf::Text::getGlobalBounds() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:13: undefined reference to `sf::RenderWindow::getSize() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:13: undefined reference to `sf::Text::getGlobalBounds() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:14: undefined reference to `sf::Transformable::setPosition(float, float)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:17: undefined reference to `sf::Window::isOpen() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:20: undefined reference to `sf::Window::pollEvent(sf::Event&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:22: undefined reference to `sf::Window::close()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:25: undefined reference to `sf::Color::Black'
C:/Users/cristina/CLionProjects/prova1/main.cpp:25: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:26: undefined reference to `sf::RenderStates::Default'
C:/Users/cristina/CLionProjects/prova1/main.cpp:26: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:27: undefined reference to `sf::Window::display()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:8: undefined reference to `sf::Font::~Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:8: undefined reference to `sf::Font::~Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `ZN2sf11VertexArrayD1Ev':
D:/Libraries/SFML/include/SFML/Graphics/VertexArray.hpp:45: undefined reference to `vtable for sf::VertexArray'
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `ZN2sf4TextD1Ev':
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `vtable for sf::Text'
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `vtable for sf::Text'
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `sf::Transformable::~Transformable()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [prova1.exe] Error 1
CMakeFiles\prova1.dir\build.make:96: recipe for target 'prova1.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/prova1.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/prova1.dir/rule] Error 2
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/prova1.dir/rule' failed
Makefile:117: recipe for target 'prova1' failed
mingw32-make.exe: *** [prova1] Error 2
« Last Edit: November 22, 2019, 03:42:00 pm by vrige »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #3 on: November 18, 2019, 04:49:02 pm »
Since you're using GCC 6.3.0 did you build SFML yourself?

See also the red box on the download page: https://www.sfml-dev.org/download/sfml/2.5.1/

Also please use [code=cpp][/code] tags when posting code or  [code][/code] for logs.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #4 on: November 19, 2019, 01:24:04 pm »
I have tried to download it, but it didn't solve my problem.
I really need SFML to do a project and probably i did some stupid errors, please help me to find them.
This is what i download: 
https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/7.3.0/threads-posix/dwarf/i686-7.3.0-release-posix-dwarf-rt_v5-rev0.7z/downloadMinGW Builds 7.3.0 (32-bit)

Code: [Select]
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\cristina\CLionProjects\prova1
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: D:/mingw32/mingw32/bin/gcc.exe
-- Check for working C compiler: D:/mingw32/mingw32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/mingw32/mingw32/bin/g++.exe
-- Check for working CXX compiler: D:/mingw32/mingw32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SFML 2.5.1 in D:/Libraries/SFML/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/cristina/CLionProjects/prova1/cmake-build-debug

[Finished]
Code: [Select]
====================[ Build | prova1 | Debug ]==================================
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\cristina\CLionProjects\prova1\cmake-build-debug --target prova1 -- -j 2
Scanning dependencies of target prova1
[ 50%] Building CXX object CMakeFiles/prova1.dir/main.cpp.obj
[100%] Linking CXX executable prova1.exe
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:8: undefined reference to `sf::Font::Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:9: undefined reference to `sf::Font::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::String::String(char const*, std::locale const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Text::Text(sf::String const&, sf::Font const&, unsigned int)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:12: undefined reference to `sf::Text::setCharacterSize(unsigned int)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:14: undefined reference to `sf::RenderWindow::getSize() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:14: undefined reference to `sf::Text::getGlobalBounds() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:13: undefined reference to `sf::RenderWindow::getSize() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:13: undefined reference to `sf::Text::getGlobalBounds() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:13: undefined reference to `sf::Transformable::setPosition(float, float)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:17: undefined reference to `sf::Window::isOpen() const'
C:/Users/cristina/CLionProjects/prova1/main.cpp:20: undefined reference to `sf::Window::pollEvent(sf::Event&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:22: undefined reference to `sf::Window::close()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:25: undefined reference to `sf::Color::Black'
C:/Users/cristina/CLionProjects/prova1/main.cpp:25: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:26: undefined reference to `sf::RenderStates::Default'
C:/Users/cristina/CLionProjects/prova1/main.cpp:26: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:27: undefined reference to `sf::Window::display()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:8: undefined reference to `sf::Font::~Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:8: undefined reference to `sf::Font::~Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:6: undefined reference to `sf::RenderWindow::~RenderWindow()'
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `ZN2sf11VertexArrayD1Ev':
D:/Libraries/SFML/include/SFML/Graphics/VertexArray.hpp:45: undefined reference to `vtable for sf::VertexArray'
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `ZN2sf4TextD1Ev':
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `vtable for sf::Text'
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `vtable for sf::Text'
D:/Libraries/SFML/include/SFML/Graphics/Text.hpp:48: undefined reference to `sf::Transformable::~Transformable()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\prova1.dir\build.make:97: prova1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/prova1.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: prova1] Error 2

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #5 on: November 21, 2019, 11:02:47 am »
can someone help me?
Is there a Clion+sfml tutorial?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #6 on: November 21, 2019, 12:36:48 pm »
Those are just normal linker errors and pretty unrelated to CLion.
Also kind of unrelated to SFML, understanding how the linker works and how to fix linker errors is a general C++ skill to learn.

Did you change your CMakeLists.txt?
It can't find the SFML symbols for some reason.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #7 on: November 21, 2019, 01:33:10 pm »
I changed it just a little bit:
Code: [Select]
cmake_minimum_required(VERSION 3.15)
project(prova1)

set(CMAKE_CXX_STANDARD 14)

## If you want to link SFML statically
set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
set(SFML_DIR "D:/Libraries/SFML/lib/cmake/SFML")

find_package(SFML 2.5 COMPONENTS graphics window system REQUIRED)
add_executable(prova1 main.cpp)
target_link_libraries(prova1 sfml-graphics sfml-window sfml-system)
I also tried to do what "exenda" did in this answer:
https://stackoverflow.com/questions/26602471/how-to-run-sfml-in-clion-error-undefined-reference-to
so i added D:\libraries\SFML\bin\ to my env variable Path, but it didn't work.
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #8 on: November 21, 2019, 04:39:12 pm »
It should link that way. Try to clear your CMake cache.

If it's only related to std::string it might be that you need to recompile SFML with the same C++ standard flag set.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #9 on: November 22, 2019, 10:48:47 am »
I tried to clear my cMake cache with "reset cMake and reload project", but it didn't work.
#include <SFML/Graphics.hpp>
#include <iostream>

int main() {
    std::cout<<"ciao"<<std::endl;

    sf::Font font;
    font.loadFromFile("resources/fonts/Pacifico.ttf");

    return 0;
}
Code: [Select]
====================[ Build | prova1 | Debug ]==================================
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\cristina\CLionProjects\prova1\cmake-build-debug --target prova1 -- -j 2
Scanning dependencies of target prova1
[ 50%] Building CXX object CMakeFiles/prova1.dir/main.cpp.obj
[100%] Linking CXX executable prova1.exe
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Font::Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:12: undefined reference to `sf::Font::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Font::~Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Font::~Font()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\prova1.dir\build.make:90: prova1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/prova1.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: prova1] Error 2

"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\cristina\CLionProjects\prova1
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: D:/mingw32/mingw32/bin/gcc.exe
-- Check for working C compiler: D:/mingw32/mingw32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/mingw32/mingw32/bin/g++.exe
-- Check for working CXX compiler: D:/mingw32/mingw32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SFML 2.5.1 in D:/Libraries/SFML/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/cristina/CLionProjects/prova1/cmake-build-debug

[Finished]
http://ppmlaboratorio.altervista.org/fotoClion/C1/Screenshot__2_.png

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #10 on: November 22, 2019, 01:27:50 pm »
Don't know why, but SFML is still not being linked.

Try a verbose build output (google how you can set it up for CMake).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #11 on: November 22, 2019, 03:40:05 pm »
I used this line: set(CMAKE_VERBOSE_MAKEFILE ON).
#include <SFML/Graphics.hpp>
#include <iostream>

int main() {
    std::cout<<"ciao"<<std::endl;

    sf::Font font;
    font.loadFromFile("resources/fonts/Pacifico.ttf");

    return 0;
}
Code: [Select]
cmake_minimum_required(VERSION 3.15)
project(prova1)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILE ON)

## If you want to link SFML statically
set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
set(SFML_DIR "D:/Libraries/SFML/lib/cmake/SFML")

find_package(SFML 2.5 COMPONENTS graphics window system REQUIRED)
add_executable(prova1 main.cpp)
target_link_libraries(prova1 sfml-graphics sfml-window sfml-system)




"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\cristina\CLionProjects\prova1
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: D:/mingw32/mingw32/bin/gcc.exe
-- Check for working C compiler: D:/mingw32/mingw32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/mingw32/mingw32/bin/g++.exe
-- Check for working CXX compiler: D:/mingw32/mingw32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SFML 2.5.1 in D:/Libraries/SFML/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/cristina/CLionProjects/prova1/cmake-build-debug

[Finished]




====================[ Build | prova1 | Debug ]==================================
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\cristina\CLionProjects\prova1\cmake-build-debug --target prova1 -- -j 2
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -SC:\Users\cristina\CLionProjects\prova1 -BC:\Users\cristina\CLionProjects\prova1\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
D:/mingw32/mingw32/bin/mingw32-make.exe -f CMakeFiles\Makefile2 prova1
mingw32-make.exe[1]: Entering directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -SC:\Users\cristina\CLionProjects\prova1 -BC:\Users\cristina\CLionProjects\prova1\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -E cmake_progress_start C:\Users\cristina\CLionProjects\prova1\cmake-build-debug\CMakeFiles 2
D:/mingw32/mingw32/bin/mingw32-make.exe -f CMakeFiles\Makefile2 CMakeFiles/prova1.dir/all
mingw32-make.exe[2]: Entering directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
D:/mingw32/mingw32/bin/mingw32-make.exe -f CMakeFiles\prova1.dir\build.make CMakeFiles/prova1.dir/depend
mingw32-make.exe[3]: Entering directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\cristina\CLionProjects\prova1 C:\Users\cristina\CLionProjects\prova1 C:\Users\cristina\CLionProjects\prova1\cmake-build-debug C:\Users\cristina\CLionProjects\prova1\cmake-build-debug C:\Users\cristina\CLionProjects\prova1\cmake-build-debug\CMakeFiles\prova1.dir\DependInfo.cmake --color=
Scanning dependencies of target prova1
mingw32-make.exe[3]: Leaving directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
D:/mingw32/mingw32/bin/mingw32-make.exe -f CMakeFiles\prova1.dir\build.make CMakeFiles/prova1.dir/build
mingw32-make.exe[3]: Entering directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
[ 50%] Building CXX object CMakeFiles/prova1.dir/main.cpp.obj
D:\mingw32\mingw32\bin\g++.exe  -DSFML_STATIC @CMakeFiles/prova1.dir/includes_CXX.rsp -g   -std=gnu++14 -o CMakeFiles\prova1.dir\main.cpp.obj -c C:\Users\cristina\CLionProjects\prova1\main.cpp
[100%] Linking CXX executable prova1.exe
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -E cmake_link_script CMakeFiles\prova1.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -E remove -f CMakeFiles\prova1.dir/objects.a
D:\mingw32\mingw32\bin\ar.exe cr CMakeFiles\prova1.dir/objects.a @CMakeFiles\prova1.dir\objects1.rsp
D:\mingw32\mingw32\bin\g++.exe -g   -Wl,--whole-archive CMakeFiles\prova1.dir/objects.a -Wl,--no-whole-archive  -o prova1.exe -Wl,--out-implib,libprova1.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\prova1.dir\linklibs.rsp
CMakeFiles\prova1.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Font::Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:12: undefined reference to `sf::Font::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Font::~Font()'
C:/Users/cristina/CLionProjects/prova1/main.cpp:11: undefined reference to `sf::Font::~Font()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\prova1.dir\build.make:93: prova1.exe] Error 1
mingw32-make.exe[3]: Leaving directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
mingw32-make.exe[2]: Leaving directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:78: CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:85: CMakeFiles/prova1.dir/rule] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
mingw32-make.exe: *** [Makefile:120: prova1] Error 2
« Last Edit: November 22, 2019, 03:42:57 pm by vrige »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #12 on: November 22, 2019, 03:56:48 pm »
Can you provide the content of @CMakeFiles\prova1.dir\linklibs.rsp?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vrige

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setting SFML on Clion
« Reply #13 on: November 22, 2019, 04:36:20 pm »
D:/Libraries/SFML/lib/sfml-graphics-s-d.lib D:/Libraries/SFML/lib/sfml-window-s-d.lib D:/Libraries/SFML/lib/sfml-system-s-d.lib -lwinmm -lgdi32 -lOpenGL32 D:/Libraries/SFML/lib/freetype.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: setting SFML on Clion
« Reply #14 on: November 22, 2019, 06:13:53 pm »
Oh!

For some reason CMake is detecting Visual Studio library files .lib instead of the MinGW library files .a
Which makes me question to what exactly you ahve put into the D:/Libraries/SFML/lib directory?

Make sure you download the matching SFML package for your compiler and delete all other, unrelated files.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/