如何在Xcode 6中向C项目添加库

我对此很新,但我会尝试提供尽可能详细的信息.我最初尝试提供截图,但是如果没有10个声誉我就不能这样做,所以我要将错误消息复制粘贴为底部的文本.

我正在研究哈佛CS50问题集1.作为其中的一部分,您应该使用为课程作业提供的库.它有两个文件:cs50.h和cs50.c

我已经下载了这些文件,最初我收到了一个错误,我发现这是因为它是一个32位的库而我正在运行64位.通过转到项目>我改变了引用库的位置.构建阶段> Link Binary with Libraries,正如我在网上发现的那样,如果我在这里处理它,Xcode将负责确保正确的架构等(32位与64位).

现在我收到黄色错误,指出它在我尝试构建时传递这些文件,因为它是一个意外的文件类型.

我发现建议使用文件检查器来查看类型,并且我通过各种可用的C文件类型进行了旋转,看看它是否可以解决任何问题而我没有运气.

我还发现了围绕这个的另一个对话,表明将体系结构类型更新为Universal选项会有所帮助,但这并没有改变任何东西.

此时,我无法通过Google搜索找到与我的问题相关的任何内容.

我也意识到,由于我的新意,我刚刚做了一些非常愚蠢的事情,但我觉得我花了很多时间来解决这个问题.我感谢任何帮助.

warning: skipping file '/Users/matthewcanova/Documents/include/cs50.h' (unexpected file type 'sourcecode.c.h' in Frameworks & Libraries build phase)
warning: skipping file '/Users/matthewcanova/Documents/include/cs50.c' (unexpected file type 'sourcecode.c.c' in Frameworks & Libraries build phase)
Warning: skipping file '/Users/matthewcanova/Documents/include/cs50.h' (unexpected file type 'sourcecode.c.h' in Frameworks & Libraries build phase)
Warning: skipping file '/Users/matthewcanova/Documents/include/cs50.c' (unexpected file type 'sourcecode.c.c' in Frameworks & Libraries build phase)

Ld /Users/matthewcanova/Library/Developer/Xcode/DerivedData/Problem_Set_1-    hkvfcrlbsfojiafrcnafkxgoannu/Build/Products/Debug/Problem\ Set\ 1 normal x86_64
cd "/Users/matthewcanova/Documents/Problem Set 1"
export 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/matthewcanova/Library/Developer/Xcode/DerivedData/Problem_Set_1-hkvfcrlbsfojiafrcnafkxgoannu/Build/Products/Debug -F/Users/matthewcanova/Library/Developer/Xcode/DerivedData/Problem_Set_1-hkvfcrlbsfojiafrcnafkxgoannu/Build/Products/Debug -filelist /Users/matthewcanova/Library/Developer/Xcode/DerivedData/Problem_Set_1-hkvfcrlbsfojiafrcnafkxgoannu/Build/Intermediates/Problem\ Set\ 1.build/Debug/Problem\ Set\ 1.build/Objects-normal/x86_64/Problem\ Set\ 1.LinkFileList -mmacosx-version-min=10.9 -Xlinker -dependency_info -Xlinker /Users/matthewcanova/Library/Developer/Xcode/DerivedData/Problem_Set_1-hkvfcrlbsfojiafrcnafkxgoannu/Build/Intermediates/Problem\ Set\ 1.build/Debug/Problem\ Set\ 1.build/Objects-normal/x86_64/Problem\ Set\ 1_dependency_info.dat -o /Users/matthewcanova/Library/Developer/Xcode/DerivedData/Problem_Set_1-hkvfcrlbsfojiafrcnafkxgoannu/Build/Products/Debug/Problem\ Set\ 1

Undefined symbols for architecture x86_64:
  "_GetInt", referenced from:
      _getPyramidHeight 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)

最佳答案 这些是源代码文件,需要使用您构建的应用程序进行编译.

根据您的说法,您似乎正在尝试链接这些文件,就像它们已经编译一样.

您应该从“Link Binary with Libraries”阶段删除它们并将“.c”文件添加到项目的“Compile source”阶段(仅限’.c’文件,因为只有这个文件实际上包含需要的代码’.h’文件是一个文件,用于通知其他人该代码提供的功能的接口)

这基本上是链接器在警告中试图告诉你的内容:在这个构建阶段发现源代码文件很困惑

点赞