Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/11/2013, 08:23
finikini
 
Fecha de Ingreso: abril-2005
Mensajes: 100
Antigüedad: 19 años
Puntos: 0
Error "undefined reference to" al compilar

Hola, recien comencé a aprender C++ y al tratar de compilar este codigo me da error.

main.cpp
Código C++:
Ver original
  1. #include "Core.h"
  2.  
  3. int main ( int argc, char* argv[] ){
  4.  
  5.     Core::singleton().Init( &argc, argv );
  6.     Core::singleton().Run();
  7.     Core::singleton().DeInit();
  8.    
  9. }

Core.h
Código C++:
Ver original
  1. #ifndef __Core__
  2. #define __Core__
  3.  
  4. class Core {
  5.  
  6.     private:
  7.     static Core instance;
  8.     Core();
  9.     ~Core();
  10.  
  11.     public:
  12.     static Core& singleton();
  13.  
  14.     public:
  15.     void Init(int* argc, char* argv[]);
  16.     void Run();
  17.     void DeInit();
  18.     private:
  19.    
  20. };
  21.  
  22. #endif

Core.cpp
Código C++:
Ver original
  1. #include "Core.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. Core Core::instance;
  7.  
  8. Core::Core(){}
  9.  
  10. Core::~Core(){}
  11.  
  12. Core& Core::singleton(){ return instance; }
  13.  
  14. void Core::Init ( int* argc, char* argv[] ){ cout << "Inicializamos el Core\n"; }
  15.  
  16. void Core::Run(){
  17.  
  18.     int i = 0;
  19.     for( i = 0 ; i < 1000000; ++i ){
  20.    
  21.         if( !( i % 10000 ) ){ cout << "Ejecutamos el paso de core numero: " << ( i / 10000 ) << "\n"; }
  22.        
  23.     }
  24.  
  25. }
  26.  
  27. void Core::DeInit(){ cout << "Desinicializamos el Core\n"; }

y este es el error que me da al compilar.
Cita:
C:\Users\Kira\Desktop\pr>g++ main.cpp
C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o:main.c pp:(.text+0x1a): undefined reference to `Core::singleton()'
C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o:main.c pp:(.text+0x2b): undefined reference to `Core::Init(int*, char**)'
C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o:main.c pp:(.text+0x33): undefined reference to `Core::singleton()'
C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o:main.c pp:(.text+0x3a): undefined reference to `Core::Run()'
C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o:main.c pp:(.text+0x3f): undefined reference to `Core::singleton()'
C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o:main.c pp:(.text+0x46): undefined reference to `Core::DeInit()'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\Kira\AppData\Local\Temp\ccoYCN4x.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Para compilar uso la ultima version de mingw g++ en windows, no uso IDE y los tres archivos estan en la misma carpeta. Para codigos simples de un solo archivo si compila correctamente. Por lo que he leido es posible que el problema tenga algo que ver con los enlaces pero ni idea de como solucionarlo.