如何在Xcode 6中为C项目添加一个库?

时间:2021-05-07 18:57:34

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. It comes in two files: cs50.h and cs50.c

我在做哈佛CS50习题集1。作为其中的一部分,你应该使用为课程提供的图书馆。它有两个文件: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. 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).

我下载了这些文件,一开始我发现了一个错误,因为它是一个32位的库,我运行的是64位的。通过使用项目>构建阶段>与库的二进制链接,我改变了引用库的位置,正如我在网上找到的那样,如果我在这里处理它,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.

在这一点上,我无法通过谷歌搜索找到与我的问题相关的任何东西。

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)

1 个解决方案

#1


2  

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)

您应该从“链接二进制与库”阶段删除它们,并添加'。c'文件到“编译源”阶段的项目(只有'。c'文件,因为只有这个文件包含需要编译的代码。”。h' file是指通知他人该代码提供的函数的接口的文件)

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

这基本上就是链接器在警告中试图告诉您的:在构建的这个阶段找到源代码文件是令人困惑的

#1


2  

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)

您应该从“链接二进制与库”阶段删除它们,并添加'。c'文件到“编译源”阶段的项目(只有'。c'文件,因为只有这个文件包含需要编译的代码。”。h' file是指通知他人该代码提供的函数的接口的文件)

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

这基本上就是链接器在警告中试图告诉您的:在构建的这个阶段找到源代码文件是令人困惑的