【问题标题】:Undefined symbols for architecture x86_64; ld: symbol(s) not found for architecture x86_64 [duplicate]架构 x86_64 的未定义符号; ld:未找到架构 x86_64 的符号 [重复]
【发布时间】: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


    【解决方案1】:

    可能是命名空间问题吗?

    没有。你甚至没有使用命名空间。

    正如你在上面看到的,我正在使用 g++ 在命令行上编译。

    不,你不是。你没有编译或链接World.cpp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-18
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 2016-12-09
      • 2018-02-20
      相关资源
      最近更新 更多