0

i want to interface from c-code using XCode IDE under MAC OS X to SWI-Prolog.

I´ve included the header files and use the following sample code:

#include <stdio.h>
#include <SWI-Prolog.h>
#include <SWI-Stream.h>

int main(int argc, const char * argv[])
{

char *av[10];
int ac = 0;

av[ac++] = "/opt/local/lib/swipl-6.2.2/bin/i386-darwin12.2.1/swipl";
av[ac++] = "-x";
av[ac++] = "mystate";
av[ac]   = NULL;

#ifdef READLINE /* Remove if you don't want readline */
PL_initialise_hook(install_readline);
#endif

if ( !PL_initialise(ac, av) )
    PL_halt(1);

PL_halt(PL_toplevel() ? 0 : 1);


printf("done...\n");
return 0;
}

I also linked at the build settings to the header and lib paths:

Header Search Path: /opt/local/lib/swipl-6.2.2/include

Library Search Path: /opt/local/lib/swipl-6.2.2/lib/i386-darwin12.2.1

But while running the code i get the following errors:

Undefined symbols for architecture x86_64:
  "_PL_halt", referenced from:
      _main in main.o
  "_PL_initialise", referenced from:
      _main in main.o
  "_PL_toplevel", referenced from:
       _main in main.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone can help me to get my code running?

Thanks in Advance and Kind regards

Solick

solick
  • 2,325
  • 3
  • 17
  • 29
  • mismatch i386 vs x86_64? – CapelliC Nov 27 '12 at 12:03
  • hmm this was the installation files for MAC OS X... but maybe i should try to compile swi-prolog myself on my mac... thanks for the hint, i´ll give it a try... But on the other hand: Running swi-prolog from terminal works fine and without problems... – solick Nov 27 '12 at 15:30
  • ld warnings on architecture x86_64... seems misconfigured – CapelliC Nov 27 '12 at 15:42
  • hmm that could be the problem... i use the precompiled version from the website for MAC and running swi from console works fine. Maybe the libs are only compiled for 32 Bit on MAC? – solick Dec 11 '12 at 11:18

2 Answers2

0

Even if you set the correct paths in the settings, it doesn't automatically find the correct library to link with. You have to add the actual library as well.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thanks for the hint. But which lib and where to link? There are a lot of *.dylib files in the lib directory... – solick Nov 27 '12 at 15:29
0

I work in Ubuntu (and yes, in Windows, still), and I've come to appreciate the pkg-config support.

If you are already comfortable with it, note that when compiled locally, SWI-Prolog generates a directory ~/lib/pkgconfig.

Then you could add that directory to pkg-config configuration, and use the SW with (IMHO) a good support.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • Hi, no i use the pre-compiled version. The problem is with XCode that the makefile is different (and graphical :) – solick Nov 27 '12 at 15:28