c++ addition of header files in linux - g++ -


all right tired looking question guess time ask :) before describe problem, project works fine on visual 2013 not suse linux g++ 4.6.2

we suppose use library cio consist of 3 files console.h, console.cpp , keys.h . main program uses 3 files called happy.cpp.

now on visual studio 2013 works fine. when try compile on linux, gives me lots of errors.

following brief code description of project

//console.h namespace cio {  // console holds state of console input output facility // class console {     //some varialbes , functions     int   getrows() const; };  extern console console; // console object - external linkage  } // end namespace cio  =============================================================================== //console.cpp /* table of platforms */ #define cio_linux       1 #define cio_microsoft   2 #define cio_borland     3 #define cio_unix        4  /* auto-select platform here */ #if   defined __borlandc__     #define cio_platform cio_borland     #define cio_lower_level_h_ <conio.h> #elif defined _msc_ver     #define cio_platform cio_microsoft     #include <windows.h>     #define cio_lower_level_h_ <conio.h> #elif defined __mach__     #define cio_platform cio_unix     #define cio_lower_level_h_ <curses.h> #elif defined __gnuc__     #define cio_platform cio_linux     #define cio_lower_level_h_ <ncurses.h> #elif !defined __borlandc__ && !defined _msc_ver && !defined __gnuc__ && !defined __mach__     #error console_plt undefined #endif  extern "c" {     #include cio_lower_level_h_ }  #include "console.h" #include "keys.h"  namespace cio { // continuation of cio namespace  // getrows retrieves number of rows in output object // int  console::getrows() const {     return bufrows; }  } // end namespace cio ================================================================================ //////happy.cpp  #include "console.h"  #include "keys.h"    // escape  using namespace cio;   int main() {      int key, rows, columns;       // screen dimensions      rows    = console.getrows();  } 

on compiling using "g++ happyface.cpp" command, following errors

happyface.cpp:(.text+0xd): undefined reference cio::console' happyface.cpp:(.text+0x12): undefined reference tocio::console::getrows() const

i dont know doing wrong here? tried including paths "g++ -i ~/happy/console.h ~/happy/console.cpp ~/happy/keys.h" , still same problem.

extern console console; // console object - external linkage 

make sure it's defined somewhere, e.g. in console.cpp. i'm not seeing definition.

g++ -i ~/happy/console.h ~/happy/console.cpp ~/happy/keys.h 

the -i flag should not necessary. assuming directory looks this:

~/happy  - console.h  - console.cpp  - keys.h  - happyface.cpp 

you should able do

cd ~/happy g++ console.cpp happyface.cpp -o happyface ./happyface 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -