c++ - undefined reference to `function_name' -


i moved windows ubuntu , wanted try c++ programming on ubuntu. here simple code , stupid error can't resolve:

horse.h

#ifndef _horse_ #define _horse_  class horse{  int speed;  public:  void saysomething();  };  #endif 

horse.cpp

#include "horse.h" #include <iostream>  using namespace std;  void horse::saysomething(){     cout << "iiiihaaaaaaa brrrrr."<<endl; } 

and main.cpp

#include "horse.h"  int main(){      horse h;      h.saysomething();  } 

after compile (compilation successful) , run error message:

/tmp/ccxudyrd.o: in function `main': main.cpp:(.text+0x11): undefined reference `horse::saysomething()' collect2: ld returned 1 exit status 

please me somehow.

try

g++ -c main.cpp horse.cpp (to compile)

g++ -o a.out main.o horse.o (to link)


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -