저는 SDL에 관한 모든 것을 배웠습니다. 지금까지 모든 것이 잘 작동했습니다.SDL, 헤더 및 이상한 오류 ..?
Undefined symbols for architecture x86_64:
"Tile::draw(SDL_Surface*)", referenced from:
_SDL_main in ccTWWnIW.o
"Tile::update()", referencedfrom:
_SDL_main in ccTWWnIW.o
"Tile::Tile(int)", referenced from:
_SDL_main in ccTWWnIW.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
무엇에 대한 이상한 것은 단지 내 "player.cpp"코드의 비트에서 "level.h"헤더를 포함 할 때 발생한다는 것입니다 : 내 코드를 컴파일 할 때마다, 나는 다음과 같은 오류가 발생합니다 .. 내 메인 프로그램에서 "level.h"를 포함하는 동안 컴파일러를 전혀 설정하지 않습니다. 필자는 주 프로그램 인 "level.h"에 정의 된 클래스를 사용하여 타일을 인스턴스화하고,이를 업데이트하고, 화면에 blit하고, "player.cpp"에서 충돌을 확인합니다. 나는 "level.h"에 정의 된 컴포넌트를 사용하는 "player.cpp"의 모든 부분을 주석 처리했으며 여전히 컴파일러 오류가 발생했습니다. 나는 "player.cpp"에서와 같은 SDL 헤더를 포함하고 컴파일러에서 플래그를 적절하게 설정했기 때문에 "x86 : 64 비트 아키텍처에서 발견되지 않은"ld : 심볼이 왜 보이지 않습니다. . 에러 메시지에서 참조하는 "level.cpp"의
비트 :
#include "SDL.h"
#include "SDL_image.h"
#include <iostream>
#include "Variables.h"
#include <cstdlib>
#include "level.h"
class Tile{
public:
int damage;
int velocity;
bool solid;
SDL_Rect position;
SDL_Rect crop;
SDL_Surface* image;
Tile(int type);
~Tile();
bool update();
void draw(SDL_Surface* target);
};
...
Tile::Tile(int type){
if(type == 0){
damage = 0;
velocity = 20;
solid = true;
position.x = 600;
position.y = rand() % 500;
SDL_Surface* temp_image = IMG_Load_RW(SDL_RWFromFile("spritesheet.png", "rb"), 1);
image = SDL_DisplayFormatAlpha(temp_image);
SDL_FreeSurface(temp_image);
crop.x = 0;
crop.y = 0;
crop.w = 50;
crop.h = 50;
}
}
...
bool Tile::update(){
position.x = position.x - velocity;
if(position.x <= 0) {
position.x = 700;
position.y = rand()%500;
}
else return 0;
}
...
void Tile::draw(SDL_Surface* target){
SDL_BlitSurface(image, &crop, target, &position);
}
코딩 스타일이 쓰레기라는 것을 알고 있습니다. 이것은 내가 SDL을 배우고 배우는 것입니다.
한 가지 더, 모든 포함은 .h 파일에 있어야하며 cpp는 자신의 .h 파일 만 포함해야합니다. –
나는 모든 include가 h 파일 (예 : #include "myfile.cpp"가 아니라 #include "myfile.h")을 포함해야 함을 의미한다고 생각하고 있습니다. #include는 _in_ .h 파일이어야합니다. 일반적으로 가능한 한 선언을 전달하는 것이 좋습니다. 그렇지 않으면 #include하십시오. – TomD
cpp에 포함하는 것이 더 좋은 예를 들어 줄 수 있습니까? –