K
Kevin Handy
key9 said:Hi all
look at the organize tree
Sounds like a troll already.
Bad engrish, lack of caps, etc.
main.c
------
#include lib_adapter.c
main()
{
foo();
}
lib_adapter.c
-------------
#include "foo_liba.c"
#include "foo_libb.c"
void foo(){
#ifdef USING_LIBA
foo_liba()
#endif
#ifdef USING_LIBB
foo_libb()
#endif
}
void need();
lib_a.c
=======
void foo_liba()
{
need();
}
lib_b.c
-------
void foo_libb()
{
need()
}
gcc -o main main.c lib_adapter.c lib_a.c lib_b.c
some of the problems:
1. main should return an int.
2. Include files should not contain executable code.
You want to end up with one copy of each function,
and putting code in include files causes the function
to be expressed every time you include the file,
causing the linker to be upset about multiple definitions.
3. Include files should end in a '.h' extension.
It's a convention, and most C programmers expect it.
This allows for a 'cc *.c -o xxx' at the command line
to compile most simple programs.
4. Since lib_adapter.c, lib_a.c, and lib_b.c are all
included in main.c, why are you compiling them a
second time?
5. main should return a value.
6. need() is not implementated anywhere.
7. Neither "USING_LIBA" nor "USING_LIBB" are defined,
thus foo() is a null function.
8. need() is prototyped after use, instead of before.
....
the code can not be complained , what I want to know is
Why can't it be complained. I see lots of things to complain about.
What errors do you get? Are we supposed to guess?
I can not put need() out side of the lib_adapter.c
What happens when you try? What error do you get?
1.how to write include structure
2.need I have to write .h file instead of include c file?
You don't seem to really understand the purpose of
include files.