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

Author Topic: Undefined references when building test project (Windows 10/CLion)  (Read 1216 times)

0 Members and 1 Guest are viewing this topic.

Popinaodude

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hi there,

I'm just trying to get my SFML setup working properly so I can get started on a project and I've spent the past day trawling through forum posts old and recent but none of the fixes suggested before have worked for me.

I have built SFML myself using static libraries with the CMake GUI. I am using the CLion IDE.

Here is the contents of my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.17)
project(SFML_test)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
set(CMAKE_VERBOSE_MAKEFILE ON)

file(GLOB SOURCES "./*.cpp")
add_executable(SFML_test ${SOURCES})

# SFML
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "C:/Program Files (x86)/SFML/lib/cmake/SFML")
find_package(SFML 2.5 COMPONENTS system graphics window audio REQUIRED)
target_link_libraries(SFML_test sfml-system sfml-graphics sfml-window sfml-audio)
 

Here is the full build log with the error when I try and build:
====================[ Build | SFML_test | Debug ]===============================
"C:\Program Files\JetBrains\CLion 2020.3\bin\cmake\win\bin\cmake.exe" --build D:\Weekend_Projects\SFML_test\cmake-build-debug --target SFML_test -- -j 9
-- Found SFML 2.5.1 in C:/Program Files (x86)/SFML/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Weekend_Projects/SFML_test/cmake-build-debug
[ 50%] Building CXX object CMakeFiles/SFML_test.dir/main.cpp.obj
[100%] Linking CXX executable SFML_test.exe
"C:\Program Files\JetBrains\CLion 2020.3\bin\cmake\win\bin\cmake.exe" -E rm -f CMakeFiles\SFML_test.dir/objects.a
C:\PROGRA~1\MINGW-~1\I686-7~1.0-R\mingw32\bin\ar.exe cr CMakeFiles\SFML_test.dir/objects.a @CMakeFiles\SFML_test.dir\objects1.rsp
C:\PROGRA~1\MINGW-~1\I686-7~1.0-R\mingw32\bin\G__~1.EXE  -static -g   -Wl,--whole-archive CMakeFiles\SFML_test.dir/objects.a -Wl,--no-whole-archive  -o SFML_test.exe -Wl,--out-implib,libSFML_test.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\SFML_test.dir\linklibs.rsp
CMakeFiles\SFML_test.dir/objects.a(main.cpp.obj): In function `main':
D:/Weekend_Projects/SFML_test/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
D:/Weekend_Projects/SFML_test/main.cpp:8: undefined reference to `sf::String::String(char const*, std::locale const&)'
D:/Weekend_Projects/SFML_test/main.cpp:8: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
D:/Weekend_Projects/SFML_test/main.cpp:8: undefined reference to `sf::RenderWindow::~RenderWindow()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\SFML_test.dir\build.make:120: SFML_test.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:98: CMakeFiles/SFML_test.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:105: CMakeFiles/SFML_test.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:137: SFML_test] Error 2
 

I've tried switching around the linked libraries with no luck. I'm sure there's something very simple that I'm missing. Any help would be appreciated, thanks!
« Last Edit: January 08, 2021, 02:05:47 am by Popinaodude »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Undefined references when building test project (Windows 10/CLion)
« Reply #1 on: January 30, 2021, 11:44:33 am »
What does the file CMakeFiles\SFML_test.dir\linklibs.rsp contain?

Have you tried find_package(SFML 2.5 COMPONENTS graphics window audio system REQUIRED) instead?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/