linking?! [newbie question]

This is a discussion on linking?! [newbie question] within the C Programming forums, part of the General Programming Boards category; Lets say my program spans across numerous .c files. How to I compile all those .c files into one program. ...

  1. #1
    Unregistered
    Guest

    Question linking?! [newbie question]

    Lets say my program spans across numerous .c files. How to I compile all those .c files into one program. I am using Borland 3.1.

    Is there a term for compiling many .c files into one program?

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > Is there a term for compiling many .c files into one program?
    Modularization.
    Look at your compiler's documents on how to do this.
    You usually compile the source files individually.
    Your linker then links the output files together into a file name specified by you.
    This is your executable program.
    The world is waiting. I must leave you now.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Just compile all of the files together.

    -Prelude
    My best code is written with the delete key.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You will need to use

    extern

    for global variables.
    Declare them in one file, if needed in another they are declared in the second file preceeded with 'extern'
    ie
    first file
    int iVar;

    second file for same variable
    extern int iVar;

    This tells the compiler to look in the other files for the variables declaration.

    Conditional compilation will also be needed for global structs declaration ect in header files included in more than one file. So you don't have to declare a struc ect in more than one place. (roughly)

    #ifndef MY_STRUCTS// if MY_STRUCTS is undefined
    #define MY_STRUCTS//define MY_STRUCTS so will be next file

    //write header file

    #endif//end of the if undefined statement
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems linking with g++
    By Just in forum Linux Programming
    Replies: 11
    Last Post: 07-24-2006, 01:35 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Replies: 8
    Last Post: 04-27-2006, 10:39 AM
  4. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  5. Linking error with DirectDrawCreateEx
    By jjj93421 in forum Game Programming
    Replies: 6
    Last Post: 04-06-2004, 03:57 PM

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