首页 > 解决方案 > 在新的 Cmake 项目中使用 OPCUA 库

问题描述

这一次,我想使用Freeopcua创建一个库以在其他项目中使用。

我已经在debian.soft文件中安装了所有工具,并使用以下命令构建了sudo sh build.sh, cmake ., make, sudo make install. 虽然在目录/usr/local/include和中分别/usr/local/libopc目录和libopc*.so,但是当我创建一个新的 cmake 项目时,会出现错误。希望有人可以帮助我或提出一些建议。谢谢大家~~~

我参考了 /usr/local/lib not found中的库,但它对我不起作用

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)

project(OPCUAIndependent)

include_directories(/usr/local/include/)
link_directories(/usr/local/lib/)

add_executable(sourceCode sourceCode.cpp)

target_link_libraries(sourceCode opc)

错误

[ 50%] Linking CXX executable sourceCode
/usr/bin/ld: cannot find -lopc
collect2: error: ld returned 1 exit status
CMakeFiles/sourceCode.dir/build.make:96: recipe for target 'sourceCode' failed
make[2]: *** [sourceCode] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/sourceCode.dir/all' failed
make[1]: *** [CMakeFiles/sourceCode.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

标签: c++linuxcmakeopc-ua

解决方案


推荐阅读