Getting iPhone Simulator App to compile with libpq on Snow Leopard

From: Bob Henkel <bob(dot)henkel(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Getting iPhone Simulator App to compile with libpq on Snow Leopard
Date: 2009-11-08 14:22:45
Message-ID: fedea56b0911080622i64e31904v26361445ee6d92b8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Verite 2009-11-08 19:02:28 Re: adding a custom tsearch parser
Previous Message Jukka Inkeri 2009-11-08 12:25:26 Re: Problem to use remote cygwin server using ssh and native psql 8.3.5