【发布时间】:2015-11-21 02:53:31
【问题描述】:
我浏览了很多关于此的问题,但似乎没有人遇到与我完全相同的问题。确切的错误信息是:
g++ -Wall -o Main Main.cpp
Undefined symbols for architecture x86_64:
"World::World(int)", referenced from:
_main in Main-vskeMa.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
可能是命名空间问题吗?正如您在上面看到的,我正在使用 g++ 在命令行上进行编译。以下是相关文件:
main.cpp
#include <iostream>
#include <cstdlib>
#include "World.h"
using namespace std;
int main()
{
cout << "-- Program Started --" << endl;
World theWorld (4);
return 0;
}
世界.h
#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
#include <time.h>
#include <stdlib.h>
#include "Biome.h"
#define TILE_SIZE 10
#define WORLD_DIM 10
#define NUM_BIOMES 5
using namespace std;
class World{
public:
World(int);
protected:
Biome* biomeArray[WORLD_DIM][WORLD_DIM];
};
世界.cpp
#include "World.h"
using namespace std;
/* functions */
/* constructor */
World::World(int numCities){
cout << "creating the world with " << numCities << " cities...";
for (int i=0; i<WORLD_DIM; i++){
for (int j=0; j<WORLD_DIM; j++){
int random = rand() % NUM_BIOMES;
Biome* aBiome = createBiome(random);
cout << aBiome->name << endl;
}
}
cout << "done!" << endl;
}
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: c++ macos linker namespaces