Thread: Calling c object file into c source file

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Calling c object file into c source file

    Hi experts,,


    Im a new comer . I'm in situation to develop one c program .

    My scenario is

    I had one C object file(eg. sample.o) that contains some functions implementation and some more. now i need to call this object file into c file , Is it possible?? or Can i include in header file , through header file , Can i include in C source file.?? Is it possible?? , or any other way. But i don't have sample.o 's source file. What i want to do for acheieve this. I googled and read some articles . Not yet get solution.. Can some help me. thanks a lot.

    Regards

    R Prabu

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Object files are intermediate files. When you compile a C file, you get an object file... when you link your project, it combines one or more object files into an executable file, a DLL or a library file. Without a list of exports (known during compile) I don't think you'll make much use of it.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Calling c object file into c

    Hi


    Can you explain little more brief??

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Compiling and Linking - Cprogramming.com
    You don't look like using gcc C compiler. Anyway I think it'd still be useful. http://www.network-theory.co.uk/docs/gccintro/

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by prabu View Post
    Hi


    Can you explain little more brief??
    Ok... can't be done.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    In your main.c
    Code:
    extern int someFunctionInSample_dot_o();
    int main ( ) {
      someFunctionInSample_dot_o();
      return 0;
    }
    Then it's just
    gcc main.c sample.o

    This only really works if sample.o was compiled with the same compiler, for the same OS.

    You can't use it to link with any random object file you might have found.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 06-08-2009, 05:33 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM