CMake链接没有找到库

时间:2017-10-31 10:21:47

标签: c++ cmake

我有一个可执行文件:

add_executable(treshhold src/main.cpp)
add_dependencies(treshhold ${PROJECT_NAME})

我有一个目录

/opt/halcon/lib/x64-linux

包含多个.so文件:

hAcqArgos3D-P1xx.so    hAcqGigEVision.so    hAcqMatrixVisionAcquire.so    hAcquEye.so            hioOPC_UA.so         libhalconcpp.so    libhalcon.so             libhdevenginecpp.so
hAcqArgos3D-P1xxxl.so  hAcqGigEVisionxl.so  hAcqMatrixVisionAcquirexl.so  hAcquEyexl.so          hioOPC_UAxl.so       libhalconcppxl.so  libhalconxl.so           libhdevenginecppxl.so
hAcqFile.so            hAcqLPS36.so         hAcqO3D3xx.so                 hAcqVideo4Linux2.so    libhalconcpp10.so    libhalconc.so      libhdevenginecpp10.so    libuastack.so
hAcqFilexl.so          hAcqLPS36xl.so       hAcqO3D3xxxl.so               hAcqVideo4Linux2xl.so  libhalconcpp10xl.so  libhalconcxl.so    libhdevenginecpp10xl.so  libusb-1.0-usan.so.0

链接使用并尝试了两者:

include_directories(/opt/halcon/lib/x64-linux)
link_directories(/opt/halcon/lib/x64-linux)

但是当我尝试链接某个库

target_link_libraries(treshhold libhalconc)

我收到错误:

[ 50%] Linking CXX executable treshhold
/usr/bin/ld: cannot find -llibhalconc

如果我尝试不创建目标链接,我会从编译器中获取缺少的引用错误。

编辑完整文件:

cmake_minimum_required(VERSION 2.8.3)
project(ros_halcon_bridge)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)



add_executable(treshhold src/main.cpp)
add_dependencies(treshhold ${PROJECT_NAME})
include_directories(/opt/halcon/lib/x64-linux)
link_directories(/opt/halcon/lib/x64-linux)
target_link_libraries(treshhold libhalconc)

EDIT2 我想用以下内容添加所有库:

target_link_libraries(treshhold hAcqArgos3D-P1xx.so hAcqGigEVision.so hAcqMatrixVisionAcquire.so hAcquEye.so hioOPC_UA.so libhalconcpp.so libhalcon.so libhdevenginecpp.so hAcqArgos3D-P1xxxl.so hAcqGigEVisionxl.so hAcqMatrixVisionAcquirexl.so hAcquEyexl.so hioOPC_UAxl.so libhalconcppxl.so libhalconxl.so libhdevenginecppxl.so hAcqFile.so hAcqLPS36.so hAcqO3D3xx.so hAcqVideo4Linux2.so libhalconcpp10.so libhalconc.so libhdevenginecpp10.so libuastack.so hAcqFilexl.so hAcqLPS36xl.so hAcqO3D3xxxl.so hAcqVideo4Linux2xl.so libhalconcpp10xl.so libhalconcxl.so libhdevenginecpp10xl.so libusb-1.0-usan.so.0)

但结果是:

[ 50%] Linking CXX executable treshhold
/usr/bin/ld: cannot find -lhAcqArgos3D-P1xx
/usr/bin/ld: cannot find -lhAcqGigEVision
/usr/bin/ld: cannot find -lhAcqMatrixVisionAcquire
/usr/bin/ld: cannot find -lhAcquEye
/usr/bin/ld: cannot find -lhioOPC_UA
/usr/bin/ld: cannot find -lhalconcpp
/usr/bin/ld: cannot find -lhalcon
/usr/bin/ld: cannot find -lhdevenginecpp
/usr/bin/ld: cannot find -lhAcqArgos3D-P1xxxl
/usr/bin/ld: cannot find -lhAcqGigEVisionxl
/usr/bin/ld: cannot find -lhAcqMatrixVisionAcquirexl
/usr/bin/ld: cannot find -lhAcquEyexl
/usr/bin/ld: cannot find -lhioOPC_UAxl
/usr/bin/ld: cannot find -lhalconcppxl
/usr/bin/ld: cannot find -lhalconxl
/usr/bin/ld: cannot find -lhdevenginecppxl
/usr/bin/ld: cannot find -lhAcqFile
/usr/bin/ld: cannot find -lhAcqLPS36
/usr/bin/ld: cannot find -lhAcqO3D3xx
/usr/bin/ld: cannot find -lhAcqVideo4Linux2
/usr/bin/ld: cannot find -lhalconcpp10
/usr/bin/ld: cannot find -lhalconc
/usr/bin/ld: cannot find -lhdevenginecpp10
/usr/bin/ld: cannot find -luastack
/usr/bin/ld: cannot find -lhAcqFilexl
/usr/bin/ld: cannot find -lhAcqLPS36xl
/usr/bin/ld: cannot find -lhAcqO3D3xxxl
/usr/bin/ld: cannot find -lhAcqVideo4Linux2xl
/usr/bin/ld: cannot find -lhalconcpp10xl
/usr/bin/ld: cannot find -lhalconcxl
/usr/bin/ld: cannot find -lhdevenginecpp10xl
/usr/bin/ld: cannot find -lusb-1.0-usan

1 个答案:

答案 0 :(得分:0)

你可以看到CMake正在做什么

make VERBOSE=1

然后你应该能够找出生成的命令有什么问题。

只有在确定了您真正想要的命令之后,如果您打算如何使用cmake正确编写它,