User:Phosgram

...

GCC Debugging

GCC Notes

Compiler Commands
Commands run from a terminal or command line/prompt.

gcc Commands
gcc (GNU C Compiler)

Basic Compile to object code (.o file):
 * gcc -c filename.c

Basic Compile to executable:
 * gcc -o "progname" "folder\filename.c"

Error checking:
 * gcc -Werror -Wall -o progname "folder\filename.c"

Full, Error-Checking Compile:
 * gcc -Werror -Wall -pedantic -o "folder\filename.c"

C99 Compliant Compile:
 * gcc -std=gnu99 -o "progname" "folder\filename.c"

Print the output of the preprocessor:
 * gcc -E "folder\filename.c"

GDB Debugger ready compile:
 * gcc -o "progname" -g "folder\filename.c"
 * gcc -g "folder\filename.c"

Multi-file build with GCC:
 * gcc -o progname source1.c source2.c source3.c source4.c

g++ Commands
Generating a '.o' file
 * g++ -c myprog.cpp

Generating an executable
 * g++
 * eg: g++ -Wall myprog.cpp -o myprog
 * eg: g++ -Wall -Werror myprog.cpp -o myprog
 * eg: g++ -pedantic-errors myprog.cpp -o myprog

Multi-file build
 * g++ -o EXECUTABLE_NAME 1ST_FILENAME 2ND_FILENAME NTH_FILENAME
 * eg: g++ -o myprogram myprog.cpp testmyprog.cpp

Running compiled programs in Unix
 * $ ./
 * eg: $ ./myprog

Makefiles
Creating a makefile
 * Note, must be named "makefile" (no extension)
 * Note, must be in sourcefile directory

Basics
Basic example: test1: echo Hi There!

C++ example: myprog: g++ -o myprog myprog.cpp testmyprog.cpp

C / C++
Sample structure: FILE_EXTENSION_TO_LOOK_FOR = g++

1ST_O_FILE_NAME_TO_BUILD.o:  FILENAME HEADER_FILENAME(S)

2ND_O_FILE_NAME_TO_BUILD.o:  FILENAME HEADER_FILENAME(S)

EXECUTABLE_NAME:  2ND_O_FILE_NAME.o 1ST_O_FILE_NAME.o Example: CXX = g++ CC = g++

myprog.o:	myprog.cpp myprog.h

testmyprog.o:	testmyprog.cpp myprog.h

myprog:		myprog.o testmyprog.o

Compiling a makefile

Make
 * make PROGRAM_NAME_IN_MAKEFILE
 * eg: make myprog

MinGW (32 bit version):
 * mingw32-make PROGRAM_NAME_IN_MAKEFILE
 * eg: mingw32-make myprog

I used the sample makefile setup, but it is not generating an executable, how do I get it to do that?
 * For the above makefile setup to create an executable, the executable must share the same name as one of the ".o" files.
 * eg: "myprog: myprog.o testmyprog.o" works, but "myprog1: myprog.o testmyprog.o" would not.