Сборка статической библиотеки для iOS (Device and Simulator) и использование в XCode - PullRequest
3 голосов
/ 12 апреля 2011

Я новичок в XCode- / iOS-Development (не программирую сам) и хочу создать несколько простых приложений, чтобы привыкнуть к этому.

Мой текущий проект - это простая генерация QR-кода.Для этой задачи я хочу использовать библиотеку с открытым исходным кодом libqrencode.(http://fukuchi.org/works/qrencode/index.en.html) Я не использовал библиотеки с открытым исходным кодом в моих старых проектах кодирования, но я думаю, что я понял большую часть «механики»;)

До сих пор я пытался собрать статическую библиотеку и включитьэто в моем XCode-проекте.Но при компиляции кода с использованием функций из библиотеки я получаю сообщения об ошибках.


1-я проблема:

Я пытаюсь построить для 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

Но когда я включаю его в свой 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


2-я проблема:

Я пытаюсь собрать для iPhone-устройства вот так:

#### 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

Но когда я включаю его в свой XCode-проект и пытаюсь использовать дваПростые функции из этой библиотеки Я получаю следующую ошибку (на самом деле то же самое сообщение об ошибке, как указано выше):

Ld build/Debug-iphonesimulator/myQRencode.app/myQRencode normal i386
cd /Users/johnny/Desktop/MyProjects/myQRencode
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L/Users/johnny/Desktop/MyProjects/myQRencode/build/Debug-iphonesimulator -L/Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Debug-iphonesimulator/lib -F/Users/johnny/Desktop/MyProjects/myQRencode/build/Debug-iphonesimulator -filelist /Users/johnny/Desktop/MyProjects/myQRencode/build/myQRencode.build/Debug-iphonesimulator/myQRencode.build/Objects-normal/i386/myQRencode.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -lqrencode -o /Users/johnny/Desktop/MyProjects/myQRencode/build/Debug-iphonesimulator/myQRencode.app/myQRencode

ld: warning: in /Users/johnny/Desktop/MyProjects/myQRencode/libqrencode/Debug-iphonesimulator/lib/libqrencode.a, file was built for unsupported file format which is not the architecture being linked (i386)
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

Вопрос 1: Я также попытался установить HOST и TARGET на i686,но это тоже не сработало (то же сообщение об ошибке).К сожалению, у меня только "i686-apple-darwin10-llvm-g ++ - 4.2" и аналогичные, но нет "i386-xxxx ....".Это проблема или какие настройки я выбрал неправильно?

Вопрос 2: Как проверить, для какой цели была создана библиотека?В bash есть специальная команда?Я помню, когда я впервые создавал libqrencode, мне нужно было получить libpng12.До сих пор я не использовал никаких команд для создания PNG, но я не перестраивал их ни для iPhone-Simulator, ни для iPhone-Device.Будет ли библиотека libpng12 по-прежнему связана с XCode и может ли это быть источником ошибки?

Любая помощь приветствуется.Извините за длинный пост, но я хотел быть максимально тщательным.Thans allready !!



Добавлена ​​информация:

Мне удалось собрать libpng12 для I386, используя следующие настройки конфигурации:

#! /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 , я получаю следующую ошибку:

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

Ответы [ 2 ]

1 голос
/ 24 апреля 2011

ОК, наконец-то у меня есть время закончить этот вопрос.Проблема была решена раньше, я просто использовал неверный путь включения.Библиотека может быть успешно создана с использованием следующего кода:

#! /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 за вашу помощь!

1 голос
/ 12 апреля 2011

Извините, что не помогли вам с проблемами компиляции, но, похоже, у вас гораздо более серьезная проблема: libqrencode лицензирован по лицензии LGPL, и многие считают его несовместимым с условиями Apple ( другое статья о несовместимости GPL / LGPL с условиями Apple ). Таким образом, вы можете подвергнуть себя юридическому риску, используя libqrencode в своем приложении.

...