0

-Hi, i'm working on a game project using cpp and SFML I try to compile it into a binary file for execute using this

g++ main.o -o sfml-app -I /path/to/sfml/include -lsfml-graphics -lsfml-window -lsfml-system

and 

./sfml-app

But the file didn't work and just keep follow the old codes after i change it, i have tried to delete the binary and compile again but didn't work either

4
  • Sorry i added wrong version, it was 24.04 Commented Aug 26 at 11:34
  • After the compile process, there were no errors. It just created a binary file which is the same as the old one, every time I delete it and start again. But the error while running the binary file is the same. Commented Aug 26 at 11:39
  • 5
    Since your input file appears to be an object file (main.o) your g++ command is just linking not compiling - the resulting binary won't reflect any changes you made to the any source code files such as main.cpp (unless you already re-compiled main.cpp to a new main.o) Commented Aug 26 at 11:52
  • Please do not use comments to add info that should be in the question. The question has an edit function. Commented Aug 26 at 18:14

1 Answer 1

1

As said in the comment by steeldriver, currently, you only are (re)linking your project, but you aren't rebuilding the object file(s) used to make the binary that have been modified since your last compilation.

You must:

  1. Recompile each altered object file (e.g., gcc -c main.c -I /path/to/sfml/include, and same for each modified .c file involved in your project since the last compilation),
  2. Link the project: gcc *.o -o sfml-app -I /path/to/sfml/include -lsfml-graphics -lsfml-window -lsfml-system.

Ideally, you should:

  • consider using a Makefile file + the make command (to install it: sudo apt install make);
  • generate the Makefile using the cmake utility or a similar tool (to install it: sudo apt install cmake + read a tutorial about cmake)
  • once your Makefile is ready, run make to compile your project.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.