Ask Your Question
0

Catkin doesn't works with Bison

asked 2015-12-23 03:36:09 -0500

Leontes gravatar image

Hello I'm having issues trying to compile a little program with a CMakeList that uses a Bison/Flex parser.

When I use catkin the system gives me the following error:

####
#### Running command: "make -j2 -l2" in "/home/leontes/Dropbox/ros_ws/build"
####
[  1%] [BISON][parser] Building parser with bison 3.0.2
Scanning dependencies of target task_executor
make[2]: *** No hay ninguna regla para construir el objetivo «../htn_planner/src/parser.hpp», necesario para «ROSbtp/task_executor/CMakeFiles/task_executor.dir/__/htn_planner/src/lexer.cpp.o».  Alto.
make[2]: *** Se espera a que terminen otras tareas....
[  2%] Building CXX object ROSbtp/task_executor/CMakeFiles/task_executor.dir/__/htn_planner/src/parser.cpp.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
In file included from ../htn_planner/yacc/parser.yy:35:0:
/home/leontes/Dropbox/ros_ws/src/ROSbtp/task_executor/../htn_planner/include/sortgoal.hh: In member function ‘bool CriteriaF::operator()(Unifier*, Unifier*) const’:
/home/leontes/Dropbox/ros_ws/src/ROSbtp/task_executor/../htn_planner/include/sortgoal.hh:68:30: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]
  criteriacit i = f->begin(), e = f->end();
                              ^
make[1]: *** [ROSbtp/task_executor/CMakeFiles/task_executor.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j2 -l2" failed

Catkin launchs Bison, Bison generates parser.cpp and parser.hpp but catkin insists that theres no rule to build that parser.hpp file. And of course I delete this files catkin not even launchs the compilation.

The CMakeLists that I've writed is this:

cmake_minimum_required(VERSION 2.8.12)
project(task_executor)

find_package(catkin REQUIRED cmake_modules)

catkin_package(
   INCLUDE_DIRS include
   LIBRARIES ${PROJECT_NAME})

#Set headers directory
include_directories("include" "../htn_planner/include")

#Set source files
file(GLOB SOURCES "../htn_planner/src/*.cpp")
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../htn_planner/src/parser.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../htn_planner/src/parser.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/../htn_planner/src/lexer.cpp")

#Build commands for Flex and Bison
find_package(FLEX)
find_package(BISON)

FLEX_TARGET(lexer  ../htn_planner/yacc/lexer.ll ../htn_planner/src/lexer.cpp)
BISON_TARGET(parser ../htn_planner/yacc/parser.yy ../htn_planner/src/parser.cpp)


ADD_FLEX_BISON_DEPENDENCY(lexer parser)

#Add a binary executable
add_executable(task_executor nodes/task_executor.cpp ../htn_planner/planner_api/planner_api.cpp ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS} ${SOURCES})
target_link_libraries(task_executor readline ${EXTRALIBS} ${PYTHON_EXTRA_LIBS} ${catkin_LIBRARIES})

I don't know what to do, I'm run out of ideas...

edit retag flag offensive close merge delete

Comments

Just a note: catkin is essentially CMake. When you write "Catkin launchs Bison [..]", it should really be "CMake launches Bison". This may seem pedantic, but it will make searching for potential solutions much easier, as the CMake community is much larger than that of catkin.

gvdhoorn gravatar image gvdhoorn  ( 2015-12-23 05:14:08 -0500 )edit

Nope, the problem is with Catkin and how it resolves dependencies and execute the packages. The same Cmakelist (without the catkin directives) works fine when run as a standalone proyect.

Leontes gravatar image Leontes  ( 2015-12-23 06:34:32 -0500 )edit

Can you try and see whether using absolute paths works? You can prefix the paths to ../htn_planner with ${CMAKE_CURRENT_SOURCE_DIR}.

gvdhoorn gravatar image gvdhoorn  ( 2015-12-23 07:34:29 -0500 )edit

@Leontes can you expand on why you think it is related to how catkin handles resolving dependencies or "execute the packages"? Based on that I have no idea what may be the source of the issue. I don't see anything in the above CMakeLists.txt which would lead me to believe it is a catkin problem.

William gravatar image William  ( 2015-12-23 07:41:46 -0500 )edit

On further inspection I think I noticed an issue, and I posted an answer.

William gravatar image William  ( 2015-12-23 07:47:19 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2015-12-23 07:46:02 -0500

William gravatar image

You don't seem to have a declared dependency between the task_executor target (created with add_executable) and the targets for generating the files with flex and bison. My guess is that running catkin_make -j1 ... would possibly work around the issue, and that adding a line like add_dependencies(task_executor lexer parser) would fix the problem for multi-threaded builds.

If that doesn't work, you mentioned that as a normal CMake package it worked. Could you post that CMake project? Can you try building that CMake project with make -j2 to see if you can reproduce the issue with the plain CMake project?

It seems to me that the most likely cause is that catkin_make defaults -jN where N is the number of cores on your computer, but you didn't do that when running cmake/make manually.

Hopefully that helps,

edit flag offensive delete link more

Comments

That was my first thought as well, but the "No hay ninguna regla para construir el objetivo [..] parser.hpp [..] necesario para [..] parser.cpp.o" seems to suggest that make can't figure out where to find parser.hpp ("no rule to make target .."). That would suggest something else.

gvdhoorn gravatar image gvdhoorn  ( 2015-12-23 08:02:36 -0500 )edit

"No rule to make target..." implies two things: the file doesn't exist, and make doesn't have a rule to create it. (if the file already existed, make wouldn't need a rule). I would think that the bison command would declare two output files, but it appears to only declare that it creates the .cpp.

ahendrix gravatar image ahendrix  ( 2015-12-23 10:32:41 -0500 )edit

When I compile the program with the original CMake I usually use make -j8 and it works fine. I fix the problem setting manually parser.cpp parser.h and lexer.cpp in the src or include directories, deleting the Bison/Flex directives and compiling as usual.

Leontes gravatar image Leontes  ( 2015-12-23 11:58:49 -0500 )edit

The add_dependencies(task_executor lexer parser) fix doesn't works. Same error with parser.hpp.

Leontes gravatar image Leontes  ( 2015-12-23 12:00:07 -0500 )edit

@Leontes: I wouldn't call that a 'fix', more a workaround.

gvdhoorn gravatar image gvdhoorn  ( 2015-12-24 02:33:58 -0500 )edit

@gvdhoorn You are right, but I can't lose so much time trying to figure why the dependencies aren't resolved before catkin builds task_executor and the generation of these files It's a minor feature that a want to add to the CmakeList. There's no problem if can't include the Bison/Flex directives.

Leontes gravatar image Leontes  ( 2015-12-24 03:15:29 -0500 )edit

Another workaround to try might be to move the FLEX_TARGET and BISON_TARGET above the catkin_package call. The theory being that catkin_package changes the EXECUTABLE_OUTPUT_PATH which might be affecting flex/bison's generation.

William gravatar image William  ( 2015-12-24 11:49:34 -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: 2015-12-23 03:36:09 -0500

Seen: 218 times

Last updated: Dec 23 '15