g++ compiling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad5000
    New Member
    • Sep 2006
    • 22

    g++ compiling

    I can't compile this using g++
    michael@michael :~/g++$ g++ program.cpp
    //ClassA.h
    class ClassA{
    private:
    int atribute;
    public:
    ClassA(int atribute);
    };
    //ClassA.cpp
    #include "ClassA.h"

    ClassA::ClassA( int atribute){
    this->atribute = atribute;
    }
    //program.cpp
    #include "ClassA.h"
    #include <iostream>

    int main(){
    ClassA object(10);
    return 1;
    }

    the compiler returns the folowing error msg:

    /tmp/ccwwAJmP.o(.tex t+0x1f): In function `main':
    : undefined reference to `ClassA::ClassA[in-charge](int)'
    collect2: ld returned 1 exit status
  • tyreld
    New Member
    • Sep 2006
    • 144

    #2
    You need to provide the compiler with all the necessary source files. You neglected to tell it that ClassA.cpp contains code needed to properly link the program. The following should solve your problem.

    g++ program.cpp ClassA.cpp

    Comment

    • nomad5000
      New Member
      • Sep 2006
      • 22

      #3
      thank you very much!

      Comment

      Working...