#error sfml
58 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@full nebula
/usr/bin/ld: main.o: in function `main':
main.cpp:(.text+0x11): undefined reference to `Game::Game()'
/usr/bin/ld: main.cpp:(.text+0x1f): undefined reference to `Game::update()'
/usr/bin/ld: main.cpp:(.text+0x2b): undefined reference to `Game::render()'
/usr/bin/ld: main.cpp:(.text+0x37): undefined reference to `Game::running() const'
/usr/bin/ld: main.cpp:(.text+0x4c): undefined reference to `Game::~Game()'
/usr/bin/ld: main.cpp:(.text+0x5f): undefined reference to `Game::~Game()'
collect2: error: ld returned 1 exit status
error message
who wrote the makefile
i found it on the internet
you're on linux?
yes
your game.cpp file did not define ~Game(), Game::running() and all of the rest of these functions
it's not the cmake script that is causing the issue
How can I fix the problem
wait, something else is happening here
your game.cpp file has these implementations, but when the raw binary sfml-app is built, more specifically linked, it behaves as if game.cpp has never been compiled at all.
I think I noticed what happened here. your makefile doesn't have a line there, or "recipe" to "cook" the file game.o, compiled from the file game.cpp, which contains the implementations of everything declared in game.h and used in whoever includes that header.
So,
sfml-app: main.o game.o
g++ main.o game.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
main.o: main.cpp
g++ -c main.cpp
game.o: game.cpp game.h
g++ -c game.cpp
this should work
you are not paying any attention to OP's issue here
I don't write make, he's using KDevelop which primarily supports CMake and SFML advises using CMake
also he used a makefile he found on the internet, so there's no guarantee it will work. clearly it did not
!howto ask
Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.
State your problem clearly and provide all necessary details:
- the relevant portion of your code, or all of it
- the expected output
- the actual output (or the full error)
:trophy: Gold Standard: Minimal Reproducible Example
Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:
- Compiler Explorer for most C and C++ snippets
- OnlineGDB for interaction, debugging
:no_entry: Do not post screenshots, let alone photos of your screen!
so did it work?
I did post this thread because the help channel was overcrowded
I'm gonna test this tomorrow or the next day after that
do you understand what exactly these lines in the makefile do?
No
Maybe execute terminal commanda
yes, and those commands are
#compile game.o from game.cpp only when game.cpp or game.h have been changed
game.o: game.cpp game.h
g++ -c game.cpp
#compile main.o only when main.cpp changed
main.o: main.cpp
g++ -c main.cpp
#link all the .o object files into the executable
sfml-app: main.o game.o
g++ main.o game.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
@wispy wren makefile:3: *** missing separator. Stop.
erase my comments beginning with a hash
same thing but now the second line

its the same as before
what order did you put the commands into?
just build on the kdevelop
what are you talking about
sfml-app: main.o game.o
g++ main.o game.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
main.o: main.cpp
g++ -c main.cpp
game.o: game.cpp game.h
g++ -c game.cpp
each command in the recipe needs to begin with one TAB character
try it
I have a basic tutorial on makefiles if you need that: https://github.com/HolyBlackCat/cpp-tutorials/blob/master/articles/multifile_programs.md
Contribute to HolyBlackCat/cpp-tutorials development by creating an account on GitHub.
Forgot to say that it works
Btw how do I add files
or open your file explorer and drag and drop with the mouse
I meant add files to the makefile
well, there's some hacks with *.c
but for now just add a new line at the bottom
it would be much easier to use the cmake template https://github.com/SFML/cmake-sfml-project
it's very portable, you can use it with any OS/Compiler/IDE/etc
if OP doesn't know the syntax of gcc itself, what is the point of this?
the point is that they don't need to learn it, instead they can use this industry-wide tool that integrate seamlessly into many different code environment.
A working template is provided which means they don't have to toy around with any setting or config
don;t need to learn the gcc syntax? what???
yep!
uninstall please
it's also the official recommended way to setup SFML by the team
I'm sorry, what's the issue?
CMake is a meta-build system, you write your config once and then it generates the build config files for whatever buildsystem/IDE/OS/compiler you are using
I literally linked a tutorial 