Thread: some problems with #include

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    32

    some problems with #include

    ok i got a structure i need to follow...

    i've got a file named say : file1.c which got the implementation of 4 functions in it... and also #includes myheader.h

    then i've got a file named: myheader.h which contains 10 more functions headers and also got the 4 function headers for the files in file1.c

    i now have another file myheader.c which implements the 10 extra function in myheader.h but also makes use of the functions found in file1.c

    I will now have a file test.c which will be my main program i'll test from...

    I understand the explanation is a bit messy but I can't make it more clear. Please can any1 tell me how should i compile on gcc? and if there are any more includes i should do?

    Thanks

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Provided you used #include <myheader.h>:

    gcc -I/path/to/myheader.h myheader.c file1.c test.c

    If you used a string instead, then gcc looks in the executable's destination folder for the header files, and should compile and link fine.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    32
    sorry but this is first time i'm messing like this with header files

    so are you saying i should only do 'gcc test.c'?

    cos if thats it i'm getting this:

    In file included from test.c:4:
    myheader.h:45: error: two or more data types in declaration of `function1'

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    That's nothing to do with include files, that's just what you've written inside them.

    Maybe a missing ; on a previous struct?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    that's not what I said at all. You have to compile all source files that are relevant to the project of course.

    And so far it doesn't seem like an "include" problem. It looks like your h file doesn't compile correctly (a syntax error?), can you post it here?

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    32
    its part of an assignment so i guess no... i'll try and check out for the bugs u told me first, i'll post here later....

    thanks for now

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    32
    sorted this out... yeah salem u were right hehe had forgotten the ';'. And i wasn't compiling all my files at one go...

    kinda new to header files, was a Pascal geek for over 8 years lol... anyway thx guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with function call
    By NeMewSys in forum C++ Programming
    Replies: 16
    Last Post: 05-22-2008, 01:53 PM
  2. C programing doubt
    By sivasankari in forum C Programming
    Replies: 2
    Last Post: 04-29-2008, 09:19 AM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. #Include "class" problems
    By Unregistered in forum C++ Programming
    Replies: 17
    Last Post: 11-26-2001, 10:40 AM