C++: Compile using Batch

Asked

Viewed 83 times

2

I’m using cmd to program, and I want to make a batch file that automates the build process. I want him to Compile the files using the command

g++ -c ./scr/Nome.cpp -o ./obj/Nome.o -std=c++1z

This should be done for all files .cpp which have been edited since the last compilation (I thought of doing an input, like this Nome would be the text the user typed, the program would then only continue if the user entered an empty line), and finally and run

cd obj
g++ Arq1.o Arq2.o -o ../a.exe

Putting all files in the obj folder instead of Arq1.o Arq2.o

How can I do that?

  • 2

    I recommend using the Cmake+Nmake. Making your own batch file to check the changes since the last build is nothing simple and it’s something that the build systems do natively. After all, that’s what they’re for: build software.

  • @Fernandosilveira I understand. I don’t usually compile by CLI, because I always used Ides

  • @Fernandosilveira Just one question, how can I debug my program line by line, because my program is going into infinite loop, but I can’t find where

  • In the gdb use the command break main and then run. When he stops at the breakpoint (function main) you can use the commands n, s, fin and c (next, step, finish and continue).

1 answer

1

There is already a tool for this and several other automation of compilations.

The tool is called make and is widely used in the GNU/Linux world.

I advise following this tutorial to learn the basics of the basics about the tool see HERE.

To get a general idea of what the make see HERE.

For further information see HERE.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.