Reputation: 43
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?
Upvotes: 1
Views: 2191
Reputation: 7156
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
Upvotes: 0
Reputation: 1607
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.
Upvotes: 1