I have a test.c file which contains main() function and some test cases and it cannot be modified it(such as adding "include *.h"). Then I have a foo.c file which contains some functions(no main() function). These functions will be tested through test cases in test.c file. What I'm going to do is use foo.c as a library and link it to test.c file. And here is the simple code.
test.c
//cannot modify int main(){ ... bar(); ... } foo.c
#include "foo.h" //I will explain this below. int bar(){ ... } I'm trying to implement an interface using .h file, such as
foo.h
#ifndef _FOO_H_ #define _FOO_H_ extern int bar(); #endif Then using cmd line
gcc -c foo.c gcc -o output test.c foo.o ./output You may guess the result. There is a warning that "implicit declaration of function 'bar' is invalid in C99 [-Wimplicit-function-declaration]". And the test.c file cannot run correctly.
Could someone help me about this? Thank you so much!
main.c?