Results 1 to 12 of 12

Thread: compile error for simple code (could be compiler)

  1. #1

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    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

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    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

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  10. #10

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    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

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    -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

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width