1

I'm working on knowrob package and I already wrote my ontology(XML file) with Protege. If I parse the owl.file and send some queries I have right answers. Now my problem is to make a cpp to parse my xml file. I already read something about json_prolog to send queries from my program to knowrob but is too muddler(http://www.knowrob.org/doc/interact_with_knowrob_via_ros). I create my launch file and it works,later when i try to compile this cpp file:

#include <string>
#include <ros/ros.h>
#include <json_prolog/prolog.h>
using namespace std;
using namespace json_prolog;
int main(int argc, char *argv[])
{
    ros::init(argc, argv, "test_json_prolog");
    Prolog pl;
    PrologQueryProxy bdgs = pl.query("member(A, [1, 2, 3, 4]), B = ['x', A],             C = foo(bar, A, B)");

    for(PrologQueryProxy::iterator it=bdgs.begin();

    it != bdgs.end(); it++)
    {
        PrologBindings bdg = *it;
        cout << "Found solution: " << (bool)(it == bdgs.end()) << endl;
        cout << "A = "<< bdg["A"] << endl;
        cout << "B = " << bdg["B"] << endl;
        cout << "C = " << bdg["C"] << endl;
    }
    return 0;
}code here

I have the error:

/tmp/cccLQk3H.o:test_json_prolog.cpp:function main: error: undefined reference to 'ros::init(int&, char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'

and other similar error about the undefined reference.

CMakelist :

cmake_minimum_required(VERSION 2.8.3)
project(json_prolog)
find_package(catkin REQUIRED rosjava_build_tools roscpp rospy json_prolog_msgs)
catkin_rosjava_setup(installApp publishMavenJavaPublicationToMavenRepository writeClasspath)
install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/knowrob/${PROJECT_NAME}/
    DESTINATION ${CATKIN_GLOBAL_MAVEN_DESTINATION}/org/knowrob/${PROJECT_NAME})
catkin_package(INCLUDE_DIRS include LIBRARIES json_prolog CATKIN_DEPENDS json_prolog_msgs )


# find SWI Prolog libraries
include(FindPkgConfig)
pkg_check_modules(SWIPL REQUIRED swipl)
include_directories(${SWIPL_INCLUDE_DIRS})
link_directories(${SWIPL_LIBRARY_DIRS})

# export Python libraries
catkin_python_setup()

# C++ client library

include_directories(include ${catkin_INCLUDE_DIRS})
find_package(PkgConfig)
pkg_check_modules(JSON_GLIB REQUIRED json-glib-1.0)
add_definitions(${JSON_GLIB_CFLAGS})
link_directories(${JSON_GLIB_LIBRARIY_DIRS})

How can I solve it?

Derzu
  • 7,011
  • 3
  • 57
  • 60
  • I'd start with printing the value of `catkin_LIBRARIES` to check if `find_package()` was successful or not. Also, this library seems to have a custom Cmake macro `catkin_package()` and it's written that it must be called before passing any info to the build. Have you called it? – Baris Demiray May 22 '15 at 08:26
  • no,i think no. So first of all: how i can check the catkin_LIBRARIES to print you the results? P.S. sorry but i'm a new ubuntu user :) – Marcello Chiurazzi May 22 '15 at 08:36
  • You can print it by calling `message(STATUS ${catkin_LIBRARIES})` in your CMakeLists.txt file – Baris Demiray May 22 '15 at 08:37
  • maybe i'm doing it in a wrong way; in terminal in the folder in which i have the CMakeList.txt? In this case: bash: syntax error near unexpected token `STATUS' – Marcello Chiurazzi May 22 '15 at 08:39
  • Ah no it should go into your `CMakeListst.txt` file, preferably right before `target_link_libraries()` call, then when you do `cmake .` it'll run with other Cmake commands. – Baris Demiray May 22 '15 at 08:44
  • These lines are already available in your question, you don't need to put them again. Can you just put `message(STATUS ${catkin_LIBRARIES})` before the call to `target_link_libraries()` and re-run Cmake? – Baris Demiray May 22 '15 at 09:07
  • `# C++ client library include_directories(include ${catkin_INCLUDE_DIRS}) find_package(PkgConfig) pkg_check_modules(JSON_GLIB REQUIRED json-glib-1.0) add_definitions(${JSON_GLIB_CFLAGS}) link_directories(${JSON_GLIB_LIBRARIY_DIRS}) add_library(json_prolog src/prolog.cpp src/prolog_query_proxy.cpp src/prolog_bindings.cpp src/prolog_value.cpp)` – Marcello Chiurazzi May 22 '15 at 09:19
  • I think I'll just write up an answer to have more space for what I mean and hopefully to be more clear. – Baris Demiray May 22 '15 at 09:37
  • ok thanks anyway i edited the post with the full CmakeList.txt – Marcello Chiurazzi May 22 '15 at 09:52

2 Answers2

1

You should start investigating with checking if your call to find_package() (you called find_package(), right?) was successful, so change the snippet you added in your question by adding a debug line,

message(STATUS ${catkin_LIBRARIES})

add_executable(test_json_prolog examples/test_json_prolog.cpp)
target_link_libraries(test_json_prolog json_prolog ${catkin_LIBRARIES})
add_dependencies(test_json_prolog ${catkin_EXPORTED_TARGETS})

Call to message should be printing the libraries you meant to link to.

Besides, see this page if you haven't already, http://wiki.ros.org/catkin/CMakeLists.txt. There they mention a custom macro that you MUST call, i.e. catkin_package(). Also the sections 6, 7, and 8 are all linked to your problem I guess.

Baris Demiray
  • 1,539
  • 24
  • 35
0

You can try to compile it directly using g++ compiler.

Please check this answer: Compile roscpp without ros (using g++)

There a source code is compiled without cmake or catkin_make

Derzu
  • 7,011
  • 3
  • 57
  • 60