Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Linux GCC
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 6:42am
daizhan299
Comments
Sergey Alexandrovich Kryukov at 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

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

Solution 1

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

—SA
  Permalink  
Comments
_theDead at 25-Dec-12 23:00pm
   
Could you show me more details? I am a novice for GCC.
Sergey Alexandrovich Kryukov at 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
_theDead at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,558
1 OriginalGriff 6,268
2 Peter Leow 2,534
3 Abhinav S 2,344
4 Maciej Los 2,297


Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 25 Dec 2012
Copyright © CodeProject, 1999-2015
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