Poco cmake 文件和本地库
poco cmake file and local libraries
首先,我是Linux新手,对C++没有经验,这就是为什么我需要你的帮助。
基本上,我有一个带有最新RASPBIAN JESSIE映像的Raspberry Pi,我必须在其上实现Websockets服务器并集成一些C++CAN库。
对于服务器,我选择使用 POCO C++库。我设法设置了一个服务器,但现在我必须包含CAN和ArduPi库(CAN库不是我刚刚收到的修复一些错误并将其集成到服务器实现中的创作)。为了构建和编译服务器,我使用了一个CMakeList文件,如下所示:链接。
CMakeList.txt
如下所示:
#Ref http://stackoverflow.com/questions/30114662/clion-cmake-and-poco
cmake_minimum_required(VERSION 3.3)
project(PoCoWebSocketTest)
# define the project
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lrt -lpthread")
set(SOURCE_FILES main.cpp)
add_executable(PoCoWebSocketTest ${SOURCE_FILES})
# set the POCO paths and libs
set(POCO_PREFIX "/usr/local") # the directory containing "include" and "lib"
set(POCO_INCLUDE_DIR"${POCO_PREFIX}/include")
set(POCO_LIB_DIR "${POCO_PREFIX}/lib")
set(POCO_LIBS
"${POCO_LIB_DIR}/libPocoNet.so"
"${POCO_LIB_DIR}/libPocoUtil.so"
"${POCO_LIB_DIR}/libPocoFoundation.so")
# set the include path for the app
target_include_directories(PoCoWebSocketTest PRIVATE $(POCO_INCLUDE_DIR))
# link the app against POCO
target_link_libraries(PoCoWebSocketTest "${POCO_LIBS}")
而我执行 make 命令后的输出:
pi@raspberrypi:~/pocotests/build $ sudo make
[ 50%] Building CXX object CMakeFiles/PoCoWebSocketTest.dir/main.cpp.o
[100%] Linking CXX executable PoCoWebSocketTest
CMakeFiles/PoCoWebSocketTest.dir/main.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x154): undefined reference to `CAN::CAN()'
collect2: error: ld returned 1 exit status
CMakeFiles/PoCoWebSocketTest.dir/build.make:97: recipe for target 'PoCoWebSocketTest' failed
make[2]: *** [PoCoWebSocketTest] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/PoCoWebSocketTest.dir/all' failed
make[1]: *** [CMakeFiles/PoCoWebSocketTest.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
主文件的包含部分是:
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/WebSocket.h"
#include "Poco/Net/NetException.h"
#include "Poco/Util/ServerApplication.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Format.h"
#include <iostream>
#include "arduPi.h"
#include "CAN.h"
using Poco::Net::ServerSocket;
using Poco::Net::WebSocket;
using Poco::Net::WebSocketException;
using Poco::Net::HTTPRequestHandler;
using Poco::Net::HTTPRequestHandlerFactory;
using Poco::Net::HTTPServer;
using Poco::Net::HTTPServerRequest;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPServerResponse;
using Poco::Net::HTTPServerParams;
using Poco::Timestamp;
using Poco::ThreadPool;
using Poco::Util::ServerApplication;
using Poco::Util::Application;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter;
从我所读到的内容来看,链接可能会出现一些问题,但我不确定。我应该在cmakefile中添加CAN和ArduPi库吗?
如果您需要有关代码的更多信息,请告诉我。
此致敬意
问题解决了,我通过添加CAN和arduPi库并将它们链接到主文件来修改make文件。
这是文件的外观:
#Ref http://stackoverflow.com/questions/30114662/clion-cmake-and-poco
cmake_minimum_required(VERSION 3.3)
project(WebSocketServerCPP)
# define the project
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lrt -lpthread")
set(SOURCE_FILES main.cpp)
add_executable(WebSocketServerCPP ${SOURCE_FILES})
# set the POCO paths and libs
set(POCO_PREFIX "/usr/local") # the directory containing "include" and "lib"
set(POCO_INCLUDE_DIR"${POCO_PREFIX}/include")
set(POCO_LIB_DIR "${POCO_PREFIX}/lib")
set(POCO_LIBS
"${POCO_LIB_DIR}/libPocoNet.so"
"${POCO_LIB_DIR}/libPocoUtil.so"
"${POCO_LIB_DIR}/libPocoFoundation.so")
add_library(libcan STATIC CAN.cpp)
add_library(libardupi STATIC arduPi.cpp)
# set the include path for the app
target_include_directories(WebSocketServerCPP PRIVATE $(POCO_INCLUDE_DIR))
# link the app against POCO
target_link_libraries(libcan libardupi)
target_link_libraries(WebSocketServerCPP libcan)
target_link_libraries(WebSocketServerCPP libardupi)
target_link_libraries(WebSocketServerCPP "${POCO_LIBS}")
谢谢齐瓦列夫。
此致敬意马泰
相关文章:
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 我应该安装 .cmake 文件来共享/cmake 还是 lib/cmake?
- cmake 可以包含具有头文件和库文件但没有 .cmake 文件的库吗?
- 隐蔽的 gcc 参数到 CMake 文件
- 如何在Windows上链接动态构建的cmake文件
- C++ : "undefined reference to"可能是因为CMake文件
- 更改 Cmake 文件以从源代码编译依赖项,而不是使用 FIND_PACKAGE
- 从 cmake 文件运行 npm 命令
- 我被困在尝试克隆需要 cmake 文件和依赖项的 git 存储库中
- 如何将G 和GTEST集成到一个CMAKE文件中
- 当我构建和编译我的C 项目时,没有通过我的CMake文件找到正确的C 库,我在做什么错
- 我如何配置我的cmake文件以与Google Test和CTEST一起使用
- 如何从现有的生成文件创建 CMake 文件?
- 如何在 c++ 中使用单例模式时编写 cmake 文件
- 如何为模块化项目正确创建 CMake 文件
- 如何使用jhbuild没有CMAKE文件来构建图书馆
- 构建块的Cmake(文件夹包含源)
- 在cmake中,cmake文件夹和CMakeLists.txt可以位于不同的文件夹中
- cmake 文件生成 -- 一种更优雅的选择
- 从CMake文件生成Embarcadero项目文件