gpt4 book ai didi

c - Xcode Mach-O 链接器 ID 错误

转载 作者:行者123 更新时间:2023-11-30 19:30:11 25 4
gpt4 key购买 nike

我是 Xcode 新手,我正在尝试使用 Xcode 学习 C 语言。当我尝试运行它时,出现错误 apple macho-o linker and link command failed with exit code 1。我不明白有关堆栈溢出的有关删除 Pod 或库路径的其他答案。请帮助并告诉我修复此错误的每一步。{编辑}抱歉,信息非常少。这是代码和错误

The Code which was Simple

Click here for The error which is disturbing

    Ld /Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Products/Debug/Education normal x86_64
cd /Users/pratikkadam/Documents/GitHub/Education
export MACOSX_DEPLOYMENT_TARGET=10.13
/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.13.sdk -L/Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Products/Debug -F/Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Products/Debug -filelist /Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Intermediates.noindex/Education.build/Debug/Education.build/Objects-normal/x86_64/Education.LinkFileList -Xlinker -rpath -Xlinker @executable_path/../Frameworks -Xlinker -rpath -Xlinker @loader_path/../Frameworks -mmacosx-version-min=10.13 -Xlinker -object_path_lto -Xlinker /Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Intermediates.noindex/Education.build/Debug/Education.build/Objects-normal/x86_64/Education_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift_static/macosx -Xlinker -force_load_swift_libs -lc++ -framework Foundation -Xlinker -add_ast_path -Xlinker /Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Intermediates.noindex/Education.build/Debug/Education.build/Objects-normal/x86_64/Education.swiftmodule -Xlinker -dependency_info -Xlinker /Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Intermediates.noindex/Education.build/Debug/Education.build/Objects-normal/x86_64/Education_dependency_info.dat -o /Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Products/Debug/Education

duplicate symbol _main in:
/Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Intermediates.noindex/Education.build/Debug/Education.build/Objects-normal/x86_64/Example.o
/Users/pratikkadam/Library/Developer/Xcode/DerivedData/Education-dhazvkwqsporefgyqgfaxhlzhscj/Build/Intermediates.noindex/Education.build/Debug/Education.build/Objects-normal/x86_64/main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

C语言命令行项目的XCode标准模板包含main.c,其中包含示例实现:

#include <stdio.h>
int main(int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
return 0;
}

您还没有向我们展示您的项目文件结构,但我假设您没有从项目中删除 main.c 。您的屏幕截图表明您创建的 Example.c 还包含 main() 函数定义。在C语言中,所有函数都位于同一平面全局级别(没有命名空间和类),因此链接器(制作可执行文件的最后阶段)提示重复的_main 符号。要解决此问题,您应该:

  1. 将 main 函数中的测试代码从 Example.c 移至 main.c 中。并删除 Example.c 任何内容。
  2. Example.c 中的函数重命名为 main() 之外的其他内容,并在 int main(int argc , const char * argv[])main.c 中。

关于c - Xcode Mach-O 链接器 ID 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51497563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com