0

I have a custom header file example.h which has prototypes for a few functions. There is a .C file example.c that I implemented which "includes" (#include "example.h") and has the implementations of the functions that has prototype in example.h.

Now, I have another function test.c that has to call the functions that are prototyped in example.h and are implemented in example.c. How Can I do it?

2 Answers 2

1

You need to link them all at the end (assuming you have already included the prototypes into your test.c). So if you're compiling, you can compile both of the .c files together into one executable. More commonly, however, is to compile these without linking (which produces object files). Then, at the end, link all of the object files together. To do this depends on your compiler, but an example would be:

gcc -c -o example.o example.c
gcc -c -o test.o test.c
gcc -o my_application test.o example.o

Or, for a small project, this works just as well

gcc -o my_application example.c test.c
Sign up to request clarification or add additional context in comments.

Comments

1

Just #include "example.h" in test.c (and don't forget to link all of the object files!)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.