致命错误LNK1120

时间:2014-09-16 19:04:06

标签: c++ fatal-error externals

所以我已经检查了一些有关此错误的其他帖子,但我似乎无法在自己的代码中追查问题。我正在处理三个单独的文件。当我在一个文件中调用函数时,它们会导致错误。据我所知,一切都被格式化并正确引用。

核心代码

#include <iostream>
#include <cstdlib> 
#include <ctime> 
#include <string>

//Task 1: Install Libaries and Get the GUI Running
#include "gui.h"

//Task 4: Implement the game engine
#include "engine.h"

//Include global constants
#include "constants.h"

using namespace std;

int main(int argc, char *argv[]){

//Seed random number generator
srand((unsigned)time(0)); 

//Task 2: Declare and Intialize Player Properties
int playerX = 0;
int playerY = 0;
int playerState = 0;

//Task 3: Declare and Initialize Background Properties'
int elementsX [MAX_NUM_ELEMENTS];
int elementsY [MAX_NUM_ELEMENTS];
int numElements = MAX_NUM_ELEMENTS;

//Initialize the game's data source
string gameFile("./data/background.txt");


//Task 5: Load Data from a file'
//loadBackground(gameFile,numElements,elementsX,elementsY);

//Task 6: Randomize Player Sprite Appearance
randomPlayer(playerX,playerY,playerState,MAX_POS_X,MAX_POS_Y,MAX_PLAYER_STATE);

//Construct GUI
GUI gui;

//Initialize Termination Criteria
bool quit = false;

//While the user hasn't quit
while(quit == false){

    //GUI waits for mouse events
    while(gui.observeEvent()){

        //GUI transmits quit event
        if(gui.quitGame()){
            quit=true;
        }
    }
    //Render Game Data
    gui.displayGameState(playerX,playerY,playerState,numElements,elementsX,elementsY);
}

//Return
return 0;

}

发动机:

#include <fstream>
#include <string>
#include "engine.h"
#include "constants.h"
#include <ctime>

using namespace std;

void loadBackground(string path, int numElements, int posX[], int posY[]){

fstream fin;
fin.open(path,ios::in);
int lineSize = 0;

fin >> numElements;
for(int i=0; i<numElements; i++){
    fin >> posX[i];
    fin >> posY[i];
}
fin.close();
}


void randomPlayer(int posX, int posY, int state, int MAX_POS_X,int MAX_POS_Y,int MAX_PLAYER_STATE){
srand((unsigned)time(0));
posX = rand()%MAX_POS_X;
posY = rand()%MAX_POS_Y;
state = rand()%MAX_PLAYER_STATE-1;

}

当调用Engine中的两个函数中的任何一个时,会发生此问题。我在Surface Pro 3上使用Visual Studio 2012。

这也是完整的构建错误:

1>------ Build started: Project: Hmwk.1.Assignment, Configuration: Debug Win32 ------
1>hmwk.1.obj : error LNK2019: unresolved external symbol "void __cdecl loadBackground(class     std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int &,int *     const,int * const)" (?loadBackground@@YAXV?$basic_string@DU?$char_traits@D@std@@V?    $allocator@D@2@@std@@AAHQAH2@Z) referenced in function _SDL_main
1>hmwk.1.obj : error LNK2019: unresolved external symbol "void __cdecl randomPlayer(int &,int     &,int &,int,int,int)" (?randomPlayer@@YAXAAH00HHH@Z) referenced in function _SDL_main
1>C:\Users\tmars_000\Desktop\Fall 2014\Intro to Game     Prog\Hmwk.1.Released\Debug\Hmwk.1.Assignment.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

engine.h

#ifndef ENGINE_H
#define ENGINE_H

#include <string>

using namespace std;

void loadBackground(string, int &, int[], int[]);
void randomPlayer(int &, int &, int &, int, int, int);

#endif

0 个答案:

没有答案