iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了xcode – 使用Libpq将iPhone App连接到PostgreSQL大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我需要为iPhone创建一个应用程序,它将使用libpq连接到postgreSQL 8.4数据库.问题是我无法得到一个链接到libpq进行编译的简单iPhone.然而,我能够获得与普通Mac桌面应用程序相同的应用程序来编译和连接到postgreSQL而没有任何问题.我在snow Leopard上运行Xcode 3.2. 我正在为arm和x86_84构建libpq. arm构建适用于真正的iPhon
我需要为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库不适用于模拟器二进制文件.

大佬总结

以上是大佬教程为你收集整理的xcode – 使用Libpq将iPhone App连接到PostgreSQL全部内容,希望文章能够帮你解决xcode – 使用Libpq将iPhone App连接到PostgreSQL所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。