Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-23-2004, 06:17 PM   #1
LQ Newbie
Registered: Sep 2003
Location: Las Vegas
Distribution: mandrake
Posts: 14

Rep: Reputation: 0
I need help with compiling my C++ programs.

I am a student taking a C++ class. I have a program that the instructor wants us to put the source code in many files, for example: mainprogram.cpp, myclass.h, myclass.cpp. Myclass.h is a header file that contains a class, and myclass.cpp is a file that contains the class function definitions.

I have put the include statement for myclass.h at the beginning of the mainprogram.cpp file, and now I don't know how to compile the files. I tried “g++ mainprogram.cpp ,yclass.cpp” but it doest see any of the functions in the file myclass.cpp.

I read the man page for g++, but wasn't able to find any helpful information on the subject.

I did one thing that got everything to compile, but this isn't how the instructor wants us to do it. I put #include “myclass.cpp” at the top of the mainprogram.cpp file, then just did a g++mainprogram.cpp and it worked.

I hope I was able to explain what I want to know clear enough so that someone can help me; if not you can email me at and i will try to explain it again.

The school uses Red Hat Linux in the lab, but i dont know what version, or the version of the gcc compiler.

Any help will be appriciated.

Old 02-23-2004, 06:38 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
I put #include “myclass.cpp” at the top of the mainprogram.cpp file,
You are including a .cpp file. That should be a header file ( .h).
Old 02-23-2004, 06:50 PM   #3
LQ Newbie
Registered: Sep 2003
Location: Las Vegas
Distribution: mandrake
Posts: 14

Original Poster
Rep: Reputation: 0
Yes, I know it isnt right. I have at the top of my mainprogram.cpp file the following statements:
#include "myclass.h"
#include "myclass.cpp"
I know that this is the wrong way to do this, but I don't know the correct way to compile it.
Old 02-23-2004, 07:07 PM   #4
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Remove all the .cpp files from include lines. Only include the header files.

Then when you compile it it compile it like this:
g++ -Wall -o executable_name source1.cpp source2.cpp
-Wall simply shows all the warnings...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Programs Faxanadu Linux - Software 3 05-30-2005 02:51 AM
Compiling Programs Thorrn4 Linux - Software 6 03-26-2005 01:25 AM
Compiling Programs mike35 Linux - Newbie 2 10-22-2003 10:39 AM
compiling programs disorderly Linux - Newbie 2 10-17-2003 01:48 PM
compiling c,c++ programs ksd Linux - Newbie 9 10-13-2003 09:23 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:22 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration