【问题标题】:Undefined symbols for architecture arm for建筑手臂的未定义符号
【发布时间】:2022-12-16 01:49:06
【问题描述】:

我是 C++ 的新手,正在尝试使用 get_string,但我不确定我写错了什么导致了错误。

我的代码如下:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
   string name = get_string("What's your name? ");
   printf("hello, %s\n", name);
}

它一直说以下错误:

Undefined symbols for architecture arm64:
  "_get_string", referenced from:
      _main in hello-890d43.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello] Error 1

有谁知道我做错了什么?

我希望代码接受输入并打印出你好,(你的输入)。

【问题讨论】:

  • 请在本网站搜索c++ Undefined symbols for architecture arm64:。这个问题已经在这里被问过和回答过好几次了。请总是在发布新问题之前彻底搜索网站。
  • cs50 不是 C 而不是 C++ 吗?

标签: c++ printf cs50 getstring


【解决方案1】:

尝试使用 cs50 时,同样的事情发生在我身上C我本地 Mac 上带有 M1 芯片的库。

即使按照此处所述安装库之后:https://cs50.readthedocs.io/libraries/cs50/c/ 它仍然没有用。

问题出在默认情况下make 命令不包含链接命令。

假设你的源文件被命名为hello.c而不是仅仅做:

make hello

您必须在终端中输入以下内容才能编译:

clang hello.c -o hello -lcs50

之后,当运行可执行文件时,它按预期工作:

./hello

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2015-04-29
    相关资源
    最近更新 更多