Including multiple .cpp file in project

This is a discussion on Including multiple .cpp file in project within the C++ Programming forums, part of the General Programming Boards category; I am writting a simple app and using g++ to compile. I am using seperate .cpp and .h files for ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    170

    Including multiple .cpp file in project

    I am writting a simple app and using g++ to compile.

    I am using seperate .cpp and .h files for each class. I have a main.cpp and .h that includes all of the .h files for each class.

    Some of the .cpp files are not found and I had to actually do a #include "Contact.cpp" to get it to compile. Is there something special I need to do to avoid having to do #include for the .cpp files? Do I have to resort to creating a makefile to get around this?
    Best Regards,

    Bonkey

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You shouldn't be #include'ing .cpp files, only .h ones.

    When you compile, an example would be:

    >>g++ -o myprog file1.cpp file2.cpp main.cpp

    Alternatively, you can compile each source file seperately, and then link the objects together afterwards.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    Thanks for the quick reply. That worked. I just had to add a few header files to some of the .h files for stdio and things like that.
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM

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