|
-
Sep 22nd, 2002, 08:22 PM
#1
Thread Starter
Frenzied Member
compile error for simple code (could be compiler)
Im compiling the following code using g++ on redhat 7.3:
Code:
//clim.cpp:
#include <iostream.h>
#include "client.h"
int main(int args, char* argv[])
{
int retVal;
retVal=Client->load(args,argv[1]);
cout << retVal << endl;
return retVal;
}
//client.h
#include <ncurses.h>
#include <stdlib.h>
class clim
{
private:
public:
long load(int args,char* argv);
};
clim* Client;
//client.cpp
#include "client.h"
#include <iostream.h>
long clim::load(int args, char* argv)
{
cout << "load" << endl;
return 20;
}
Now why doesnt that work?
When in CLi, I get an error "undefined reference to 'load'" and when in GUI, I get the error "undefined reference to 'main'
Both errors stem from an output file with a random filename, like cfkjd94..
Then collect2 says that ld returned a 1 exit status, whatever that means...
retired member. Thanks for everything 
-
Sep 23rd, 2002, 03:59 AM
#2
Monday Morning Lunatic
Did you compile both source files together?
Also, don't declare the Client inside the header, put it in the source file and use extern if you need it in both.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 23rd, 2002, 02:33 PM
#3
Thread Starter
Frenzied Member
am I supposed to compile it separately?
I now use 'gcc clim.cpp' thinking that it would compile everything that it has a reference to. Is that incorrect?
Any you mean having the extern in the clim.cpp, and the main dec. in the client.cpp?
Ill try that when Im back in linux
retired member. Thanks for everything 
-
Sep 23rd, 2002, 03:13 PM
#4
Monday Morning Lunatic
No. If you wanted to just *compile* it, use the -c switch to gcc. Otherwise, give both files on the command line and it'll sort the linking out.
See the GCC documentation
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 24th, 2002, 05:59 AM
#5
And use <iostream>.
Future versions of gcc are planned to have a mechanism that will automatically rip off the face of anyone using old-style headers, so you'd better go to the save side now.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 24th, 2002, 06:40 AM
#6
Monday Morning Lunatic
They already do. Sample output... 
Code:
#include <iostream.h>
void main() {
cout << "Hello world!" << endl;
}
...produces...
Code:
[mike@relativity mike]$ g++ -Wall -pedantic -o evil evil.cpp
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
from evil.cpp:1:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes
at least one deprecated or antiquated header. Please consider using one of the 32 headers
found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header
for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header
<strstream.h>. To disable this warning use -Wno-deprecated.
evil.cpp:3: `main' must return `int'
evil.cpp:3: warning: return type for `main' changed to `int'
[mike@relativity mike]$
Note to all, you should always use the -Wall flag, and -pedantic if you *really* want to get it right
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 24th, 2002, 06:45 AM
#7
Yeah, but the next version will literally rip your head off! I'm working on it...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 24th, 2002, 06:49 AM
#8
Monday Morning Lunatic
Make sure to get it compatible with the USB Crush-O-Matic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 24th, 2002, 06:50 AM
#9
Ok. Will do.
I hope GNU doesn't reject my module when it's ready.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 24th, 2002, 09:05 PM
#10
Thread Starter
Frenzied Member
3 questions:
whats -Wall and the other one do?
whats usb crushomatic? is that some funny program of a joke?
are you a devel. for gcc?

man i feel stupid around here; back in vb forums it was easy with answering what a messagebox is, but here..... WOO! MAN!
retired member. Thanks for everything 
-
Sep 24th, 2002, 09:24 PM
#11
Monday Morning Lunatic
-Wall turns on all warnings (see the GCC manual). -pedantic just makes it complain about the really little things 
USB Crush-O-Matic is my idea of a joke for when users do silly things the OS can get its own back 
Am I a gcc developer? **** no. I'm nowhere near good enough for that. In fact, it took some serious messing around just to even compile gcc...it causes internal compiler errors in some versions of gcc, you need to pick the right one to use
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 25th, 2002, 08:06 AM
#12
Neither am I. But there are too many people that use the old style headers out there, so I think drastic measures would be appropriate.
I just hope the Crush-O-Matic will never be supported under windows. It would be capable of killing people without any reason.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|