#error sfml

58 messages ยท Page 1 of 1 (latest)

green rivetBOT
#

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.

wild sequoia
#

@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

full nebula
#

who wrote the makefile

wild sequoia
#

i found it on the internet

full nebula
#

you're on linux?

wild sequoia
#

yes

wispy wren
# wild sequoia yes

your game.cpp file did not define ~Game(), Game::running() and all of the rest of these functions

wispy wren
wispy wren
# wild sequoia 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

wispy wren
full nebula
#

also he used a makefile he found on the internet, so there's no guarantee it will work. clearly it did not

rustic oasis
#

!howto ask

green rivetBOT
# rustic oasis !howto ask
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

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
Where to Post

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!
wispy wren
wild sequoia
wild sequoia
wispy wren
wild sequoia
#

Maybe execute terminal commanda

wispy wren
# wild sequoia 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
wild sequoia
#

@wispy wren makefile:3: *** missing separator. Stop.

wispy wren
wild sequoia
#

same thing but now the second line

wild sequoia
#

its the same as before

wispy wren
wild sequoia
#

just build on the kdevelop

wispy wren
#

what are you talking about

wispy wren
# wild sequoia just build on the kdevelop
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

hearty badger
wild sequoia
#

Btw how do I add files

hearty badger
#

Wdym add files??

#

You mean send to discord?

wispy wren
#

or open your file explorer and drag and drop with the mouse

wild sequoia
wispy wren
robust viper
#

it's very portable, you can use it with any OS/Compiler/IDE/etc

wispy wren
robust viper
#

A working template is provided which means they don't have to toy around with any setting or config

wispy wren
robust viper
wispy wren
robust viper
#

it's also the official recommended way to setup SFML by the team

robust viper
robust viper
# wispy wren uninstall please

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

hearty badger