SFML Setup within CLion
Understanding how CLion Handles Compilation & Execution
If you have ever wrote a simple «Hello World!» program within CLion, you would know that you are able to compile and run your code with a single click of the run button. The reason why you are able to have that streamlined experience is due to CLion’s use of a framework called CMake within their project creation templates. The reason why CLion is able to maintain that single-click run experience even when multiple files are made is due to the fact that it automatically integrates it into your CMakeLists.txt file. What the CMakeLists.txt file does is that it uses bulit-in commands of the CMake language to essentially detail what the project is and how it’s made. This can range from indicating the name of the executable and indicating source files all the way to complex compilation/execution rules. This is great beacuse it makes it so that a project can have lots of versatility, as you can determine what files and libraries to use.
Static Libraries vs Dynamic Libraries
As you already know, C++ is quite a vast language that comes with the standard libraries installed (ie. string, stdexcept, etc.), but withs this being said there are still so many things that you simply can’t do without using external libraries (unless of course you want to go about reinventing the wheel). In fact, many larger projects developed in the industry can you use several external libraries (ie. OpenGL, OpenCV, SFML..), and as a project becomes larger and larger linking the libraries within the terminal each and everytime can become quite tedious and tiresome — this is where the CMake frameworks comes in. CMake provides functions that allow you to link libraries for when you are compiling and running your software.
SFML
Installation
Windows
MacOS
Open terminal and type copy the following.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
This is instaling homebrew which is an open-source software package management system that simplifies the installation of software.
it should look something like this
This installs sfml through homebrew
Setup
Windows
MacOS
Once installation is done, in your Minesweeper project, copy and paste this into your CMakeLists.txt file:
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(<your project name here>)
## If you want to link SFML statically
# set(SFML_STATIC_LIBRARIES TRUE)
## In most cases better set in the CMake cache
# set(SFML_DIR "<sfml root prefix>/lib/cmake/SFML")
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(Minesweeper main.cpp)
target_link_libraries(Minesweeper sfml-graphics sfml-audio)
And replace the < your project name here > in the «project(< your project name here >)» part with the name of the project you made in CLion. The gator brackets shouldn’t be there. It should look like project(Minesweeper).
Running it
Here is a main.cpp you can use to test to see if it works, it is also on the repo if you want to get it there.
#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; }
i am setting up a work environment for a school project on my windows computer. We are going to make a basic game using c++ and CLion. To make a game i need to use the SFML library. I have followed a few tutorials but i cant seem to get it to work anyway.
I have:
- Downloaded CLion and configured it with MinGW
- Downloaded SFML and copied its «findSFML.cmake» file to a new directory in my project that i call cmake_modules.
- Edited my CMakeLists.txt file so it looks like this:
cmake_minimum_required(VERSION 3.6) project(testet) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES main.cpp) add_executable(testet ${SOURCE_FILES}) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") find_package(SFML REQUIRED system window graphics network audio) if (SFML_FOUND) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(testet ${SFML_LIBRARIES}) endif()
These are the three steps that i see on every tutorial / answer. But I get the following error anyway:
"C:Program Files (x86)JetBrainsCLion 2016.3bincmakebincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UsersBenjaminClionProjectstestet
CMake Error at cmake_modules/FindSFML.cmake:355 (message):
Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)
So it cant find the SFML? But should’nt the «findSFML.cmake» solve this? Any help is appretiated… Thanks!
asked Nov 23, 2016 at 20:00
I believe you are missing the link_directories()
call. You can use it like this:
link_directories("C:/Path_To_Library")
This should help solve your issue.
answered Nov 23, 2016 at 20:10
CodeLikeBeakerCodeLikeBeaker
20.3k13 gold badges78 silver badges107 bronze badges
6
I have successfully configured SFML with CLion on Ubuntu 16.04 and I think it will be same for Window user also.
My project name is SFML_TEST so change every occurrence of SFML_TEST with your project name.
- Create a new Clion C++ Project.
- Navigate to /path/to/CLionProjects/[Project_Name]/CMakeLists.txt
-
After the following statement
add_executable(SFML_TEST ${SOURCE_FILES})
Add following lines of code
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") find_package(SFML REQUIRED system window graphics network audio) if (SFML_FOUND) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(SFML_TEST ${SFML_LIBRARIES}) endif()
-
Create a new directory /path/to/CLionProjects/[project_name]/cmake_modules/FindSFML.cmake
- In FindSFML.cmake file paste the following line of code from the given file https://github.com/SFML/SFML/blob/master/cmake/Modules/FindSFML.cmake
- Done!!!.. Happy Coding
answered Sep 11, 2017 at 15:29
my fix was, that I had to change the root path of SFML in the FindSFML.cmake
so just set(SFML_ROOT Z://your_project)
after the block of comments and you are ready to go
answered Jan 23, 2018 at 9:31
Skip to content
I started to dig into c++ and SFML.
I had some problems setting up SFML in CLion, and after some research I finally found a good cmake config. So I’m going to share the Setup I have for everyone.
You will need SFML in your system. I’m on OSX so I did a brew install sfml in the terminal
You need a CMakeLists.txt
cmake_minimum_required(VERSION 3.10) project(shrump) set(CMAKE_CXX_STANDARD 11) # set(SOURCE_FILES main.cpp) add_executable(shrump main.cpp) #add_executable(Game ${SOURCE_FILES}) # 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()
and a FindSFML.cmake file inside cmake_modules folder in your project
Here is the content of the FindSFML.cmake file
cmake_minimum_required(VERSION 3.10)
project(shrump)
set(CMAKE_CXX_STANDARD 11)
# set(SOURCE_FILES main.cpp)
add_executable(shrump main.cpp)
#add_executable(Game ${SOURCE_FILES})
# 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()
Once we have that in place we can add the main.cpp file to your project and this
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(640,480,32),"Hello SFML");
sf::Font font;
font.loadFromFile("OpenSans-Bold.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;
}
And this should work 🙂
Here is a repo with a template as a reference or as a starting point for your own projects
https://github.com/perebalsach/sfml_clion_template.git
Вступление
Привет, это статья посвящена установке и подключение библиотеки SFML к среде разработки Clion в Linux Ubuntu. Я не могу гарантировать что это способ заработает на других дистрибутивах linux, но то что это работает в Ubuntu гарантирую на 90 %.
Проблемы
Я заметил что у многих людей возникают трудности подключения sfml не только к Clion, но и к другим средам разработки отличных от Visual Studio. Это видно по количеству запросов на форуме и видеороликов на youtube. В частности это проблемы связанны с cmake.
Установка
Итак приступим. Для начала воспользуемся информацией с официального сайта sfml, по установке на Ubuntu.
Забыл упомянуть что способ который я описываю работает с sfml 2.5 и выше. Для начала открываем терминал и вставляем туда команду:
sudo apt-get install libsfml-dev
, для установки sfml по стандартному пути.
Подключение
Открываем ваш clion и создаем новый c++ проект. После создание открываем файл — CmakeList.txt.
По умолчание ваш CmakeList.txt выглядит так.
cmake_minimum_required(VERSION ваша версия cmake)
project(ваш проект)
set(CMAKE_CXX_STANDARD стандарт c++)
add_executable(ваш проект main.cpp)
Мы же изменим его вот так.
cmake_minimum_required(VERSION ваша версия)
project(ваш проект)
set(CMAKE_CXX_STANDARD ваш стандарт c++)
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(ваш проект main.cpp)
target_link_libraries(ваш проект sfml-graphics sfml-audio)
В строке find_package() мы находим sfml по стандартному пути. В строке target_link_libraries() мы подключаем библиотеки. Вы также можете подключить остальные библиотеки sfml, например: sfml-network.
Тогда это будет выглядеть так: target_link_libraries(ваш проект sfml-graphics sfml-audio sfml-network).
Запуск!
Все готов обновляем ваш CmakeList.txt. и можно запускать.
Вставляем в ваш файл с функцией main тестовый код с сайта sfml.
Вот этот:
#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;
}
Заключение
И теперь вы можете работать с вашими sfml проектами в среде разработки clion.Или другой среды использующей build — систему cmake.
Для написание статья использовалась следующая информация: официальный сайт SFML.
For a school project I am trying to set up SFML on my computer that runs Windows 10. The assignment is developing a small engine, based on SFML, in a few weeks. I am very new to C++, and I am not used to the working pipeline and the ways of C++ development yet.
At the moment I am trying to set things up so that I can work on the project from home, but I have a lot of trouble understanding and setting things up, since it’s very different to what I’m use to.
My CMakeLists.txt file looks like the following:
cmake_minimum_required(VERSION 2.8.4)
project(CppEngine)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
if(WIN32)
set(SFML_ROOT "$ENV{PROGRAMFILES(x86)}/SFML")
endif(WIN32)
set(CMAKE_BUILD_TYPE Release)
find_package(SFML 2.1 COMPONENTS system window graphics REQUIRED)
include_directories(${SFML_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
set(SOURCE_FILES main.cpp )
set(HEADER_FILES )
add_executable(CppEngine ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(CppEngine ${SFML_LIBRARIES})
I get a very strange error message, as a result, whenever I try to compile and run. It is particularly strange, because I am running on Windows:
error: #error This UNIX operating system is not supported by SFML library
#error This UNIX operating system is not supported by SFML library
How can I fix this error?
#c #windows #sfml #clion
Вопрос:
У меня установлен SFML в CLion, но я сталкиваюсь с некоторыми проблемами, когда пытаюсь запустить какой-то базовый код, чтобы проверить, правильно ли он работает.
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
в этом нет ошибок,но он работает неправильно, я получаю это, когда запускаю его Process finished with exit code -1073741515 (0xC0000135)
. Есть какие-нибудь идеи о том, как это можно исправить?
это изображение кода, если оно вам поможет
кроме того,вот мой файл cmake
Комментарии:
1. попробуйте использовать
RenderWindow
вместоWindow
, также событие должно быть выведено за пределы цикла, чтобы избежать бессмысленного построения/разрушения каждого цикла.
Ответ №1:
Для флагов компоновщика вам необходимо добавить sfml-window
и sfml-system
.
Ответ №2:
Обновление: Я заставил его работать, мне нужно было переместить библиотеки DLL в файлы проекта и немного переписать CMake
Topic: setting SFML on Clion (Read 10584 times)
0 Members and 1 Guest are viewing this topic.
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
//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;
}
//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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UserscristinaDesktopsfml_clion_template-mastersfml_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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" --build C:UserscristinaDesktopsfml_clion_template-mastersfml_clion_template-mastercmake-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
CMakeFilessfml_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'
CMakeFilessfml_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'
CMakeFilessfml_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'
CMakeFilessfml_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
CMakeFilessfml_clion_template-master.dirbuild.make:90: recipe for target 'sfml_clion_template-master.exe' failed
CMakeFilesMakefile2: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
CMakeFilesMakefile2: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 »
Logged
« Last Edit: November 17, 2019, 08:02:45 pm by eXpl0it3r »
Logged
it still doesn’t work. Can you help me a little bit more? I don’t really know what to do.
//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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UserscristinaCLionProjectsprova1
-- 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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" --build C:UserscristinaCLionProjectsprova1cmake-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
CMakeFilesprova1.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()'
CMakeFilesprova1.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'
CMakeFilesprova1.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
CMakeFilesprova1.dirbuild.make:96: recipe for target 'prova1.exe' failed
CMakeFilesMakefile2: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
CMakeFilesMakefile2: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 »
Logged
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.
Logged
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)
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UserscristinaCLionProjectsprova1
-- 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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" --build C:UserscristinaCLionProjectsprova1cmake-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
CMakeFilesprova1.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()'
CMakeFilesprova1.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'
CMakeFilesprova1.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]: *** [CMakeFilesprova1.dirbuild.make:97: prova1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFilesMakefile2:75: CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:82: CMakeFiles/prova1.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: prova1] Error 2
Logged
can someone help me?
Is there a Clion+sfml tutorial?
Logged
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.
Logged
I changed it just a little bit:
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:librariesSFMLbin to my env variable Path, but it didn’t work.
Logged
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.
Logged
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;
}
====================[ Build | prova1 | Debug ]==================================
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" --build C:UserscristinaCLionProjectsprova1cmake-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
CMakeFilesprova1.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]: *** [CMakeFilesprova1.dirbuild.make:90: prova1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFilesMakefile2:75: CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:82: CMakeFiles/prova1.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: prova1] Error 2
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UserscristinaCLionProjectsprova1
-- 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
Logged
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).
Logged
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;
}
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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UserscristinaCLionProjectsprova1
-- 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 FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" --build C:UserscristinaCLionProjectsprova1cmake-build-debug --target prova1 -- -j 2
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -SC:UserscristinaCLionProjectsprova1 -BC:UserscristinaCLionProjectsprova1cmake-build-debug --check-build-system CMakeFilesMakefile.cmake 0
D:/mingw32/mingw32/bin/mingw32-make.exe -f CMakeFilesMakefile2 prova1
mingw32-make.exe[1]: Entering directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -SC:UserscristinaCLionProjectsprova1 -BC:UserscristinaCLionProjectsprova1cmake-build-debug --check-build-system CMakeFilesMakefile.cmake 0
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -E cmake_progress_start C:UserscristinaCLionProjectsprova1cmake-build-debugCMakeFiles 2
D:/mingw32/mingw32/bin/mingw32-make.exe -f CMakeFilesMakefile2 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 CMakeFilesprova1.dirbuild.make CMakeFiles/prova1.dir/depend
mingw32-make.exe[3]: Entering directory 'C:/Users/cristina/CLionProjects/prova1/cmake-build-debug'
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -E cmake_depends "MinGW Makefiles" C:UserscristinaCLionProjectsprova1 C:UserscristinaCLionProjectsprova1 C:UserscristinaCLionProjectsprova1cmake-build-debug C:UserscristinaCLionProjectsprova1cmake-build-debug C:UserscristinaCLionProjectsprova1cmake-build-debugCMakeFilesprova1.dirDependInfo.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 CMakeFilesprova1.dirbuild.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:mingw32mingw32bing++.exe -DSFML_STATIC @CMakeFiles/prova1.dir/includes_CXX.rsp -g -std=gnu++14 -o CMakeFilesprova1.dirmain.cpp.obj -c C:UserscristinaCLionProjectsprova1main.cpp
[100%] Linking CXX executable prova1.exe
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -E cmake_link_script CMakeFilesprova1.dirlink.txt --verbose=1
"C:Program FilesJetBrainsCLion 2019.2.4bincmakewinbincmake.exe" -E remove -f CMakeFilesprova1.dir/objects.a
D:mingw32mingw32binar.exe cr CMakeFilesprova1.dir/objects.a @CMakeFilesprova1.dirobjects1.rsp
D:mingw32mingw32bing++.exe -g -Wl,--whole-archive CMakeFilesprova1.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 @CMakeFilesprova1.dirlinklibs.rsp
CMakeFilesprova1.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]: *** [CMakeFilesprova1.dirbuild.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]: *** [CMakeFilesMakefile2:78: CMakeFiles/prova1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2: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 »
Logged
Can you provide the content of
@CMakeFilesprova1.dirlinklibs.rsp
?
Logged
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
Logged
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.
Logged
19 / 17 / 6 Регистрация: 09.01.2014 Сообщений: 337 |
|
1 |
|
08.09.2017, 20:52. Показов 6253. Ответов 4
Здравствуйте. В интернете много мануалов о подключении данной библиотеки к visual studio, но для CLion я не нашел ни одного мануала. Не могли бы вы пошагово объяснить как подключить sfml к Clion?
__________________
0 |
Don’t worry, be happy 17781 / 10545 / 2035 Регистрация: 27.09.2012 Сообщений: 26,514 Записей в блоге: 1 |
|
09.09.2017, 12:35 |
2 |
Скачайте SFML.cmake и подключайте без проблем.
1 |
19 / 17 / 6 Регистрация: 09.01.2014 Сообщений: 337 |
|
09.09.2017, 15:32 [ТС] |
3 |
А вы не могли бы несколько подробнее объяснить? Сейчас я скачиваю SFML для GCC 6.1.0 MinGW (SEH) — 64-bit, скачиваю сам компилятор, устанавливаю этот компилятор по умолчанию в Clion, а что дальше делать — не совсем понимаю если честно…
0 |
Don’t worry, be happy 17781 / 10545 / 2035 Регистрация: 27.09.2012 Сообщений: 26,514 Записей в блоге: 1 |
|
09.09.2017, 15:38 |
4 |
а что дальше делать — не совсем понимаю если честно… Вы не правильный вопрос задаете. Как подключить SFML (скачав FindSFML.cmake) расписано здесь: Если «в лоб», то необходимо указать компилятору
1 |
19 / 17 / 6 Регистрация: 09.01.2014 Сообщений: 337 |
|
09.09.2017, 16:49 [ТС] |
5 |
Да, я по этому мануалу и пытаюсь настроить. Проблема в том, что , на сколько я понимаю — при настройке как в примере предполагается, что у меня уже где-то в нужном месте лежит сама библиотека. Я делаю все как в примере, но так и не могу разобраться как указать компилятору Добавлено через 30 минут
0 |
Я устанавливаю рабочую среду для школьного проекта на моем компьютере с Windows. Мы собираемся сделать основную игру, используя c ++ и CLion. Чтобы сделать игру, мне нужно использовать библиотеку SFML. Я следовал нескольким урокам, но я все равно не могу заставить его работать.
Я имею:
- Скачал CLion и настроил его с помощью MinGW
- Скачал SFML и скопировал его файл «findSFML.cmake» в новый каталог в моем проекте, который я назвал cmake_modules.
- Отредактировал мой файл CMakeLists.txt, чтобы он выглядел так:
cmake_minimum_required(VERSION 3.6) project(testet) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES main.cpp) add_executable(testet ${SOURCE_FILES}) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") find_package(SFML REQUIRED system window graphics network audio) if (SFML_FOUND) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(testet ${SFML_LIBRARIES}) endif()
Вот три шага, которые я вижу в каждом уроке / ответе. Но я все равно получаю следующую ошибку:
"C:Program Files (x86)JetBrainsCLion 2016.3bincmakebincmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:UsersBenjaminClionProjectstestet
CMake Error at cmake_modules/FindSFML.cmake:355 (message):
Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)
Так он не может найти SFML? Но не должен ли «findSFML.cmake» решить эту проблему? Любая помощь оценивается … Спасибо! : D
1
Решение
Я полагаю, что вам не хватает link_directories()
вызов. Вы можете использовать это так:
link_directories("C:/Path_To_Library")
Это должно помочь решить вашу проблему.
0
Другие решения
Я успешно настроил SFML с CLion на Ubuntu 16.04 и я думаю, что это будет то же самое для пользователя Windows также.
Мой проект называется SFML_TEST так что меняйте каждый случай SFML_TEST с названием вашего проекта.
- Создайте новый проект Clion C ++.
- Перейдите в /path/to/CLionProjects/[Project_Name]/CMakeLists.txt
-
После следующего заявления
add_executable(SFML_TEST ${SOURCE_FILES})
Добавьте следующие строки кода
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") find_package(SFML REQUIRED system window graphics network audio) if (SFML_FOUND) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(SFML_TEST ${SFML_LIBRARIES}) endif()
-
Создайте новый каталог /path/to/CLionProjects/[project_name]/cmake_modules/FindSFML.cmake
- В файле FindSFML.cmake вставьте следующую строку кода из данного файла https://github.com/SFML/SFML/blob/master/cmake/Modules/FindSFML.cmake
- Готово !!! .. Счастливого кодирования
0
я решил, что мне нужно было изменить корневой путь SFML в FindSFML.cmake
так просто set(SFML_ROOT Z://your_project)
после блока комментариев и вы готовы идти
0