Thread: Compiling Multifile Program

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    2

    Compiling Multifile Program

    I am trying to compile a program with two source files and a header file. A.cpp and B.cpp both include A.h which has my variables and function prototypes. However when I compile, I get variables undefined messages. What is the proper way of doing this? Thanx

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    first, this is the c board, not c++, and how are you compiling, you have to link them together.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you could start by saying which OS/Compiler you have

    Assuming (from your other post) that you have some windows oriented compiler with an IDE, you need to add A.cpp and B.cpp to the project source files, then choose "build"
    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.

  4. #4
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    Quote Originally Posted by chrismiceli
    first, this is the c board, not c++, and how are you compiling, you have to link them together.
    1. this is c++ board OBVIOUSLY
    2. Put the files in the same project...try that

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > 1. this is c++ board OBVIOUSLY
    Yeah, now it is - originally it was on the C board before I moved it here
    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.

  6. #6
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    Quote Originally Posted by Salem
    > 1. this is c++ board OBVIOUSLY
    Yeah, now it is - originally it was on the C board before I moved it here
    my bad then

  7. #7
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    use makefile

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Makefiles do rule but are a pain in the arse to setup

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. adding an #include stops my program from compiling
    By angelscars in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2005, 05:24 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 3
    Last Post: 04-19-2004, 08:09 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM