24
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MacでPCLビルドエラーへの対処[ld: library not found for]

Last updated at Posted at 2019-04-21

TL;DR

パス通す

~/bashrc
export LIBRARY_PATH=/usr/local/Cellar/flann/1.9.1_7/lib/

はじめに

Macbook Proにインストールして満足していたPCL.

「さあ使うぞ!」

と思い立って作成してあったプロジェクトをビルドすることにした.
cmakeは無事に通り,次にmakeを実行した際に,今まで見たこともないエラーが出てきた.

今回は-lflannに対して問題を解決したが,他の

ld: library not found for -l*

とMacに言われた全ての方に役立つと思う.

しかし,ゴリ押しで解決したため,他の良い方法があれば教えていただけるととても嬉しい.

問題

実際のmakeコマンドにたいする出力は,

makeの出力
[ 50%] Linking CXX executable proj
ld: library not found for -lflann
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [proj] Error 1
make[1]: *** [CMakeFiles/proj.dir/all] Error 2
make: *** [all] Error 2

と出てきた.

ld: library not found for -lflann

とあり,どうやらflannライブラリが見つからないらしい・・・

対処

  • まずはmakeを最新版に更新したり,flannを再インストールしたりと試した.失敗.
  • 再起動を試した.失敗.
  • 手動でライブラリを追加.成功.

上記の方法を試したうち,成功した方法のみを記載する.

方法

ライブラリ名はgslであるが,同じ問題を解決しているページを発見した.この手法を試した.

まずは,flannの場所を確認.
2通りの方法を記載したが,前者はPermission deniedなども表示されるため,後者が好ましい.

find flann
$ find / -name flann
$ find / -name flann 2>/dev/null

これを確認すると,

flannの場所を探す
$ find / -name flann 2>/dev/null
/usr/local/include/flann
/usr/local/var/homebrew/linked/flann
/usr/local/opt/flann
/usr/local/Cellar/flann
/usr/local/Cellar/flann/1.9.1_7/include/flann
/Users/username/Library/Logs/Homebrew/flann

これを確認して,

$ export LIBRARY_PATH=/usr/local/Cellar/flann/1.9.1_7/lib/

とパスに追加する.

ビルド確認
$ make
[ 50%] Linking CXX executable proj
[100%] Built target proj

毎回export ~を入力するのは面倒であるため,~/.bash_profileに以下を追記

~/.bash_profile
export LIBRARY_PATH=/usr/local/Cellar/flann/1.9.1_7/lib/

これで,エラーとはおさらばっ!

おわりに

解決はしたのだが,一つ謎が残った.

後から見直すと,cmakemakeを繋げて行うと以下になり,

error
-- Eigen found (include: /usr/local/include/eigen3, version: 3.3.7)
-- Boost version: 1.69.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   thread
--   date_time
--   iostreams
--   serialization
--   chrono
--   atomic
--   regex
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
** WARNING ** io features related to libusb-1.0 will be disabled
-- QHULL found (include: /usr/local/include, lib: optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib)
-- Found Glew: GLEW;-framework Cocoa
-- looking for PCL_COMMON
-- looking for PCL_KDTREE
-- looking for PCL_OCTREE
-- looking for PCL_SEARCH
-- looking for PCL_SAMPLE_CONSENSUS
-- looking for PCL_FILTERS
-- looking for PCL_2D
-- looking for PCL_GEOMETRY
-- looking for PCL_IO
-- looking for PCL_FEATURES
-- looking for PCL_ML
-- looking for PCL_SEGMENTATION
-- looking for PCL_VISUALIZATION
-- looking for PCL_SURFACE
-- looking for PCL_REGISTRATION
-- looking for PCL_KEYPOINTS
-- looking for PCL_TRACKING
-- looking for PCL_RECOGNITION
-- looking for PCL_STEREO
-- looking for PCL_APPS
-- looking for PCL_OUTOFCORE
-- looking for PCL_PEOPLE
-- looking for PCL_SIMULATION
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/username/pcl/project/build
[ 50%] Linking CXX executable proj
ld: library not found for -lflann
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [proj] Error 1
make[1]: *** [CMakeFiles/proj.dir/all] Error 2
make: *** [all] Error 2

となる.cmakeに対して,

-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)

flann見つけたよと書かれているのに,
makeに対しては

ld: library not found for -lflann

-lflannないよと言われている.謎である.

24
15
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
24
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?