微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xcode – 使用Libpq将iPhone App连接到PostgreSQL

我需要为iPhone创建一个应用程序,它将使用libpq连接到Postgresql 8.4数据库.问题是我无法得到一个链接到libpq进行编译的简单iPhone.然而,我能够获得与普通Mac桌面应用程序相同的应用程序来编译和连接到Postgresql而没有任何问题.我在SNow Leopard上运行Xcode 3.2.

我正在为arm和x86_84构建libpq. arm构建适用于真正的iPhone,x86_64适用于iPhone模拟器.然后我创建一个包含两个文件的胖二进制文件,最后得到一个名为libpq的文件.这个文件是我在常规Mac应用程序中使用的文件,它工作正常,并在尝试构建iPhone应用程序时导致问题.

这是我构建libpq时的构建脚本.

#!/bin/bash

DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
SDKROOT=$DEVROOT/SDKs/iPhoneOS3.0.sdk

rm -rf  /Users/bob/mylibs
mkdir /Users/bob/mylibs #Store there compiled libs
make clean

#Build ARM library
./configure --host=arm-apple-darwin --without-readline --disable-ipv6 CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/" CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT" CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS" LD=$DEVROOT/usr/bin/ld
make -C src/interfaces/libpq
cp /Users/bob/Downloads/postgresql-8.4.1/src/interfaces/libpq/libpq.a /Users/bob/mylibs/libpq.arm

#Then build i386 library
make clean && ./configure  && make -C src/interfaces/libpq
cp src/interfaces/libpq/libpq.a  /Users/bob/mylibs/libpq.i386

#Then make fat binary
$DEVROOT/usr/bin/lipo -arch armv6 /Users/bob/mylibs/libpq.arm -arch x86_64 /Users/bob/mylibs/libpq.i386 -create -output  /Users/bob/mylibs/libpq

当我尝试从Xcode中编译iPhone应用程序时,这是构建日志.

Build iPhonePg of project iPhonePg with configuration Debug

Ld build/Debug-iphonesimulator/iPhonePg.app/iPhonePg normal i386
cd /Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg
setenv MACOSX_DEPLOYMENT_TARGET 10.5
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/iPhonesimulator3.0.sdk -L/Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/build/Debug-iphonesimulator -L../../../../mylibs -L/Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg -L/Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/../../../../mylibs -F/Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/build/Debug-iphonesimulator -filelist /Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/build/iPhonePg.build/Debug-iphonesimulator/iPhonePg.build/Objects-normal/i386/iPhonePg.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework CoreGraphics /Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/libpq -o /Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/build/Debug-iphonesimulator/iPhonePg.app/iPhonePg

ld: warning: in /Users/bob/Documents/Programming/PragProgrammerIphonesDK/iPhonePg/libpq,missing required architecture i386 in file
Undefined symbols:
  "_PQclear",referenced from:
      -[iPhonePgAppDelegate applicationDidFinishLaunching:] in iPhonePgAppDelegate.o
  "_PQerrorMessage",referenced from:
      -[iPhonePgAppDelegate applicationDidFinishLaunching:] in iPhonePgAppDelegate.o
  "_PQconnectdb",referenced from:
      -[iPhonePgAppDelegate applicationDidFinishLaunching:] in iPhonePgAppDelegate.o
  "_PQfinish",referenced from:
      -[iPhonePgAppDelegate applicationDidFinishLaunching:] in iPhonePgAppDelegate.o
  "_PQstatus",referenced from:
      -[iPhonePgAppDelegate applicationDidFinishLaunching:] in iPhonePgAppDelegate.o
  "_PQexec",referenced from:
      -[iPhonePgAppDelegate applicationDidFinishLaunching:] in iPhonePgAppDelegate.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

遇到这种情况的其他人可以提供帮助吗?

谢谢
StartShip3000

解决方法

看起来你实际上并没有链接到库中.您已将其所在的目录添加搜索路径中,但我在链接行的任何位置都没有看到-lpq.

此外,模拟器环境仅为32位,x86_64库不适用于模拟器二进制文件.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐