Poco cmake 文件和本地库

poco cmake file and local libraries

本文关键字:cmake 文件 Poco      更新时间:2023-10-16

首先,我是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}")

谢谢齐瓦列夫。

此致敬意马泰