LoginSignup
1
0

More than 3 years have passed since last update.

catkin buildの際のCMakeエラー集

Last updated at Posted at 2020-10-27

経緯

最近、CMakeLists.txtを自分で書いたりするのですが、その際にエラーに割と出くわすので、自分が出くわしたエラーとその対処法をまとめようと思います。エラーに出くわすたびに随時更新していきます。同じエラーに出くわした方が、無駄な時間を過ごさないことを願います。

1. CMakeList.txt内のコマンドの順番違い

catkin build パッケージ名

上のコマンドを打つと、下のようなエラーが発生しました。

Errors     << sample2:cmake /home/nvidia/catkin_ws/logs/sample2/build.cmake.002.log
CMake Error at /home/nvidia/catkin_ws/devel/share/sample1/cmake/sample1Config.cmake:173 (message):
  Project 'sample2' tried to find library 'sample1_lib'.  The library is
  neither a target nor built/installed properly.  Did you compile project
  'sample1'? Did you find_package() it before the subdirectory containing
  its code is included?
Call Stack (most recent call first):
  /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:76 (find_package)
  CMakeLists.txt:17 (find_package)

これは、sample2というパッケージ内で、sample1_libを使おうとしているのですが、見つからないよと言っています。sample1のCMakeLists.txtで、catkin_package()でライブラリをexportしたはずなのですが、sample2で見つからないと言われたので、ちょっとハマってしまいました。
原因は、CMakeLists.txtにはビルドする上で、各コマンドに順番があるためでした。下のような順番に従わないといけません。自分の場合は、add_library()の後に、catkin_package()を書いてしまっていたので、エラーになっていました。書き方の詳細はこちらに書いてあります。
Screenshot from 2020-10-27 21-37-40.png

間違いや質問、ご意見等ありましたらお気軽にコメントください。頑張って答えますので(笑)。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0