iPhone - 为什么编译器在为 ARM 架构构建时找不到某些包含?

iPhone - Why can the compiler not find some includes when building for ARM architecture?(iPhone - 为什么编译器在为 ARM 架构构建时找不到某些包含?)

本文介绍了iPhone - 为什么编译器在为 ARM 架构构建时找不到某些包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 iPhone 项目中使用 C 库.我对 iPhone 开发非常熟悉.我的图书馆

I am trying to make use of a C library in an iPhone project. I am very green with iPhone development. My Library

我已经奋斗了好几天,试图将这个库构建成一个静态库,我可以在模拟器 (i386) 和 ARM7 上使用它.

I have been battling for days now to try and get this library build into a static library that I can use for both the simulator (i386) and ARM7.

使用库的包含配置和生成文件,我可以毫无问题地构建库.但是,如果我编辑 makefile 以尝试构建相同的库但针对 armv7 架构,我会遇到很多错误.错误似乎是报告无法找到某些头文件.

Using the the library's include configuration and makefile I can build the library without issue. However if I edit the makefile to try and build this same library but target the armv7 architecture I get many errors. The errors seem to be reporting that some header files cannot be located.

那么编译器是否会根据目标体系结构尝试在不同的位置查找头文件?

So does the compiler attempt to look in different places for header files depending on the target architecture?

这是我为 armv7 编辑的 make 文件:

This is the make file that I have edited to attempt to build for the armv7:

 # $Id: Makefile.in 62 2005-03-09 21:11:53Z gyunaev $
CC = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1 
CFLAGS = -Wall -DIN_BUILDING_LIBIRC -O3 -DENABLE_THREADS -D_REENTRANT
AR=ar cr
RANLIB=ranlib
INCLUDES=-I../include


OBJS = libircclient.o

all:    lib

lib:    libircclient.a

install: lib
    -mkdir /usr/local/include
    -mkdir /usr/local/lib
    cp ../include/libircclient.h /usr/local/include/libircclient.h
    cp ../include/libirc_errors.h /usr/local/include/libirc_errors.h
    cp ../include/libirc_events.h  /usr/local/include/libirc_events.h 
    cp libircclient.a /usr/local/include/lib/libircclient.a

$(OBJS): utils.c dcc.c errors.c portable.c sockets.c colors.c

libircclient.a: $(OBJS)
    $(AR) libircclient.a $(OBJS)
    $(RANLIB) libircclient.a

clean:
    rm -f libircclient.a $(OBJS)

distclean: clean
    -rm -f Makefile

.c.o:
    @echo "Compiling  $<"
    @$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

这是我遇到的编译错误示例:

Here is a sample of the compilation errors I am experiencing:

Compiling  libircclient.c
In file included from /usr/include/sys/_types.h:33,
             from /usr/include/_types.h:27,
             from /usr/include/stdio.h:64,
             from portable.c:18,
             from libircclient.c:15:
/usr/include/machine/_types.h:36:24: error: arm/_types.h: No such file or directory
In file included from /usr/include/_types.h:27,
             from /usr/include/stdio.h:64,
             from portable.c:18,
             from libircclient.c:15:
/usr/include/sys/_types.h:94: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_blkcnt_t’
/usr/include/sys/_types.h:95: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_blksize_t’
/usr/include/sys/_types.h:96: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_dev_t’

我做错了吗?编辑makefile是愚蠢的吗?:) 你如何处理 unix ninjas 这种情况?一些研究让我相信我需要创建一个通用库......

Am I going about this all wrong? Is editing the makefile dumb? :) How do you unix ninjas handle this situation? Some research has lead me to believe that I need to create a universal library...

谢谢!

推荐答案

问题是/usr/include 中的包含文件是针对 Mac OS X 的,而不是针对 iPhone/iPad 的.如果你想让事情顺利进行,你必须(至少)添加 Kay 在她的评论中提到的标志......

The problem is that the include file in /usr/include are for Mac OS X, not for the iPhone/iPad. If you want to get things to work you will have to add (at least) the flags that Kay mentioned in her comment...

非常更简单的方法是使用 XCode.只需创建一个新项目(选择 Cocoa Touch Static Library)并添加源文件.根据 Makefile 你需要添加:utils.c dcc.c errors.cportable.c sockets.c colors.c

A much easier way to go about this is to use XCode. Just create a new project (choose the Cocoa Touch Static Library) and add the source files. According to the Makefile you will need to add: utils.c dcc.c errors.c portable.c sockets.c colors.c

希望这会有所帮助.

您还可以查看 IRCClient 这是一个 Objective-C您正在使用的库的包装器.没有必要重新发明轮子!

You might also check out IRCClient which is a Objective-C wrapper for the library you are using. No point reinventing the wheel!

附加信息 2011 年 5 月 8 日

ADDITIONAL INFORMATION 5/8/11

原来 Objective-C 包装器是针对 Mac OS X 而不是 iOS

Turns out the Objective-C wrapper is aimed at Mac OS X not iOS

要编译它,您需要执行以下操作:

Here's what you need to do to get this to compile:

获取新鲜资源:

svn co https://libircclient.svn.sourceforge.net/svnroot/libircclient libircclient

进入libircclient/trunk/libircclient/src目录并运行

Change into the libircclient/trunk/libircclient/src directory and run

./configure

注意:这是一个有点肮脏的把戏.这实际上是为 Mac OS X 配置的,但大多数情况下事情都足够相似,可以正常工作.这会在 include 中生成一个名为 config.h 的文件.

Note: this is a slightly dirty trick. This is really configuring for Mac OS X but most of the times things are similar enough for this to work. This generates a file called config.h in include.

启动 XCode 并选择创建一个新的 Cocoa Touch 静态库.出现提示时创建一个新目录 libircclient/trunk/libircclient/iOS 并将新项目保存在那里.

Fire up XCode and choose to create a new Cocoa Touch static library. When prompted create a new directory libircclient/trunk/libircclient/iOS and save the new project there.

将 libircclient/trunk/libircclient/src 中的文件 libircclient.c 添加到项目中.事实证明,这个文件包含了所有其他的 C 文件.

Add the file libircclient.c from libircclient/trunk/libircclient/src to the project. It turns out that this file includes all the other C files.

打开您的项目设置并将 ../../include 添加到您的搜索头路径.

Open your project settings and add ../../include to you search header path.

构建并享受!

这篇关于iPhone - 为什么编译器在为 ARM 架构构建时找不到某些包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iPhone - 为什么编译器在为 ARM 架构构建时找不到某些包含?

基础教程推荐