Zunächst einmal bin ich neu in Linux und nicht so erfahren mit C++ deshalb brauche ich Ihre Hilfe.poco CMake-Datei und lokale Bibliotheken
Grundsätzlich habe ich einen Raspberry Pi mit dem neuesten RASPBIAN JESSIE Bild, auf dem ich einen WebSockets Server implementieren und einige C++ CAN-Bibliotheken integrieren muss.
Für den Server wählte ich POCO C++ - Bibliotheken. Ich habe es geschafft, einen Server einzurichten, aber jetzt muss ich die CAN- und ArduPi-Bibliotheken hinzufügen (CAN-Bibliothek ist nicht meine Schöpfung, die ich gerade erhalten habe, um einige Fehler zu beheben und sie in die Serverimplementierung zu integrieren). Zum Erstellen und Kompilieren des Servers verwende ich eine CMakeList-Datei wie hier gezeigt: link.
Die CMakeList.txt wie folgt aussieht:
#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}")
und die Ausgabe, nachdem ich machen Befehl ausführen:
[email protected]:~/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
Der Teil der Hauptdatei enthalten ist:
#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;
Von dem, was ich gelesen habe, ist es möglich, ein Problem mit der Verknüpfung zu haben, aber ich bin nicht sicher. Sollte ich CAN und ArduPi Bibliothek in cmakefile hinzufügen?
Wenn Sie weitere Informationen über den Code benötigen, sagen Sie es mir einfach.
Bestes regads, Matei
Wenn 'CAN' Bibliothek header-nur nicht, Sie müssen auf jeden Fall verbinden mit ihm' target_link_libraries mit() 'CMake Befehl. – Tsyvarev
Vielen Dank für Ihre Frage, ich hatte auch ein Problem mit POCO und Sie haben meine Nacht gerettet! – Germain