简体   繁体   中英

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.

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

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).

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.

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.

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)

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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