Linking header files, Source files and main program(Accel. C++)

This is a discussion on Linking header files, Source files and main program(Accel. C++) within the C++ Programming forums, part of the General Programming Boards category; I've been working thru Accelerated C++ on my new laptop recently and I have finished chapter 4, well I'm up ...

  1. #1
    Registered User Daniel Primed's Avatar
    Join Date
    Jun 2005
    Posts
    13

    Linking header files, Source files and main program(Accel. C++)

    I've been working thru Accelerated C++ on my new laptop recently and I have finished chapter 4, well I'm up to the exercises. The problem is that the chapter goes thru how to organize a program and the big program is one that uses header files, regular code and source files for the header files. I've saved the header files as .h files and C++ code as .cpp files. I'm not sure what happens to the source files. Thye are the source for the 2 header files, they aren't the header files but use and declare some of what is in the header files that they belong to. I'm not sure what to do about the source files. Are they just regular C++ files because there is no reference to them in the main program. If anyone that has used Accelerated C++ could help me out or point me in the right direction that would be apreciated.

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    18
    I also tried to use the code of chapter 4 of this book but it didn't work neither , so I gave up and returned to Teach Yourself in 21 days ...

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,328
    Thye are the source for the 2 header files, they aren't the header files but use and declare some of what is in the header files that they belong to. I'm not sure what to do about the source files. Are they just regular C++ files because there is no reference to them in the main program.
    You can treat them as 'regular' C++ source files. One way would be to name the source file for foo.h as foo.cpp, but the actual name of the source file doesnt matter to the compiler and linker so long as it is compiled and linked.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    If you are using an IDE like Dev-C++ or Visual C++, add all the source files (cpp files) to the project. As long as one and only one of those files has a main() function, the project will compile and link them together correctly.

    If you are using a command-line compiler, then you need to compile all the source files. A makefile makes it easier to handle that, so consider learning how to use one if you don't use an IDE.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confusion on header and source files
    By dnguyen1022 in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2009, 02:42 AM
  2. compiling source files and header file at once?
    By 1jackjack in forum C Programming
    Replies: 10
    Last Post: 05-04-2007, 11:06 AM
  3. windows header files not linking correctly
    By skorman00 in forum Windows Programming
    Replies: 2
    Last Post: 04-13-2005, 11:14 AM
  4. Linking Source Files
    By ChrisJ in forum C++ Programming
    Replies: 4
    Last Post: 06-27-2003, 09:33 AM
  5. linking source files
    By estranged in forum C Programming
    Replies: 9
    Last Post: 04-03-2002, 05:38 PM

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