简体   繁体   English

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

[英]How do I add a library to my C project in Xcode 6

I am fairly new to this, but I will try to provide as detailed information as possible. 我对此很新,但我会尝试提供尽可能详细的信息。 I initially tried to provide a screenshot, but I can't do so without 10 reputation, so I am going to copy+paste the error messages as text at the bottom. 我最初尝试提供截图,但是如果没有10个声誉我就不能这样做,所以我将复制+粘贴错误消息作为底部的文本。

I am working on the Harvard CS50 Problem Set 1. As part of that, you are supposed to use a library provided for the coursework. 我正在研究哈佛CS50问题集1.作为其中的一部分,您应该使用为课程作业提供的库。 It comes in two files: cs50.h and cs50.c 它有两个文件:cs50.h和cs50.c

I have downloaded these files and initially I was getting an error, which I found was because it's a 32-bit library and I'm running 64-bit. 我已经下载了这些文件,最初我收到了一个错误,我发现这是因为它是一个32位的库而我正在运行64位。 I changed where I was referencing the libraries by going to the Project > Build Phases > Link Binary with Libraries, as what I found online indicated that if I handled it here, Xcode would take care of ensuring the correct architecture and such (32-bit vs. 64-bit). 我通过转到Project> Build Phases> Link Binary with Libraries改变了我引用库的位置,正如我在网上发现的那样,如果我在这里处理它,Xcode将负责确保正确的架构等(32位)与64位)。

Now I am getting the yellow errors stating that it is passing over these files when I try to build because it is an unexpected file type. 现在我收到黄色错误,指出它在我尝试构建时传递这些文件,因为它是一个意外的文件类型。

I found a recommendation to use the File Inspector to view the type and I rotated through the various C file types available to see if it would fix anything and I had no luck. 我发现建议使用文件检查器来查看类型,并且我通过各种可用的C文件类型进行了旋转,看看它是否可以解决任何问题而我没有运气。

I also found another conversation around this that indicated updating the architecture type to the Universal option would help, but that has not changed anything. 我还发现了围绕这个的另一个对话,表明将体系结构类型更新为Universal选项会有所帮助,但这并没有改变任何东西。

At this point, I am unable to find anything that seems related to my problem through Google searches. 此时,我无法通过Google搜索找到与我的问题相关的任何内容。

I also realize that due to my newness, I have just done something royally stupid, but I feel I have spend a lot of time trying to fix this. 我也意识到,由于我的新意,我刚刚做了一些非常愚蠢的事情,但我觉得我花了很多时间来解决这个问题。 I appreciate any help. 我感谢任何帮助。

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)

Those are source code files, that need to be compiled with the application you build. 这些是源代码文件,需要使用您构建的应用程序进行编译。 From what you say, it looks like you are trying to link those files as if they were already compiled. 根据您的说法,您似乎正在尝试链接这些文件,就像它们已经编译一样。

You should remove them from the "Link Binary with Libraries" phase and add the '.c' file to the "Compile source" phase of your project (only the '.c' file, because only this file actually contains code that needs to be compiled. The '.h' file is a file meant to inform others of the interface of the functions provided by that code) 您应该从“Link Binary with Libraries”阶段删除它们并将“.c”文件添加到项目的“Compile source”阶段(仅限'.c'文件,因为只有这个文件实际上包含需要的代码'.h'文件是一个文件,用于通知其他人该代码提供的功能的接口)

This is basically what the linker is trying to tell you in the warnings: it is confused to find source-code files at this phase of building 这基本上是链接器在警告中试图告诉你的内容:在这个构建阶段发现源代码文件很困惑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM