Click to See Complete Forum and Search --> : 3 files: .c .c .h
barton boi
09-24-2003, 12:37 AM
I want to compile and link 2 .c files, and include 1 .h file.
I have BCC for windows, and GCC for linux. I can try this on either one. I believe I need to create a makefile, or is there an easier way?
Thanks
anfpunk
09-24-2003, 01:20 AM
should be able to do:
gcc -o file.o file.c
gcc -o file file.o
it's been awhile but I"m pretty sure that's right.
Oh yah, you'll prolly want to include the file in the .c files.
EverlastingGod
09-24-2003, 11:45 AM
Assuming the .h file is included by a #include in one of the two .c files...
gcc file1.c file2.c
or
gcc -c file1.c
gcc -c file2.c
gcc file1.o file2.o
or
gcc -c file1.c
gcc file1.o file2.c
or
gcc -c file2.c
gcc file2.o file1.c
or
any other variation on this
Note: Add -o executablename if you want an program name other than the default one.
gameboy1234
09-25-2003, 04:08 AM
echo "test: file1.c file2.c file.h" > Makefile
echo " gcc -o test file1.c file2.c" >> Makefile
make
After that, just type "make" to rebuild. Only works in Unix land, or if you've installed msys and mingw on your Windows system. Makes an executable called test (or test.exe under windows).
EverlastingGod
09-25-2003, 10:45 AM
Originally posted by gameboy1234
echo "test: file1.c file2.c file.h" > Makefile
echo " gcc -o test file1.c file2.c" >> Makefile
make
I think the forum chopped the whitespace... should be a tab before "gcc"
gameboy1234
09-25-2003, 05:30 PM
Yeah that's a tab not a space.