I need to create an application for the iPhone that will connect to the PostgreSQL 8.4 database using libpq. The problem is that I cannot get a simple iPhone that references libpq for compilation. However, I can get an equivalent application, which is a regular Mac desktop application for compiling and connecting to PostgreSQL without any problems. I am on Xcode 3.2 running on Snow Leopard.
I am creating libpq for both hands and for x86_84. Manual assembly is for the real iPhone, and x86_64 is for the iPhone simulator. Then I create a bold binary file containing both files, and the result is a file called libpq. This file is the one I use in a regular Mac application, and it works fine and causes problems when trying to create an iPhone application.
Here is my build script when creating libpq.
#!/bin/bash
DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
SDKROOT=$DEVROOT/SDKs/iPhoneOS3.0.sdk
rm -rf /Users/bob/mylibs
mkdir /Users/bob/mylibs
make clean
./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
make clean && ./configure && make -C src/interfaces/libpq
cp src/interfaces/libpq/libpq.a /Users/bob/mylibs/libpq.i386
$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
Here is the build log when I try to compile an iPhone application from Xcode.
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
Does anyone else come across this that might help?
Thanks StartShip3000
source
share