2

The compiler is telling that the messages (.../message.h) being not found. See my CMakeLists.txt below

cmake_minimum_required(VERSION 2.8.3)
project(my_package)
add_compile_options(-std=c++11)


find_package(catkin REQUIRED
  COMPONENTS cv_bridge
  image_transport
  roscpp
  #rospy
  sensor_msgs
  std_msgs
  message_generation
  genmsg
  external_package
  )
find_package(nodelet REQUIRED)


#----
add_message_files( FILES
  my_message1.msg
  my_message2.msg

  )

generate_messages( DEPENDENCIES
  std_msgs sensor_msgs
  )

catkin_package(
  CATKIN_DEPENDS  message_runtime std_msgs sensor_msgs roscpp cv_bridge image_transport
  )



#******     EXTRA PACKAGES
find_package(LAPACK REQUIRED)
find_package(BLAS REQUIRED)
find_package( PkgConfig REQUIRED)
FIND_PACKAGE(Boost)
find_package( OpenCV )
include_directories(${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} )

SET(MY_FLAG ok) # OR no!!

if(MY_FLAG)
#**** exe files
set(exefiles
  file1
  file2
  )

foreach(file ${exefiles})
  add_executable(${file} ${CMAKE_CURRENT_SOURCE_DIR}/pathToExeFiles/${file}.cpp ) 
endforeach(file)


#******  Lib & link
include_directories(${SRC}/pathToMyLib)
set(MY_LIB
  lib1
  lib2
  libn
  )
endif(MY_FLAG)

foreach(file ${exefiles})
  target_link_libraries(${file2link} 
    ${MY_LIB} 
    ${MY_LIB} 
    ${MY_LIB} 
    ${catkin_LIBRARIES}
    ${Boost_LIBRARIES}
    ${gsl_LIBRARIES} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}
    ${OpenCV_LIBRARIES}
    )

  add_dependencies(${file} external_package_generate_messages_cpp  ${${my_package}_EXPORTED_TARGETS})
endforeach(file)


ADD_SUBDIRECTORY(src)

However, am able to compile with the following trick. I first set My_FLAG to flase and compile. Next, I set it back to true and compile again. By doing so it works fine. But... I could guess there should be a more elegant/professional/straightforward solution. Am so far not able to detect the cause of this problem. Any solution please?

I think the issue is related to the order of the dependencies... Which? No idea...

Courier
  • 920
  • 2
  • 11
  • 36

2 Answers2

2

It looks like your EXPORTED_TARGETS dependency is wrong.

add_dependencies(${file} external_package_generate_messages_cpp  ${${my_package}_EXPORTED_TARGETS})

The ${${my_package}_EXPORTED_TARGETS} should be ${${PROJECT_NAME}_EXPORTED_TARGETS} or ${my_package_EXPORTED_TARGETS}

so:

add_dependencies(${file} external_package_generate_messages_cpp  ${${PROJECT_NAME}_EXPORTED_TARGETS})

Failing that a dependency on ${catkin_EXPORTED_TARGETS} may help.

Michael
  • 507
  • 4
  • 11
1

It looks like you are not adding message generation dependency when adding executable targets within the loop

if(MY_FLAG)
#**** exe files
set(exefiles
  file1
  file2
  )

foreach(file ${exefiles})
  add_executable(${file} ${CMAKE_CURRENT_SOURCE_DIR}/pathToExeFiles/${file}.cpp ) 
  add_dependencies(${file} external_package_generate_messages_cpp  ${${my_package}_EXPORTED_TARGETS})
endforeach(file)
....

What is most likely happening in your case is, the first run with MY_FLAG=Off you generate the messages in the second foreach where you actually add the dependencies. The second run with MY_FLAG=On works because now the messages have been already generated.

cassinaj
  • 1,043
  • 7
  • 13
  • Still the same issue. In fact, try remove both `/devel` and `/build`, then try compiling again. Or, you could try move your package out from `/catkin-dev/src/`, remove \buid and \devel, compile, then move back your project and try compiling again. In my case I had to always set the flag to flase in the first compilation.... – Courier Aug 04 '16 at 04:29
  • In fact the error is related to an issue with my sources not my exe files. In fact the flag I set also enable/disable the sources, not only the exe files. – Courier Aug 04 '16 at 04:33