Last active
August 29, 2015 14:17
-
-
Save paulbuis/742a8ec87321ca09ebc1 to your computer and use it in GitHub Desktop.
Simple C language separate compilation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "foo.h" | |
int fooSum(struct foo* pFoo) { | |
return pFoo->a + pFoo->b; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct foo { | |
int a; | |
int b; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "foo.h" | |
int main(int argc, char* argv[]) { | |
struct foo f; | |
f.a = 1; | |
f.b = 2; | |
int s = fooSum(&f); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = gcc | |
CFLAGS = -g -Wall | |
TARGET = foo.exe | |
OFILES = main.o foo.o | |
LIBS = -lm | |
all: $(TARGET) | |
foo.o: foo.c foo.h | |
main.o: main.c foo.h | |
foo.exe: $(OFILES) | |
$(CC) $(CFLAGS) -o foo.exe $(OFILES) $(LIBS) | |
clean: | |
$(RM) foo.exe *.o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Directions to create an executable
create foo.o
gcc -c foo.c
create main.o
gcc -c main.c
link foo.o and main.o into foo.exe
gcc -o foo.exe main.o foo.o
compile in link as single command:
gcc -o foo.exe main.c foo.c
or use "make" to do this all for you
make