【问题标题】:c++ Mac Xcode: Undefined symbols for architecture x86_64:c ++ Mac Xcode:架构x86_64的未定义符号:
【发布时间】:2016-03-25 08:17:34
【问题描述】:

我在 Mac 上的 Xcode 中用 c++ 运行以下代码

int fibo(int x)
{
      if (x==1||x==2)
          return 1;
          else
              return fibo(x-1)+fibo(x-2);
}

收到这个错误不知道为什么。

undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人可以帮我吗?

【问题讨论】:

    标签: c++ ios xcode macos


    【解决方案1】:

    您需要定义一个main 函数。这是第一个被调用来“启动”你的程序的函数。

    将此添加到您的文件中:

    int main()
    {
        fibo(10);  // calls your function with
    }
    

    【讨论】:

    • 我这样做了,但是在这样做之后,它说“x”未声明,我该怎么办??
    • 看起来 x 没有定义。我怀疑你的意思是 n。
    • 嗯不,我不这么认为,我给 x 作为输入,所以它应该已经知道函数
    【解决方案2】:

    你应该实现 main() 函数。

    main函数在程序初始化后被调用 具有静态存储持续时间的非本地对象。它是 在托管中执行的程序的指定入口点 环境(即,具有操作系统)。入口指向 独立程序(引导加载程序、操作系统内核等)是 实现定义。 http://en.cppreference.com/w/cpp/language/main_function

    #include <iostream> // for std::cout
    int fibo(int x)
    {
          if (x==1||x==2)
              return 1;
              else
                  return fibo(x-1)+fibo(x-2);
    }
    
    int main() 
    {
          int x = 1;
          int result = fibo(x);
          std::cout << "Result: " << x; // Printing result
          return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-07
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      • 2021-03-12
      • 2016-11-07
      • 2015-11-24
      相关资源
      最近更新 更多