问题
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
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/13583039/interface-from-c-programm-in-xcode-to-swi-prolog