2014-03-30 2 views
1

SDL을 사용하여이 코드를 작성했지만 약간의 오류가 있습니다.해결 오류 LNK2019; 해결되지 않은 외부 기호

이 내가 할 수 있지만, 아무것도 변경되지 모든 일을 한 코드

#include <SDL.h> 
#include <SDL_image.h> 
#include <SDL_ttf.h> 
#include <SDL_mixer.h> 
#include <fstream> 
#include <iostream> 
using namespace std; 


/////////////////////////////////// functions & global variable //////////////////////////////// 

SDL_Window* window; 
SDL_Renderer* renderer; 
SDL_Color textColor; 
TTF_Font* font; 
SDL_Surface* surface=SDL_GetWindowSurface(window); 
SDL_Event event; 




SDL_Texture* LoadTexture(char* path) 
{ 
    SDL_Surface* surface = IMG_Load(path); 
    SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer,surface); 
    SDL_FreeSurface(surface); 
    return texture; 
} 



///////////////////////////////////// Cell ///////////////////////////////////// 

class Cell 
{ 
private: 
    char num; 

public: 
    Cell(); 
    Cell(int ,int ,char); 
    char * img; 
    pair <int ,int> cor; 
    int flag; 
    int size; 
    void display(); 
    bool indomain(int ,int); 
}; 


Cell :: Cell(int x ,int y ,char n){ 
    num=n; 
    cor.first=x; 
    cor.second=y; 
    size=40; 
    flag=0; 
    if (num == '#') 
     img="0.png"; 
    else if (num == '!') 
     img="1.png"; 
    else 
     img="street.png"; 
} 

bool Cell :: indomain(int x ,int y){ 
    if ((cor.first<=x && x<=cor.first+size) && (cor.second<=y && y<=cor.second+size)) 
     return true; 
    return false; 
} 


void Cell :: display(){ 
    SDL_Rect rect; 
    rect.x=cor.first; 
    rect.y=cor.second; 
    SDL_Texture* texture = LoadTexture(img); 
    SDL_RenderCopy(renderer,texture,NULL,&rect); 
} 


//////////////////////////////////////////// Tower ///////////////////////////////////////// 

class Tower 
{ 
public: 
    Tower(); 
    Tower(int ,int ,int ,int ,char* ,int ,int ,int); 
    ~Tower(); 
    int price; 
    int up_cost; 
    char * img; 
    int power; 
    int domain; 
    int grade; 
    int index; 
    pair <int ,int> cor; 
    void upgrade(); 
    void display(); 
    bool mark(int ,int); 
}; 


Tower :: Tower(int pr ,int co ,int pow ,int dom ,char* im ,int x ,int y ,int i){ 
    price=pr; 
    up_cost=co; 
    power=pow; 
    domain=dom; 
    img=im; 
    cor.first=x; 
    cor.second=y; 
    grade=1; 
    index=i; 
} 

void Tower :: upgrade(){ 
    if (grade<5) 
    { 
     grade+=1; 
     power*=2; 
     domain*=1.2; 
     price*=1.2; 
    } 
} 

void Tower :: display(){ 
    SDL_Rect rect; 
    rect.x=cor.first; 
    rect.y=cor.second; 
    SDL_Texture* texture = LoadTexture(img); 
    SDL_RenderCopy(renderer,texture,NULL,&rect); 
} 

bool Tower :: mark(int x, int y){ 
    if ((cor.first<=x && x<=cor.first+40) && (cor.second<=y && x<=cor.second+80)) 
     return true; 
    return false; 
} 





//////////////////////////////// Enemy ////////////////////////////////////// 

class Enemy 
{ 
public: 
    Enemy(); 
    Enemy(int ,char* ,int ,int ,int); 
    ~Enemy(); 
    char * img; 
    int health; 
    int cellNum; 
    int index; 
    pair <int ,int> cor; 
    bool live(); 
    void display(); 
    void damge(Tower t); 
}; 


Enemy :: Enemy(int h ,char* im ,int x ,int y ,int i){ 
    health=h; 
    img=im; 
    cor.first=x; 
    cor.second=y; 
    cellNum=0; 
    index=i; 
} 

bool Enemy :: live(){ 
    if (health>0) 
     return true; 
    return false; 
} 

void Enemy :: damge(Tower t){ 
    health-=t.power; 
} 

void Enemy :: display(){ 
    SDL_Rect rect; 
    rect.x=cor.first; 
rect.y=cor.second; 
SDL_Texture* texture = LoadTexture(img); 
SDL_RenderCopy(renderer,texture,NULL,&rect); 
} 




///////////////////////////////////////////// Map /////////////////////////////////////// 

class Map 
{ 
private: 
char * file; 
int len; 

public: 
Map(); 
Map(char* ,int); 
~Map(); 
Cell map[15][20]; 
pair <int ,int> * path; 
void display(); 
void put_tower(Tower ,Cell); 
void put_enemy(Enemy ,Cell); 
void remove(Cell); 
void enemyMove(Enemy); 
void pathFinder(int); 
}; 


Map :: Map(char * f ,int l){ 
file=f; 
len=l; 
ifstream infile; 
infile.open(file); 
char * line=new char; 
for (int i=0;i<15;i++) 
{ 
    infile >> line; 
    for (int j=0;j<20;j++) 
     map[i][j]=Cell(j*40 ,i*40 ,line[j]); 
} 
this->pathFinder(len); 
} 

void Map :: put_enemy(Enemy e ,Cell c){ 
e.cor=c.cor; 
e.display(); 
} 

void Map :: put_tower(Tower t ,Cell c){ 
t.cor=c.cor; 
t.display(); 
} 

void Map :: remove(Cell c){ 
c.display(); 
} 

void Map :: enemyMove(Enemy e){ 
e.cellNum+=1; 
e.cor=path[e.cellNum]; 
} 

void Map :: pathFinder(int l){ 
path=new pair<int ,int> [l]; 
ifstream infile; 
infile.open(file); 
char ** lines=new char* [15]; 
for (int i=0;i<15;i++) 
    infile >> lines[i]; 
for (int i=0;i<20;i++) 
    if (lines[0][i]=='0') 
    { 
     path[0]=make_pair(0,i); 
     break; 
    } 
int x=0; 
int y=path[0].second; 
int ord=48; 
for (int i=1;i<l;i++) 
{ 
    if (int(lines[x-1][y])==((ord-47)%10)+48) 
     x-=1; 
    else if (int(lines[x+1][y])==((ord-47)%10)+48) 
     x+=1; 
    else if (int(lines[x][y-1])==((ord-47)%10)+48) 
     y-=1; 
    else if (int(lines[x][y+1])==((ord-47)%10)+48) 
     y+=1; 
    path[i]=make_pair(x,y); 
    ord+=1; 
} 
} 

void Map :: display(){ 
for (int i=0;i<15;i++) 
    for (int j=0;j<20;j++) 
     map[i][j].display(); 
} 





//////////////////////////////////////////////////// Game //////////////////////////////////////// 

class Game 
{ 
private: 
int health; 
int money; 
int score; 
int step; 

public: 
Game(int ,int); 
~Game(); 
bool End; 
int enemyNum; 
int towerNum; 
Enemy enemys[20]; 
Tower towers[50]; 
int getHealth(); 
int getMoney(); 
int getScore(); 
int getStep(); 
void setHealth(int); 
void setMoney(int); 
void setScore(int); 
void setStep(int); 
void distroy_enemy(Enemy ,Cell); 
void distroy_tower(Tower ,Cell); 
void shooting(Tower); 
void drag_drop(Tower); 
void upgradeTower(Tower); 
void buyTower(Tower); 
void sellTower(Tower ,Cell); 
void display(Map); 
void displayMenu(); 
void endDisplay(); 
bool checkEnd(); 
void animation(); 
}; 

Game :: Game(int h ,int m){ 
health=h; 
money=m; 
step=1; 
score=0; 
enemyNum=0; 
towerNum=0; 
End=false; 
} 

int Game :: getHealth(){ 
return health; 
} 
int Game :: getMoney(){ 
return money; 
} 

int Game :: getScore(){ 
return score; 
} 

int Game :: getStep(){ 
return step; 
} 

void Game :: setHealth(int h){ 
health=h; 
} 

void Game :: setMoney(int m){ 
money=m; 
} 

void Game :: setScore(int s){ 
score=s; 
} 

void Game :: setStep (int s){ 
step=s; 
} 

void Game :: distroy_enemy(Enemy e,Cell c){ 
for (int i=e.index;i<enemyNum-1;i++) 
    enemys[i]=enemys[i+1]; 
enemyNum-=1; 
c.display(); 
} 

void Game :: distroy_tower(Tower t ,Cell c){ 
for (int i=t.index;i<towerNum-1;i++) 
    towers[i]=towers[i+1]; 
towerNum-=1; 
c.display(); 
} 

void Game :: shooting(Tower t){ 
for(int i=0;i<enemyNum;i++) 
{ 
    if (sqrt(pow(enemys[i].cor.first,2)+pow(enemys[i].cor.second,2)) <= t.domain) 
     enemys[i].health-=t.power; 
} 
} 

void Game :: upgradeTower(Tower t){ 
t.upgrade(); 
money-=t.up_cost; 
} 

void Game :: buyTower(Tower t){ 
money-=t.price; 
towers[towerNum]=t; 
towerNum+=1; 
t.display(); 
} 

void Game :: sellTower(Tower t ,Cell c){ 
distroy_tower(t,c); 
money+=t.price/2; 
} 

void Game :: endDisplay(){ 
End=true; 
SDL_FillRect(surface,&surface->clip_rect,SDL_MapRGB(surface->format,0XFF,0XFF,0XFF)); 
SDL_Surface* text; 
font=TTF_OpenFont("AV.TTF",40); 
textColor.b=20; 
textColor.g=10; 
textColor.r=0; 
if (health<=0) 
{ 
    text=TTF_RenderText_Solid(font ,"You lose" ,textColor); 
} 
else if (health>0) 
{ 
    text=TTF_RenderText_Solid(font ,"Complete the mission" ,textColor); 
} 
SDL_Rect rect; 
rect.x=300; 
rect.y=300; 
SDL_BlitSurface(text,NULL,surface,&rect); 
} 

bool Game :: checkEnd(){ 
if (health<=0 || step==20) 
    return true; 
return false; 
}  

void Game :: displayMenu(){ 
SDL_Rect rect; 
rect.x=800; 
rect.y=0; 
SDL_Texture* texture = LoadTexture("menu.png"); 
SDL_RenderCopy(renderer,texture,NULL,&rect); 
} 


void Game :: display(Map m){ 
m.display(); 
for (int i=0;i<towerNum;i++) 
    towers[i].display(); 
for (int i=0;i<enemyNum;i++) 
    enemys[i].display(); 
this->displayMenu(); 
/////////// ttf 
} 

void Game :: animation(){ 
SDL_Rect Lrect; 
Lrect.x=83; 
Lrect.y=0; 
SDL_Rect Rrect; 
Rrect.x=915; 
Rrect.y=0; 
SDL_Texture* leftpic = LoadTexture("left.png"); 
SDL_Texture* rightpic = LoadTexture("right.png"); 
for (int i=0;i<12;i++) 
{ 
    SDL_RenderCopy(renderer,leftpic,NULL,&Lrect); 
    SDL_RenderCopy(renderer,rightpic,NULL,&Rrect); 
    Rrect.x-=20; 
    Lrect.x+=60; 
    SDL_RendererFlip(); 
    SDL_Delay(300); 
} 
} 





////////////////////////////////////////////////////////////// main ////////////////////////////////////////////////////////////////////// 


int main() 
{ 
window=SDL_CreateWindow("Frontline Defence",SDL_WINDOWPOS_UNDEFINED, 
    SDL_WINDOWPOS_UNDEFINED,940,600,SDL_WINDOW_SHOWN); 
Game game(1000,500); 
Map map("map.txt",30); 
while (!game.checkEnd()) 
    { 
     if (SDL_PollEvent(&event)) 
     { 
      if (event.type == SDL_QUIT) 
       return 0; 
      if (event.type == SDL_MOUSEBUTTONDOWN) 
      { 
       SDL_Delay(3000); 
      } 
     } 
    } 
    game.endDisplay(); 
    return 0; 
} 

입니다!

Error 12 error LNK1120: 8 unresolved externals C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\Debug\ConsoleApplication1.exe ConsoleApplication1 
Error 4 error LNK2019: unresolved external symbol "public: __thiscall Cell::Cell(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall Map::Map(char *,int)" ([email protected]@[email protected]@Z) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 8 error LNK2019: unresolved external symbol "public: __thiscall Enemy::~Enemy(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall Game::Game(int,int)" ([email protected]@[email protected]@Z) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 7 error LNK2019: unresolved external symbol "public: __thiscall Enemy::Enemy(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall Game::Game(int,int)" ([email protected]@[email protected]@Z) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 10 error LNK2019: unresolved external symbol "public: __thiscall Game::~Game(void)" ([email protected]@[email protected]) referenced in function "int __cdecl SDL_main(void)" ([email protected]@YAHXZ) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 9 error LNK2019: unresolved external symbol "public: __thiscall Map::~Map(void)" ([email protected]@[email protected]) referenced in function "int __cdecl SDL_main(void)" ([email protected]@YAHXZ) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 6 error LNK2019: unresolved external symbol "public: __thiscall Tower::~Tower(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall Game::Game(int,int)" ([email protected]@[email protected]@Z) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 5 error LNK2019: unresolved external symbol "public: __thiscall Tower::Tower(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall Game::Game(int,int)" ([email protected]@[email protected]@Z) C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\classes.obj ConsoleApplication1 
Error 11 error LNK2019: unresolved external symbol _SDL_main referenced in function _main C:\Users\FUJITSU\Desktop\frontline defence\project\ConsoleApplication1\ConsoleApplication1\SDL2main.lib(SDL_windows_main.obj) ConsoleApplication1 
+1

링커에서는 이러한 함수에 대한 구현이 없다는 것을 알려줍니다. 예를 들어'Cell :: Cell() {/ * 여기에 뭔가가있을 것}'과'Enemy :: ~ Enemy() {/ * something goes here * /}'등이 필요합니다. '_SDL_main' - 이것은 라이브러리 또는 다른 설정 문제 일 수 있습니다. –

+0

나는 네가 한 말대로 해냈다. 그러나 새로운 문제가 있습니다. 코드를 컴파일 할 때 프로그램이 중단되고이 메시지 상자는 "ConsoleApplication1.exe의 0x00D02601에서 처리되지 않은 예외 : 0xC0000005 : 0xCECDCDCD 위치 쓰기 액세스 위반"을 엽니 다. 지금 어떻게해야합니까? – rkarami

답변

2

당신은가 있어요 : 내가 주 파일 및 기타 여러 가지 방법으로 코드의 모든 부분을 입력, 라이브러리를 비롯하여 해봤지만

도움이되지 않았다 다음은 오류입니다 링커 오류가 생성자와 소멸자를 참조하는 이유는 이들 함수에 대한 구현을 제공하지 않았기 때문입니다 (Michael Burr가 주석에서 지적한 것처럼). int main(int argc, char* argv[]) 당신은 또한 링커에 대한 입력에 SDL2main.lib을 가지고 있는지 확인하십시오 main 함수는 특정 서명이 필요하기 때문에

unresolved external symbol _SDL_main referenced in function _main입니다.

마지막으로 코드 예제에 포함되지 않은 곳을 만들지 않는 한 renderer을 만들지 않으므로 main에 SDL_Window를 만든 후에 SDL_CreateRenderer()에 대한 호출을 추가해야합니다.

+0

나는 네가 한 말대로 해냈다. 그러나 새로운 문제가 있습니다. 코드를 컴파일 할 때 프로그램이 중단되고이 메시지 상자는 "ConsoleApplication1.exe의 0x00D02601에서 처리되지 않은 예외 : 0xC0000005 : 0xCECDCDCD 위치 쓰기 액세스 위반"을 엽니 다. 지금 어떻게해야합니까? – rkarami

관련 문제