添加一个头文件于X code [英] Adding a header file to Xcode

查看:543
本文介绍了添加一个头文件于X code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加一个C库于X code。我下载了图书馆从网上的C类和压缩文件包含两个文件: cs50.c cs50.h

I'm trying to add a C library to Xcode. I downloaded the library from an online C class, and the zipped file contains two files: cs50.c and cs50.h.

我用下面的命令安装这些文件:

I installed these files using the following commands:

gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
rm -f cs50.o
chmod 0644 cs50.h libcs50.a
sudo mv cs50.h /usr/include
sudo cp libcs50.a /usr/lib

在建项目,我收到以下错误信息:

When building the project, I get the following error message:

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

这是我如何引用我在程序的头文件:

This is how I'm referencing the header file in my program:

#include </usr/include/cs50.h>

如果我不包括道路,我得到的找不到文件的消息

If I don't include the path, I get a can't find file message.

我的X code的版本是:4.5.2版本(4G2008a),我运行OS X 10.7.5

My version of Xcode is: Version 4.5.2 (4G2008a) and I'm running OS X 10.7.5.

感谢您的任何建议。

更新:

推荐答案

作为一般规则,你不应该安装或的/ usr 修改什么,除非你有一个非常充分的理由这样做。该目录是保留给操作系统,并且可以快速地碰到了很多问题 - 例如,如果你不小心覆盖系统库或头文件,甚至在安装新的东西在更新操作系统时,有可能会导致问题

As a general rule, you should never install or modify anything in /usr unless you have a very good reason to do so. This directory is reserved for the operating system, and you can quickly run into a lot of problems - for instance if you accidentally overwrite a system library or header file and even installing new things in there may cause problems when updating your operating system.

如果你确实需要安装这个系统范围内,然后把它放到的/ usr /本地

If you really need to install this system-wide, then put it into /usr/local.

不过,既然你编译调试信息库中,我假设你还需要测试并在您的项目玩它。

However, since you compiled the library with debugging information, I assume that you also want to test and play around with it in your project.

要做到这一点,它更容易添加源作为一个新的C / C ++库的目标到项目中。那么x code会照顾一切丑陋的细节,如编译,选择合适的处理器架构(32位或64位),你会以x code获得源代码级调试支持,如果你想安装您的应用程序或为它创建一个包,那么X code也将自动捆绑依赖你。

To do that, it's much easier to add the sources as a new "C/C++ Library" target to your project. Then Xcode will take care of all the ugly details such as compiling, choosing the right processor architecture (32 or 64 bit), you'll get source-level debugging support in Xcode and if you ever want to install your app or create a package for it, then Xcode will also automatically bundle the dependencies for you.

这篇关于添加一个头文件于X code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆