为iOS(设备和模拟器)构建静态库并在XCode中使用

为iOS(设备和模拟器)构建静态库并在XCode中使用,xcode,ios,ios-simulator,static-libraries,Xcode,Ios,Ios Simulator,Static Libraries,我是XCode-/iOS开发新手(不是编程本身),我想制作一些简单的应用程序来适应它 我目前的项目是一个简单的二维码生成。对于这个任务,我想使用开源库libqrencode。 ( ) 我在以前的编码项目中没有使用开源库,但我想我理解大多数“机制”;) 到目前为止,我一直试图构建静态库并将其包含在我的XCode项目中。但是当使用库中的函数编译代码时,我会收到错误消息 第一个问题: 我尝试为iPhone设备构建如下: #### Build libqrencode for iPhoneOS e

我是XCode-/iOS开发新手(不是编程本身),我想制作一些简单的应用程序来适应它

我目前的项目是一个简单的二维码生成。对于这个任务,我想使用开源库libqrencode。 ( ) 我在以前的编码项目中没有使用开源库,但我想我理解大多数“机制”;)

到目前为止,我一直试图构建静态库并将其包含在我的XCode项目中。但是当使用库中的函数编译代码时,我会收到错误消息


第一个问题:

我尝试为iPhone设备构建如下:

#### Build libqrencode for iPhoneOS


export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export HOST=arm-apple-darwin10
export TARGET=arm-apple-darwin10
export PREFIX=$HOME/Desktop/MyProjects/cocoa/libqrencode/Release-iphoneos

export AR=$DEVROOT/usr/bin/ar
export CPP=$DEVROOT/usr/bin/cpp
export CXXPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/arm-apple-darwin10-llvm-g++-4.2
export LD=$DEVROOT/usr/bin/ld
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib

./configure --prefix=$PREFIX --host=$HOST --target=$TARGET --disable-shared --enable-static

makedepend
make
make install
#### Build libqrencode for iPhone-Simulator


export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
export HOST=i386-apple-darwin10
export TARGET=i386-apple-darwin10
export PREFIX=$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator

export AR=$DEVROOT/usr/bin/ar
export CPP=$DEVROOT/usr/bin/cpp
export CXXPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/i686-apple-darwin10-llvm-g++-4.2
export LD=$DEVROOT/usr/bin/ld
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib

./configure --prefix=$PREFIX --host=$HOST --target=$TARGET --disable-shared --enable-static

makedepend
make
make install
#! /bin/bash

#### Build libqrencode for iPhone-Simulator

unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset LIBS
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH

export SDKVER="4.2"
export DEVROOT="/Developer/Platforms/iPhoneSimulator.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneSimulator$SDKVER.sdk"

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="$PKG_CONFIG_PATH"
export PREFIX="$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
export CPPFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -pipe -no-cpp-precomp -I$SDKROOT/usr/include -I$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -I/usr/local/iphone-simulator-$SDKVER/include -m32"
export CFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export CXXFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export LDFLAGS="-miphoneos-version-min=$SDKVER -arch i386 --sysroot='$SDKROOT' -L$SDKROOT/usr/lib -L$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib -L/usr/local/iphone-simulator-$SDKVER/lib -m32"
export CPP="$DEVROOT/usr/bin/cpp"
export CXXCPP="$DEVROOT/usr/bin/cpp"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"

./configure --prefix="$PREFIX" --host="i386-apple-darwin9" --enable-static --disable-shared
但是,当我将它包括在我的XCode项目中并尝试使用该库中的两个简单函数时,我得到了以下错误:

Ld build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv6/myQRencode normal armv6
cd /Users/johnny/Desktop/MyProjects/myQRencode
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -L/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -L/Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib -F/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -filelist /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv6/myQRencode.LinkFileList -dead_strip -miphoneos-version-min=4.2 -framework Foundation -framework UIKit -framework CoreGraphics -lqrencode -o /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv6/myQRencode

ld: warning: in /Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib/libqrencode.a, file was built for unsupported file format which is not the architecture being linked (armv6)
Undefined symbols:
  "_QRcode_encodeString", referenced from:
      _main in main.o
  "_QRcode_free", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Ld build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv7/myQRencode normal armv7
cd /Users/johnny/Desktop/MyProjects/myQRencode
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -L/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -L/Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib -F/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -filelist /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv7/myQRencode.LinkFileList -dead_strip -miphoneos-version-min=4.2 -framework Foundation -framework UIKit -framework CoreGraphics -lqrencode -o /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv7/myQRencode

ld: warning: in /Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib/libqrencode.a, file was built for unsupported file format which is not the architecture being linked (armv7)
Undefined symbols:
  "_QRcode_encodeString", referenced from:
      _main in main.o
  "_QRcode_free", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make  all-recursive
Making all in .
/bin/sh ./libtool --tag=CC   --mode=link gcc  -Wall -miphoneos-version-min=4.2 -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk' -isystem /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include -isystem /Users/johnny/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-4.2/include -m32 -version-number 3:1:1 -miphoneos-version-min=4.2 -arch i386 --sysroot='/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk' -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib -L/Users/johnny/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib -L/usr/local/iphone-simulator-4.2/lib -m32 -o libqrencode.la -rpath /Users/johnny/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib qrencode.lo qrinput.lo bitstream.lo qrspec.lo rscode.lo split.lo mask.lo  
libtool: link: rm -fr  .libs/libqrencode.a
libtool: link: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar cru .libs/libqrencode.a  qrencode.o qrinput.o bitstream.o qrspec.o rscode.o split.o mask.o
/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(bitstream.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(rscode.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(split.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
libtool: link: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib .libs/libqrencode.a
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(bitstream.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(rscode.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(split.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
make[2]: *** [libqrencode.la] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2


第二个问题:

我尝试为iPhone设备构建如下:

#### Build libqrencode for iPhoneOS


export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export HOST=arm-apple-darwin10
export TARGET=arm-apple-darwin10
export PREFIX=$HOME/Desktop/MyProjects/cocoa/libqrencode/Release-iphoneos

export AR=$DEVROOT/usr/bin/ar
export CPP=$DEVROOT/usr/bin/cpp
export CXXPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/arm-apple-darwin10-llvm-g++-4.2
export LD=$DEVROOT/usr/bin/ld
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib

./configure --prefix=$PREFIX --host=$HOST --target=$TARGET --disable-shared --enable-static

makedepend
make
make install
#### Build libqrencode for iPhone-Simulator


export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
export HOST=i386-apple-darwin10
export TARGET=i386-apple-darwin10
export PREFIX=$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator

export AR=$DEVROOT/usr/bin/ar
export CPP=$DEVROOT/usr/bin/cpp
export CXXPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/i686-apple-darwin10-llvm-g++-4.2
export LD=$DEVROOT/usr/bin/ld
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib

./configure --prefix=$PREFIX --host=$HOST --target=$TARGET --disable-shared --enable-static

makedepend
make
make install
#! /bin/bash

#### Build libqrencode for iPhone-Simulator

unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset LIBS
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH

export SDKVER="4.2"
export DEVROOT="/Developer/Platforms/iPhoneSimulator.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneSimulator$SDKVER.sdk"

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="$PKG_CONFIG_PATH"
export PREFIX="$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
export CPPFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -pipe -no-cpp-precomp -I$SDKROOT/usr/include -I$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -I/usr/local/iphone-simulator-$SDKVER/include -m32"
export CFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export CXXFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export LDFLAGS="-miphoneos-version-min=$SDKVER -arch i386 --sysroot='$SDKROOT' -L$SDKROOT/usr/lib -L$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib -L/usr/local/iphone-simulator-$SDKVER/lib -m32"
export CPP="$DEVROOT/usr/bin/cpp"
export CXXCPP="$DEVROOT/usr/bin/cpp"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"

./configure --prefix="$PREFIX" --host="i386-apple-darwin9" --enable-static --disable-shared
但是,当我将它包括在我的XCode项目中并尝试使用该库中的两个简单函数时,我得到了以下错误(实际上与上面一样的错误消息):

问题1: 我还尝试将主机和目标设置为i686,但也不起作用(相同的错误消息)。不幸的是,我只有“i686-apple-darwin10-llvm-g++-4.2”和类似的版本,但没有“i386 xxxx…”。这是问题所在还是我选择了错误的设置

问题2: 如何检查构建库的目标是什么?bash中有特殊命令吗? 我记得第一次构建libqrencode时,我需要获取libpng12。到目前为止,我没有使用任何命令来创建PNG,但我没有为iPhone模拟器或iPhone设备重建PNG。libpng12库是否仍然由XCode链接,这是否会导致错误

谢谢你的帮助。很抱歉发了这么长的帖子,但我想尽可能彻底。准备好了



新增信息:

我使用以下配置设置为I386构建了libpng12:

#! /bin/bash

#### Build libpng12 for iPhone-Simulator

unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset LIBS
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH

unset CPP
unset CXXPP
unset CC
unset CXX
unset LD
unset STRIP
unset CPPFLAGS
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
unset AS
unset ASCPP

export SDKVER="4.2"
export DEVROOT="/Developer/Platforms/iPhoneSimulator.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneSimulator$SDKVER.sdk"

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="$PKG_CONFIG_PATH"
export PREFIX="$HOME/Desktop/MyProjects/cocoa/libpng12/Debug-iphonesimulator"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
export CPPFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -pipe -no-cpp-precomp -I$SDKROOT/usr/include -I$HOME/Desktop/MyProjects/cocoa/libpng12/Debug-iphonesimulator/include -I/usr/local/iphone-simulator-$SDKVER/include"
export CFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libpng12/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export CXXFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libpng12/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include"
export LDFLAGS="-miphoneos-version-min=$SDKVER -arch i386 --sysroot='$SDKROOT' -L$SDKROOT/usr/lib -L$HOME/Desktop/MyProjects/cocoa/libpng12/Debug-iphonesimulator/lib -L/usr/local/iphone-simulator-$SDKVER/lib"
export CPP="$DEVROOT/usr/bin/cpp"
export CXXCPP="$DEVROOT/usr/bin/cpp"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"

./configure --prefix="$PREFIX" --host="i386-apple-darwin9" --enable-static --disable-shared
但当我尝试对libqrencode使用类似/相同的设置时,我得到以下错误:

Ld build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv6/myQRencode normal armv6
cd /Users/johnny/Desktop/MyProjects/myQRencode
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -L/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -L/Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib -F/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -filelist /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv6/myQRencode.LinkFileList -dead_strip -miphoneos-version-min=4.2 -framework Foundation -framework UIKit -framework CoreGraphics -lqrencode -o /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv6/myQRencode

ld: warning: in /Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib/libqrencode.a, file was built for unsupported file format which is not the architecture being linked (armv6)
Undefined symbols:
  "_QRcode_encodeString", referenced from:
      _main in main.o
  "_QRcode_free", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Ld build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv7/myQRencode normal armv7
cd /Users/johnny/Desktop/MyProjects/myQRencode
setenv IPHONEOS_DEPLOYMENT_TARGET 4.2
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -L/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -L/Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib -F/Users/johnny/Desktop/MyProjects/myQRencode/build/Release-iphoneos -filelist /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv7/myQRencode.LinkFileList -dead_strip -miphoneos-version-min=4.2 -framework Foundation -framework UIKit -framework CoreGraphics -lqrencode -o /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Release-iphoneos/myQRencode.build/Objects-normal/armv7/myQRencode

ld: warning: in /Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release-iphoneos/lib/libqrencode.a, file was built for unsupported file format which is not the architecture being linked (armv7)
Undefined symbols:
  "_QRcode_encodeString", referenced from:
      _main in main.o
  "_QRcode_free", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make  all-recursive
Making all in .
/bin/sh ./libtool --tag=CC   --mode=link gcc  -Wall -miphoneos-version-min=4.2 -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk' -isystem /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include -isystem /Users/johnny/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-4.2/include -m32 -version-number 3:1:1 -miphoneos-version-min=4.2 -arch i386 --sysroot='/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk' -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib -L/Users/johnny/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib -L/usr/local/iphone-simulator-4.2/lib -m32 -o libqrencode.la -rpath /Users/johnny/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib qrencode.lo qrinput.lo bitstream.lo qrspec.lo rscode.lo split.lo mask.lo  
libtool: link: rm -fr  .libs/libqrencode.a
libtool: link: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar cru .libs/libqrencode.a  qrencode.o qrinput.o bitstream.o qrspec.o rscode.o split.o mask.o
/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(bitstream.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(rscode.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(split.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
libtool: link: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib .libs/libqrencode.a
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(bitstream.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(rscode.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib: archive member: .libs/libqrencode.a(split.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
make[2]: *** [libqrencode.la] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

对不起,没有帮助你解决编译问题,但是看起来你有一个更大的问题:LBQReNoCK是在LGPL下授权的,很多人认为它是()。因此,在应用程序中使用libqrencode可能会给自己带来法律风险。

好的,我终于有时间完成这个问题了。这个问题以前已经解决了,我只是使用了一个错误的include路径。可以使用以下代码成功创建库:

#### Build libqrencode for iPhoneOS


export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export HOST=arm-apple-darwin10
export TARGET=arm-apple-darwin10
export PREFIX=$HOME/Desktop/MyProjects/cocoa/libqrencode/Release-iphoneos

export AR=$DEVROOT/usr/bin/ar
export CPP=$DEVROOT/usr/bin/cpp
export CXXPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/arm-apple-darwin10-llvm-g++-4.2
export LD=$DEVROOT/usr/bin/ld
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib

./configure --prefix=$PREFIX --host=$HOST --target=$TARGET --disable-shared --enable-static

makedepend
make
make install
#### Build libqrencode for iPhone-Simulator


export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
export HOST=i386-apple-darwin10
export TARGET=i386-apple-darwin10
export PREFIX=$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator

export AR=$DEVROOT/usr/bin/ar
export CPP=$DEVROOT/usr/bin/cpp
export CXXPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/i686-apple-darwin10-llvm-g++-4.2
export LD=$DEVROOT/usr/bin/ld
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib

./configure --prefix=$PREFIX --host=$HOST --target=$TARGET --disable-shared --enable-static

makedepend
make
make install
#! /bin/bash

#### Build libqrencode for iPhone-Simulator

unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset LIBS
unset DYLD_FALLBACK_LIBRARY_PATH
unset DYLD_FALLBACK_FRAMEWORK_PATH

export SDKVER="4.2"
export DEVROOT="/Developer/Platforms/iPhoneSimulator.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneSimulator$SDKVER.sdk"

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="$PKG_CONFIG_PATH"
export PREFIX="$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
export CPPFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -pipe -no-cpp-precomp -I$SDKROOT/usr/include -I$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -I/usr/local/iphone-simulator-$SDKVER/include -m32"
export CFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export CXXFLAGS="-miphoneos-version-min=$SDKVER -std=c99 -arch i386 -pipe -no-cpp-precomp --sysroot='$SDKROOT' -isystem $SDKROOT/usr/include -isystem $HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/include -isystem /usr/local/iphone-simulator-$SDKVER/include -m32"
export LDFLAGS="-miphoneos-version-min=$SDKVER -arch i386 --sysroot='$SDKROOT' -L$SDKROOT/usr/lib -L$HOME/Desktop/MyProjects/cocoa/libqrencode/Debug-iphonesimulator/lib -L/usr/local/iphone-simulator-$SDKVER/lib -m32"
export CPP="$DEVROOT/usr/bin/cpp"
export CXXCPP="$DEVROOT/usr/bin/cpp"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export CXX="$DEVROOT/usr/bin/g++-4.2"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"

./configure --prefix="$PREFIX" --host="i386-apple-darwin9" --enable-static --disable-shared

再次感谢DarkDust对您的帮助

谢谢你的建议。再次提醒我,我多么讨厌许可证问题:)但这应该只是(也许)未来的问题,因为一开始我并不打算在苹果应用商店发布应用程序。如上所述,我的这个部分项目的意思是“开始使用XCode”。事实上,我甚至想发布整个源代码(因为大多数工作不是我的)。但至少我现在知道,我以后再也不用考虑把它提交到AppStore了。我已经和作者核实过了,他确认libqrencode可以在bsd风格的许可下使用。如果你对此有更多的了解,我会回击他的观点,虽然环境变量看起来不错,但生成的静态库似乎无法识别。查看命令的输出
otool-hv/Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Release iphoneos/lib/libqrencode.a
,它是否在输出的第二列和第三列中列出了
ARM
V6
V7
?谢谢你的提示!否,它列出了所有条目的“X86_64”。因此,在建立图书馆时,显然存在一些错误,但为什么呢?很明显,我试图用配置定义正确的cpuytype(目标)。顺便说一句,iPhone模拟器库也是如此。@EliteTUM:这表明它不是用
arm-apple-darwin10-llvm-g++-4.2
编译的。您需要检查生成的
Makefile
(应该在变量
CC
和/或
CXX
中)@DarkDust:在
的末尾/configure…
我得到了
CC=gcc
CXX=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-llvm-g++-4.2
@EliteTUM:你是说在
的末尾配置
的输出吗?如果它在Makefile中,则尝试编辑它并设置
CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-llvm-gcc-4.2