I have been trying to run SFML on VSCode using CMake. After getting CMake to build a working executable. I wrote a simple program that makes a window and draws a circle. However when I build the program I am getting an undefined reference error.
f:/program files/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: F:/projects/game engine/lib/libsfml-system-s-d.a(Err.cpp.obj):Err.cpp:(.rdata+0x40): undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::seekpos(std::fpos<int>, std::_Ios_Openmode)'
This is my main.cpp
:
#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;
}
These are my CMake lists:
cmake_minimum_required(VERSION 3.0.0)
project(game_engine VERSION 0.1.0)
SET(SFML_STATIC_LIBRARIES TRUE)
include_directories(${CMAKE_SOURCE_DIR}/include)
SET(SFML_DIR ${CMAKE_SOURCE_DIR}/lib/cmake/SFML)
find_package(SFML COMPONENTS graphics system window REQUIRED)
include(CTest)
enable_testing()
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-window)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
I am using VSCode and using the CMake tools extension.
I decided to make a MakeFile to check if anything will change and this was my code:
make:
g++ -g src/main.cpp -Iinclude -Llib -lopenal32 -lsfml-main -lsfml-system -l sfml-window -lsfml-graphics -lsfml-network -lsfml-audio -o main
When I ran the executable I got the following errors:
sfml-graphics-2.dll not found
sfml-window-2.dll not found
sfml-system-2.dll not foind
The folder organization is as follows:
Project
|-bin(all DLL files)
|-build(Cmake build files)
|-include(headers and other cpp files)
|-lib(all static libraries)
| |-cmake
| | |-SFML
|-src(my main.cpp)
|-CMakeLists.txt
|-MakeFile