access functions from another c file

This is a discussion on access functions from another c file within the C Programming forums, part of the General Programming Boards category; Hello, I have this problem. I have to create my own malloc file. I have made a header<.H file> that ...

  1. #1
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151

    access functions from another c file

    Hello, I have this problem. I have to create my own malloc file. I have made a header<.H file> that holds the function names of all my functions. I am calling this malloc from another file.

    I cannot compile that malloc file alone, because malloc requires data such sizeof etc....

    But when I am compiling my program (other than malloc). I get this error.

    Code:
    Undefined                       first referenced
     symbol                             in file
    my_malloc                           /var/tmp//ccKI1S6Y.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    What would be the way around this?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    In your .c file that defines malloc(), include all of the necessary header files, such as stdio.h or whatever else you need.

    In your .c file that uses your own malloc(), include the header files that you need, as well as your .h file for your malloc() (and any that your .h file depends upon).

    Compile them both together, or compile separately (but don't try to link them separately).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Help on simple file functions
    By enjoyincubus in forum C Programming
    Replies: 20
    Last Post: 12-01-2006, 03:41 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21