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

Author Topic: CMake Linking errors  (Read 894 times)

0 Members and 1 Guest are viewing this topic.

NoahRGB

  • Newbie
  • *
  • Posts: 1
    • View Profile
CMake Linking errors
« on: July 27, 2022, 07:59:29 pm »
Hello

I'm not the best at C++, and the CMake / compilation / linking / library process is very new to me. I'm using CMake and Visual Studio Code. I am aware there is a tutorial I could follow step by step for this, but it uses CMake GUI and I am not looking to use that.

I seem to almost be there, and I have copied and pasted the 'pong' example into my main.cpp, and there are no errors. In addition, when I go to include a library it gives me a nice autocompleted list of the different modules, so I thought this was promising

I can build using CMake and it goes well without and error, but when I press the run button on VS Code, I get about 50 errors, some of them being LNK2019 and some LNK1120. I've tried researching what this means, but I can't fix it at all with anything online.. When I just use a blank main.cpp that uses cout it runs fine

This is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(SFML-Learning)

add_executable(SFML-Learning main.cpp)

set(SFML_DIR "SFML-2.5.1/lib/cmake/SFML")

find_package(SFML 2.5.1 COMPONENTS graphics window system audio)

add_executable(SFMLTest main.cpp)

target_link_libraries(SFMLTest sfml-graphics sfml-window sfml-system sfml-audio)

This is the start of my main.cpp (copied from the pong example)
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>
#include <cmath>
#include <ctime>
#include <cstdlib>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
...
...
...
...
...

 

I've tried the 32 bit and 64 bit GCC MinGW versions of SFML on the downloads page, because some topics online said it may be because of a mismatch, but they both create the same problems. The only other thing I can think of is the 'Kit' option on my VS Code UI, which gives me an option of Visual Studio Community 2019 and 2022 x64 and x86 Kits which are presumably used to link everything, so I may be using the wrong kit, but none of them seem to fix it

Can anyone think of a reason why this is happening?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: CMake Linking errors
« Reply #1 on: August 02, 2022, 12:36:13 am »
Are you using the CMake plugin in VS Code?
If you just setup the C++ plugin, it won't build with CMake and will ignore anything you did in the GUI.

See also here: https://code.visualstudio.com/docs/cpp/cmake-linux
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/