Including header files and source files for classes
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
This would also work:
g++ -Wall -o main main.cpp test.cpp
In my first method I build a non-linked object file (the -c option does this) that contains the binary code for the test.cpp class. This binary must be included in the 2nd compile for linking purposes. The 2nd method gets rid of the middle step... but is less ideal if you are building a large project with lots and lots of files.
BTW, to compile that example I did have to change endl to std::endl in the cout statement. It would have been equally correct to just set the namespace to standard by putting in a "use namespace std;" line in main.cpp.
Originally posted by jtshaw If you find yourself having to include cpp files then typically one of the following is true:
1. Your missing a declaration in your header file.
2. Your doing some obscure embedded programming with a poor compiler.
3. Your not linking your program properly.
4. You have a major design problem.
I have seen this only once, in glibc, but there it is used very, very often. Entering
grep -r '#include.*\.c[">]' glibc-2.3.5 | wc -l
gives me 1607 lines. I don't know why it is done there, certainly not for point 1., 2., or 3., and probably not for 4.; it seems that sometimes there are good reasons to do so.