Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: need help with c++ headers

  1. #1
    Join Date
    Jan 2012
    Beans
    161

    Angry need help with c++ headers

    Ok i am programming in C++ and im trying to implement a header file....here is my code for the main function:

    Code:
    #include <iostream>
    #include "printsomething.h"
    
    using namespace std;
    
    int main(){
    
    printsomething ps;
    return 0;
    }
    and here is my header file (printsomething.h):

    Code:
    #ifndef PRINTSOMETHING_H
    #define PRINTSOMETHING_H
    
    
    class printsomething
    {
        public:
            printsomething();
    
    };
    
    #endif // PRINTSOMETHING_H
    here is my header source:

    Code:
    #include "printsomething.h"
    #include <iostream>
    
    using namespace std;
    
    printsomething::printsomething()
    {
        cout << "Don Juan with Don Cannon!" << endl;
    }
    when i try to build and run ( via codeblocks):

    I get the error:

    'undefined reference to 'printsomething:rintsomething()'

    WHYYYYYYYYYYYY

  2. #2
    Join Date
    Jan 2012
    Beans
    161

    Re: need help with c++ headers

    that is a double colon btw not a smiley face lol

  3. #3
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,273
    Distro
    Kubuntu

    Re: need help with c++ headers

    Quote Originally Posted by wingnut2626 View Post
    ]
    WHYYYYYYYYYYYY
    You have to compile both of your source files.

    Code:
    g++ main.cpp printsomething.cpp

  4. #4
    Join Date
    Jan 2012
    Beans
    161

    Re: need help with c++ headers

    how come the codeblocks doesnt do that automatically? and when i compile them both, it works but still cannot execute....

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,273
    Distro
    Kubuntu

    Re: need help with c++ headers

    I suspect that CodeBlock (CB) is compiling each file, thus producing individual object files. These two object files should then be linked together to form the executable program.

    If this is not transpiring, then undoubtedly there is a configuration issue with your project.

    I can only advise you about building projects from the command line; I disdain using an IDE for development, so I personally will not be able to help you with CB. Perhaps someone else can.

  6. #6
    Join Date
    Jan 2012
    Beans
    161

    Re: need help with c++ headers

    yes, ive been reading that IDE's are the "lazy man's method" so i think im going to begin to use command line resources to code. What do you reccommend?

  7. #7
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,273
    Distro
    Kubuntu

    Re: need help with c++ headers

    Quote Originally Posted by wingnut2626 View Post
    yes, ive been reading that IDE's are the "lazy man's method" so i think im going to begin to use command line resources to code. What do you reccommend?
    I recommend that you use the command line too.

  8. #8
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,664
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: need help with c++ headers

    These commands are all you really need to start with:

    http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

    (Example 2 is what you are trying to do at the moment).

    Once you are comfortable with those, have a look at 'make' and how to create Makefiles that automate the above. (There is a crude Makefile in the stuff I posted on your Tictactoe thread).

    Once you understand 'make' you can move on to the intimidating (but actually not that bad) task of setting up a project with GNU Autotools.
    Last edited by r-senior; January 31st, 2013 at 09:20 PM.

  9. #9
    Join Date
    Jan 2012
    Beans
    161

    Re: need help with c++ headers

    thanks! ill look into that now. you guys are very helpful!

  10. #10
    Join Date
    Jan 2012
    Beans
    161

    Re: need help with c++ headers

    And there are no code errors with my code is there?

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •