Ask Your Question
1

Is there a way to run a c++ file immediately using the sdl library without the need to repeatedly type the compiler flag?

asked 2023-05-07 12:44:39 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-07 12:46:01 +0000

qstack gravatar image

Yes, you can create a makefile to automate the build process. A makefile is a script that automates the building of a program, including compiling, linking, and executing. Here is an example makefile for a simple SDL program:

CC=g++
CFLAGS=-Wall -std=c++11
LIBS=-lSDL2

all: myprogram

myprogram: main.o
    $(CC) $(LIBS) $< -o $@

main.o: main.cpp
    $(CC) $(CFLAGS) -c $< -o $@

clean:
    rm -f myprogram main.o

To use this makefile, save it as "Makefile" (case-sensitive) in the same directory as your main.cpp file. Then in a terminal, type:

make
./myprogram

This will compile and link the program, producing an executable file called "myprogram", which you can run with the second command. Whenever you make changes to your source code, you can simply run "make" again to recompile and relink the program.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-07 12:44:39 +0000

Seen: 9 times

Last updated: May 07 '23