Сам вопрос: почему не линкует?
Вот файлы:
Код: Выделить всё
# %CPATH% and %LIBRARY_PATH% with headers and libs must exist in env. variables
hello.exe: main.o he.o
gcc main.o he.o -lSDL -o hello.exe
main.o: main.cpp
gcc -x c++ -c main.cpp
he.o: he.h he.cpp
gcc -x c++ -c he.h he.cpp
run:
hello.exe
clean:
del hello.exe main.o he.omain.cpp
Код: Выделить всё
#include "SDL.h"
#include <stdio.h>
#include "he.h"
#undef main
int main(int argc, char *argv[]) {
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
printf("Could not initialize SDL: %s.\n", SDL_GetError());
exit(-1);
}
HE* h = HE::instance();
SDL_Quit();
printf("!!!!");
return 0;
}he.h
Код: Выделить всё
#ifndef _HE_
#define _HE_
class HE{
public:
static HE* instance();
private:
static HE* _instance;
HE();
};
#endifhe.cpp
Код: Выделить всё
#include "he.h"
HE* HE::_instance = 0;
HE::HE(){}
HE* HE::instance() {
if (_instance == 0) {
_instance = new HE();
}
return _instance;
}При этом:
Код: Выделить всё
C:\!Docs\!c\sdl>make
gcc -c main.cpp
gcc -x c++ -c he.h he.cpp
gcc main.o he.o -lSDL -o hello.exe
he.o:he.cpp:(.text+0x24): undefined reference to `operator new(unsigned int)'
collect2: ld returned 1 exit status
make: *** [hello.exe] Error 1В чем траблы? Походу неправильно собираю, хотя если все объединиить в 1 файл и просто его компилить через
Код: Выделить всё
C:\!Docs\!c\sdl>gcc -x c++ all.cpp -lSDL -o all.exe
C:\DOCUME~1\ner\LOCALS~1\Temp/ccS0baaa.o:all.cpp:(.text+0x24): undefined reference to `operator new(unsigned int)'
collect2: ld returned 1 exit statusКстати мой Makefile нормально составлен?
P.S. ща пока что только начал изучать сборку, поэтому файлы еще не связаны друг с другом логикой =)