Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a .h file called hello.h in the include folder,a .c file in lib folder called hello.c which is the definition of functions in hello.h, and a .c file in another folder called main.c which call the functions in hello.h to do something. How can I get hello.h, hello.c and main.c files complied together under the GCC complier?
Posted
Comments
Sergey Alexandrovich Kryukov 25-Dec-12 14:00pm    
Why giving us all those detail? Just read GCC documentation — how to pass file/path names to the compiler.
—SA

1 solution

Please see my comment to the question, and then, this: http://gcc.gnu.org/onlinedocs/[^].

—SA
 
Share this answer
 
Comments
daizhan 25-Dec-12 23:00pm    
Could you show me more details? I am a novice for GCC.
Sergey Alexandrovich Kryukov 26-Dec-12 0:28am    
You see, I could, but if you do it, it would probably take no more of your time as if I did it. But as you are the one who is interested immediately in looking into this, wouldn't it be more fair, if you do it first? If you face some problems, you are welcome to ask a follow-up question here.

There are no really principle difference in .h and .c files. For the compiler, they are all code files. However, the usual technique is to put only the declarations in .h files to make them visible to other .c files, and feed only the .c files to the compiler. This way, .h files go into the compiler only through the #include clause.

If you put these simple ideas together, you will see what to do; and it gives you more universal understanding on how C projects should be organized.

—SA
daizhan 26-Dec-12 4:02am    
Thanks for your advice.I have already solved this problem.I am working on APUE. But I know little about GCC. Could you give me some suggestions to know more about GCC?
Sergey Alexandrovich Kryukov 26-Dec-12 12:27pm    
I have no idea what so would be so special which needs a general advice. Learn it, get experience. Everything as usual. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900