Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch5 imageBasics程序make时报错 #42

Open
bene-yan opened this issue Nov 16, 2019 · 5 comments
Open

ch5 imageBasics程序make时报错 #42

bene-yan opened this issue Nov 16, 2019 · 5 comments

Comments

@bene-yan
Copy link

在做第五讲的OpenCV基本操作的实践,程序make时报错如下:

[ 50%] Building CXX object CMakeFiles/imageBasics.dir/imageBasics.cpp.o
[100%] Linking CXX executable imageBasics
/usr/bin/ld: 找不到 -lEigen3::Eigen
collect2: error: ld returned 1 exit status
CMakeFiles/imageBasics.dir/build.make:155: recipe for target 'imageBasics' failed
make[2]: *** [imageBasics] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/imageBasics.dir/all' failed
make[1]: *** [CMakeFiles/imageBasics.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

一开始有更多的类似/usr/bin/ld: 找不到 -l*** 的错误,但是通过建立相应的.so文件软链接的方式消除了。不过这个Eigen库不是没有.so文件吗,实在不知道怎么解决了。还望知道的朋友解答一下

@gaoxiang12
Copy link
Owner

你的cmakelist怎么写了?链到Eigen上去了吗?

@bene-yan
Copy link
Author

感谢高博的回复!
Eigen是只需要include_dir就行吧?我的CMakeLists.txt是这样写的:

cmake_minimum_required(VERSION 2.8)

project(imageBasics)

set(CMAKE_CXX_FLAGS "-std=c++11")

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories("/usr/include/eigen3")

add_executable(imageBasics imageBasics.cpp)

target_link_libraries(imageBasics ${OpenCV_LIBS})

我运行从您的仓库中git clone过来的代码也是报同样的错误。
另外,安装依赖项的时候,libvtk5-dev提示无法安装,我装的是libvtk6-dev。所以一开始有很多类似报错都是/usr/bin/ld: 找不到 -ltk***。不知道是不是这个原因?我安装的OpenCV 版本是3.4.7

@gaoxiang12
Copy link
Owner

你上面贴的错误和opencv应该没关系。这个cmakelist也会报eigen的链接错误吗?

@bene-yan
Copy link
Author

是的,用这个cmakelists也会报eigen的错误。然后我重新做了下ch3的useEigen,没有问题。

ch5的这个程序cmake时有一个warning,而且这个warning重复出了十多次,下面我只贴出了一段这样的waring。会不会是我的cmake的问题?

-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found version "3.4.7") 
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:13 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "imageBasics" links to target "Eigen3::Eigen" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.
【重复】

-- Generating done
-- Build files have been written to: /home/bene-robot/slambook2/ch5/imageBasics/build

@bene-yan
Copy link
Author

问题解决了!我改了cmakelist的写法,新的cmakelist如下:

cmake_minimum_required(VERSION 2.8)

project(imageBasics)

set(CMAKE_CXX_FLAGS "-std=c++11")

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

find_package(Eigen3 REQUIRED)
include_directories( EIGEN3_INCLUDE_DIRS)
#include_directories("/usr/include/eigen3")
message(${EIGEN3_INCLUDE_DIRS})

add_executable(imageBasics imageBasics.cpp)

target_link_libraries(imageBasics ${OpenCV_LIBS})

就是把#include_directories("/usr/include/eigen3")改成了

find_package(Eigen3 REQUIRED)
include_directories( EIGEN3_INCLUDE_DIRS)

是参考了这个链接https://stackoverflow.com/questions/12249140/find-package-eigen3-for-cmake

但是message输出的信息也是/usr/include/eigen3,不知道为什么直接用#include_directories("/usr/include/eigen3")就不行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants