Ld /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug/c normal x86_64
cd /Users/ashutoshagarwal/Desktop/c
setenv MACOSX_DEPLOYMENT_TARGET 10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /MacOSX10.9.sdk -L / Users / ashutoshagarwal / Library / Developer / Xcode / DerivedData / c-cnyfflmvjyaashaoduqduqqsfegd / Build / Products / Debug -F / Users / ashutoshagarwal / Library / Developer / Xcode / DerivedData / c-cnyfflmvjyaashaoduqduqqsfegd / Build / Products / Debug -filelist /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Intermediates/c.build/Debug/c.build/Objects-normal/x86_64/c.LinkFileList -mmacosx-version -min = 10.9 -framework Foundation -Xlinker -dependency_info -Xlinker /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Intermediates/c.build/Debug/c.build/Objects-normal/x86_64/ c_dependency_info.dat -o / Users / ashutoshagarwal / Library / Developer / Xcode / DerivedData / c-cnyfflmvjyaashaoduqduqqsfegd / Build / Products / Debug / c
Undefined symbols for architecture x86_64:
"_add_history", referenced from:
_main in main.o
"_readline", referenced from:
_main in main.o
_source in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我得到Apple-Mach-O Linker(Id)错误,已经发送了几个小时试图解决这个问题,不知道该做什么。
答案 0 :(得分:2)
看起来您正在使用GNU readline和GNU历史库,默认情况下,它们位于libedit.dylib
的mac上:
$ nm /usr/lib/libedit.dylib | fgrep readline
0000000000009899 T _readline
000000000001f444 D _readline_echoing_p
000000000001f400 D _rl_readline_name
000000000001f3f8 D _rl_readline_version
$ nm /usr/lib/libedit.dylib | fgrep add_history
000000000000acbc T _add_history
(T
表示该符号位于图书馆的文字部分中。)
因此,您需要将-ledit
添加到链接器命令行。如果您使用的是Xcode,则可以将libedit.dylib
添加到要链接的库列表中,或者如果您使用的是make
,那么您可能需要编辑LIBS
中的Makefile
变量}}
答案 1 :(得分:0)
错误消息:
Undefined symbols for architecture x86_64: "_add_history", referenced from: _main in main.o
"_readline", referenced from: _main in main.o _source in main.o ld: symbol(s) not found for
architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)'
告诉您链接器找不到符号readline
和add_history
。在没有看到源代码以及精确的链接器和编译器命令行的情况下,很难推测出确切的原因。可能的原因是您无法与外部库或程序的其他模块链接。