Click here to Skip to main content
13,046,533 members (72,878 online)
Rate this:
Please Sign up or sign in to 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 25-Dec-12 5:42am
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.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please see my comment to the question, and then, this:[^].

_theDead 25-Dec-12 23:00pm
Could you show me more details? I am a novice for GCC.
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.

_theDead 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. :-)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 25 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100