【发布时间】:2022-01-14 20:14:31
【问题描述】:
在我编写两个函数 xxxx 作为 uni 工作的一部分时发生以下错误。我使用的 IDE 是 Visual Studio Code。
问题是当我尝试编译文件夹code/myIO中的单个文件时,它抛出了一个错误:
(我已经用 ($) 替换了文件夹的路径。我保证问题不存在)
cd ($) && clang++ r.cpp -o ($)/r -D LOCAL -Wall -O2 -fsanitize=undefined
Undefined symbols for architecture arm64:
"_Tp::INT", referenced from:
split(char const*, _Tp*) in r-ebf422.o
"_Tp::fmt", referenced from:
split(char const*, _Tp*) in r-ebf422.o
"_Tp::str", referenced from:
split(char const*, _Tp*) in r-ebf422.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
而且,当我尝试链接一些文件时,发生了类似的错误。
clang++ -shared -o libmystdio.so myscanf.o myprintf.o
Undefined symbols for architecture arm64:
"_Tp::INT", referenced from:
split(char const*, _Tp*) in myscanf.o
split(char const*, _Tp*) in myprintf.o
"_Tp::fmt", referenced from:
split(char const*, _Tp*) in myscanf.o
split(char const*, _Tp*) in myprintf.o
"_Tp::str", referenced from:
split(char const*, _Tp*) in myscanf.o
split(char const*, _Tp*) in myprintf.o
"_Tp::LONG", referenced from:
split(char const*, _Tp*) in myscanf.o
split(char const*, _Tp*) in myprintf.o
"_Tp::LONGLONG", referenced from:
split(char const*, _Tp*) in myscanf.o
split(char const*, _Tp*) in myprintf.o
"_out_buf", referenced from:
myprintf(char const*, ...) in myprintf.o
"_out_idx", referenced from:
myprintf(char const*, ...) in myprintf.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libmystdio.so] Error 1
如果你想知道我写了什么,please click here。不过还没写完,不知道你会不会有兴趣...(我做了几个cmet,大部分都是中文的,给我的队友看)
而且,文件夹 code 中的文件不受影响。可以正常编译运行。只有code/myIO文件夹出错了。
这是我的 clang++ 版本:
clang++ -v
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
提前感谢您的帮助!
【问题讨论】:
-
这能回答你的问题吗? What is an undefined reference/unresolved external symbol error and how do I fix it? 如果没有,请更新您的问题,详细说明您的问题与其他问题所涵盖的问题不同。 minimal reproducible example 会有所帮助,只要确保它重现错误消息并附上您认为错误消息错误的解释。