LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-23-2004, 05:17 PM   #1
bitessy
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 bitessy@yahoo.com 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.

Tessy
 
Old 02-23-2004, 05:38 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
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, 05:50 PM   #3
bitessy
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<iostream>
#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, 06:07 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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...
 
  


Reply


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 01:51 AM
Compiling Programs Thorrn4 Linux - Software 6 03-26-2005 12:25 AM
Compiling Programs mike35 Linux - Newbie 2 10-22-2003 09:39 AM
compiling programs disorderly Linux - Newbie 2 10-17-2003 12:48 PM
compiling c,c++ programs ksd Linux - Newbie 9 10-13-2003 08:23 AM


All times are GMT -5. The time now is 11:33 PM.

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