Thread: Getting iPhone Simulator App to compile with libpq on Snow Leopard
In my quest to create a simple PostgreSQL program that runs on the iPhone I have ran into some problems. The first issue I had with my build was libpq being compiled for architecture of type x86_64 by default on Snow Leopard and the Simulator being i386 so my build would fail telling me libpq was the wrong architecture type. I was able to get around this issue as found here -> http://stackoverflow.com/questions/1678381/connect-iphone-app-to-postgresql-using-libpq. Now I'm getting a new "Undefined symbols" issue. Here is the code that is attempting to connect to PostgreSQL // // iPhonePgAppDelegate.m // iPhonePg // // Created by bob on 11/4/09. // Copyright __MyCompanyName__ 2009. All rights reserved. // #import "iPhonePgAppDelegate.h" #import "iPhonePgViewController.h" #include "libpq-fe.h" @implementation iPhonePgAppDelegate @synthesize window; @synthesize viewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { const char *conninfo; PGconn *conn; PGresult *res; conninfo = "host = 192.168.1.5 dbname = dev user=postgres password=zzzzz"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); res = PQexec(conn, "INSERT INTO public.junk(junk_data) VALUES('HELLO');"); if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); } PQclear(res); PQfinish(conn); [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } Here is the output from my build attempt that is showing an error. Keep in mind I have the equivalent Mac version of this app connecting to PostgreSQL just fine. The only real difference is the project type of the apps, Mac app vs iPhone app. So I feel pretty good about me not doing something that is obviously wrong. I'm on Snow Leopard with Xcode 3.2 using libpq compiled for i386 from PostgreSQL 8.4.1 source. 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/../../../../mylibs/libpq.i386 -o /Users/bob/Documents/Programming/PragProgrammerIphoneSDK/iPhonePg/build/Debug-iphonesimulator/iPhonePg.app/iPhonePg Undefined symbols: "_fopen$UNIX2003", referenced from: _parseServiceInfo in libpq.i386(fe-connect.o) _PasswordFromFile in libpq.i386(fe-connect.o) ld: symbol(s) not found collect2: ld returned 1 exit status Any help would be greatly appreciated. Thanks Bob
hi bob, > Undefined symbols: > "_fopen$UNIX2003", referenced from: > _parseServiceInfo in libpq.i386(fe-connect.o) > _PasswordFromFile in libpq.i386(fe-connect.o) > ld: symbol(s) not found > collect2: ld returned 1 exit status > > Any help would be greatly appreciated. hm, fopen is a standard c (libSystem) function. make shure you have linked your library (libpq) against the same versions of standard libraries as you try with your iphone-app. check your linker options, specially -isysroot. you can check later to which libSystem your lib or app was built with: otool -L <LibOrApp> regards, jan otto
Thanks Jan that was the issue. The SDK that my app was using for the simulator build was was 10.5 while the my compile of libpq was using 10.6. Once I forced libpq to compile with 10.5 all my problems went away. Thanks for your help I appreciate it. On Mon, Nov 9, 2009 at 8:40 AM, Jan Otto <asche@me.com> wrote: > hi bob, > >> Undefined symbols: >> "_fopen$UNIX2003", referenced from: >> _parseServiceInfo in libpq.i386(fe-connect.o) >> _PasswordFromFile in libpq.i386(fe-connect.o) >> ld: symbol(s) not found >> collect2: ld returned 1 exit status >> >> Any help would be greatly appreciated. > > hm, fopen is a standard c (libSystem) function. make shure you > have linked your library (libpq) against the same versions of > standard libraries as you try with your iphone-app. > > check your linker options, specially -isysroot. > > you can check later to which libSystem your lib or app was built > with: otool -L <LibOrApp> > > regards, jan otto >