Ask Your Question
1

Compiling ros node with cmake and swi-prolog

asked 2012-09-06 02:38:16 -0500

McKracken gravatar image

Hi to all! I have a ROS node that performs some swi-prolog queries using the pl2cpp library (it comes together with the swi-prolog installation). Now, the problem is that when i have a .cpp file that interacts with prolog in this way, i need to compile it together with the used prolog file with the compilation command swipl-ld

ex. swipl-ld my_ccp_file.cpp my_prolog_file.pl

this generates the stand alone executable with the cpp and the prolog linked together. I don't know how and when to call this procedure in the compilation process of a ROS node.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-09-06 02:59:43 -0500

Lorenz gravatar image

I don't think you are required to use swipl-ld if you just want to link against prolog. As far as I know, it's just a wrapper that makes sure the right libraries are included and maybe stores some initial state.

However, on Ubuntu, swi-prolog provides a package-config file that you can use in your CMakeLists.txt. For swi-prolog, something like this should work:

include(FindPkgConfig)
pkg_check_modules(SWIPL REQUIRED swipl)
include_directories(${SWIPL_INCLUDE_DIRS})
link_directories(${SWIPL_LIBRARY_DIRS})

# ... some other stuff and the definition of your executable target
target_link_libraries(<your target> ${SWIPL_LIBRARIES})

If initialization of the prolog kernel does not work properly, the reason could be that your prolog home could not be found since your executable will not contain any saved prolog state. Have a look at the corresponding section in the prolog manual. Sorry for not providing a direct link but this site does not like urls with parenthesis and I'm too lazy to look up the corresponding code. Here the url: http://www.swi-prolog.org/pldoc/doc_for?object=section(2,'9.6',swi('/doc/Manual/findhome.html')).

edit flag offensive delete link more
0

answered 2012-09-06 04:12:04 -0500

McKracken gravatar image

Ok, i think this is the right way! Thank you. Now I have one last question (i know it could be the last because i tried it): To use prolog via code, first of all i need to initialize the prolog engine

PlEngine e("a.out")

passing it the "a.out" file produced by the swipl-ld compilation. Then, i can produce this file by compiling another project (oh yeah, another totally different from my ROS node), by putting this file in the ROS node directory and by using it to initialize the engine. This works (it seems, now i'm testing hard this solution), but... ...it is a non conventional solution. What i would like to have is the compilation of the ROS node producing the a.out file (or something similar...by compiling first the ROS node with swipl-ld - this rises a problem of resource linking).

edit flag offensive delete link more

Comments

I think you can just path the path to the swipl binary, e.g. /usr/bin/swipl. All it needs is the path to a binary that contains the prolog state as far as I know. Btw. please don't open answers for new questions. Either comment or edit your original question. This site is different from forums.

Lorenz gravatar image Lorenz  ( 2012-09-06 04:20:11 -0500 )edit

Also. if my answer was correct, please mark it so (little check under the downvote button).

Lorenz gravatar image Lorenz  ( 2012-09-06 04:20:52 -0500 )edit

Sorry, it's my first post! Thank you a lot

McKracken gravatar image McKracken  ( 2012-09-06 05:06:26 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-09-06 02:38:16 -0500

Seen: 650 times

Last updated: Sep 06 '12