catkin_make无法创建可执行文件并自动将头文件复制到开发 [英] catkin_make unable to create executable and automatically copy header files to devel

查看:743
本文介绍了catkin_make无法创建可执行文件并自动将头文件复制到开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行catkin_make时,我知道它应该自动将我包含在主cpp文件中的头文件复制到devel中并创建一个可执行文件,但是,它没有这样做。

when I ran my catkin_make, I understand that it should automatically copy the header files which I included in the main cpp file into devel and create an executable, however, it is not doing so.

错误:

Linking CXX executable /home/catkin_ws/devel/lib/mqtt_pub/mqtt_pub_node
/usr/bin/ld: cannot find -lmosquitto.h
collect2: error: ld returned 1 exit status
make[2]: *** [/home/catkin_ws/devel/lib/mqtt_pub/mqtt_pub_node] Error 1
make[1]: *** [mqtt_pub/CMakeFiles/mqtt_pub_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j1 -l1" failed

请注意,mqtt_pub_node不不存在。为什么要寻找不存在的东西?它应该是自动创建的。据我所知,可执行文件应该位于devel / lib / mqtt_pub中,不确定系统在哪里考虑mqtt_pub_node(directory)。如果我创建目录mqtt_pub_node并将其头文件放入其中,则catkin_make成功,但不会创建可执行文件。

Note that mqtt_pub_node doesn't exist. Why is it looking for something that doesn't exist? It should be automatically created. From what I know, the executable should be in devel/lib/mqtt_pub, not sure where did the system think about mqtt_pub_node(directory). If I create the dir mqtt_pub_node and put my header file in it, the catkin_make is successful, but the executable would not be created.

头文件应该复制到devel / include中,但是在我的catkin_ws上,没有这样的目录。

The header files should be copied into devel/include, but on my catkin_ws, there is no such directory.

Cmakelist

Cmakelist

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES mqtt_pub
  CATKIN_DEPENDS roscpp std_msgs
  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  /catkin_ws/src/mqtt_pub/include/mqtt_pub
  include
)

link_directories(
  /catkin_ws/src/mqtt_pub/include/mqtt_pub
)

link_libraries(
  mosquitto.h
)

add_executable(mqtt_pub_node src/mqtt_publish.cpp)
target_link_libraries(mqtt_pub_node ${catkin_LIBRARIES})

感谢您的指导,谢谢!

Would appreciate the guidance, thanks!

cassinaj提供的解决方案出错

Error from the solution given by cassinaj

CMakeFiles/mqtt_pub_node.dir/src/mqtt_publish.cpp.o: In function `main':
mqtt_publish.cpp:(.text+0x1f8): undefined reference to `mosquitto_lib_init'
mqtt_publish.cpp:(.text+0x210): undefined reference to `mosquitto_new'
mqtt_publish.cpp:(.text+0x237): undefined reference to   `mosquitto_username_pw_set'
mqtt_publish.cpp:(.text+0x259): undefined reference to `mosquitto_connect'
mqtt_publish.cpp:(.text+0x285): undefined reference to `mosquitto_loop_start'
mqtt_publish.cpp:(.text+0x2bc): undefined reference to `mosquitto_publish'
mqtt_publish.cpp:(.text+0x2d0): undefined reference to `mosquitto_loop_stop'
mqtt_publish.cpp:(.text+0x2df): undefined reference to `mosquitto_disconnect'
mqtt_publish.cpp:(.text+0x2ee): undefined reference to `mosquitto_destroy'
mqtt_publish.cpp:(.text+0x2f3): undefined reference to `mosquitto_lib_cleanup'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/lorawan/catkin_ws/devel/lib/mqtt_pub/mqtt_pub_node] Error 1
make[1]: *** [mqtt_pub/CMakeFiles/mqtt_pub_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j1 -l1" failed


推荐答案

已解决。使用Mosquitto时,我必须在CMakeList中链接客户端库。基本上是libmosquitto.so文件,它是客户端库。

Solved. When using Mosquitto, I had to link the client library in my CMakeList. Basically the libmosquitto.so file, which is the client library.

我在cmake列表中添加了以下内容:

I added the following to my cmake list:

set(Mosquitto_libs
  /usr/lib/x86_64-linux-gnu/libmosquitto.so
  /usr/lib/x86_64-linux-gnu/libmosquitto.so.1
)
target_link_libraries(mqtt_pub_node ${catkin_LIBRARIES} ${Mosquitto_libs})

这篇关于catkin_make无法创建可执行文件并自动将头文件复制到开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆