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

  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
    28,412
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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, 03: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, 06:38 PM