使MAC ARM架构的C库 [英] make arm architecture c library in mac

查看:210
本文介绍了使MAC ARM架构的C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让苹果在我自己的C库,它包括我的iPhone程序。
在C code是简单的,就像这样:

I'm trying to make my own c library in Mac and include it to my iphone program. The c code is simple , like this:

文件math.h:

int myPow2(int);

math.c:

math.c:

#include "math.h"

int myPow2(int num) { 
    return num*num; 
} 

我寻找如何让C库文件(某或.LIB ..等),似乎需要使用gcc编译(有没有其他的方法?),所以我用这个命令:

I search how to make the c library file ( .a or .lib ..etc) seems need to use gcc compiler (Is there other methods?) so I use this command:

gcc -c math.c -o math.o
ar rcs libmath.a math.o

和包含在iPhone项目。现在,它有问题时生成X $ C $ÇiPhone项目。

And include it in iPhone Project. Now it has the problem when build xcode iphone project.

文件是专为不支持的文件
  格式这不是架构
  被链接

"file was built for unsupported file format which is not the architecture being linked"

我发现了一些<一个href=\"http://stackoverflow.com/questions/1542880/iphone-library-file-is-not-of-required-architecture\">pages有关该问题的讨论的,但没有详细说明如何使在i386 / arm架构库。而且我也终于用这个命令来做到这一点:

I found some pages discuss about the problem, but no detail how to make the i386/arm architecture library. And I finally use this command to do it:

gcc -arch i386 -c math.c -o math.o
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1 -c math.c -o math.o 

我不知道这种方法是正确的?或者有有另一种方法来做到这一点?

I dont know if this method is correct? Or there has another method to do it?

推荐答案

什么 Bavarious 说。

添加一个新的目标项目。当X code要求你用什么模板,选择静态库。

Add a new target to your project. When XCode asks you what template to use, chose "Static Library".

添加文件库到该目标。添加静态库的目标是你的主要目标可执行文件的依赖。补充一下,被内置到您的主执行程序的目标库中。瞧!

Add the files for the library to that target. Add the static library target as a dependency of your main executable target. Add the library that gets built to your main executable target. Voila!

这篇关于使MAC ARM架构的C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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