I have several .c files and one .a object file. What command with gcc should I use to compile them to one exe file? If we use a makefile, how will it look like?
The . a file is a library, already compiled. You compile your . c file to a .o, then you use the linker to link your .o with the . a to produce an executable.
Run the gcc command to compile your C program. The syntax you'll use is gcc filename. c -o filename.exe . This compiles the program and makes it executable.
For simple cases you can probably do this:
gcc -o maybe.exe useful.a something.c
Makefiles for non-trivial projects usually first invoke gcc to compile each .c file to a .o object.
gcc -c something.c
Then they invoke the linker (these days often using gcc as a wrapper for it) with a list of .o and .a files to link into an output executable.
gcc -o maybe.exe useful.a something.o
Note also that for most installed libraries, it's typical not to explicitly specify the .a file but instead to say -lhandy which would be short for "try to find something called libhandy.a in the configured (or specified with -L) search directories"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With