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
Printable View
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
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.
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.
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).
I think the forum chopped the whitespace... should be a tab before "gcc"Quote:
Originally posted by gameboy1234
echo "test: file1.c file2.c file.h" > Makefile
echo " gcc -o test file1.c file2.c" >> Makefile
make
Yeah that's a tab not a space.