Reputation: 41
First of all, I am new in Linux and not so experienced with C++ this is why I need your help.
Basically, I have a Raspberry Pi with the latest RASPBIAN JESSIE image on which I have to implement a websockets server and integrate some C++ CAN library.
For the server, I chose to use POCO C++ Libraries. I managed to set up a server but now I have to include the CAN and ArduPi libraries( CAN library is not my creation I just received to fix some bugs and to integrate it in the server implementation). To build and compile the server I use a CMakeList file as sown here: link.
The CMakeList.txt
looks like:
#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}")
And the output after I execute make command:
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
The include part of the main file is:
#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;
From what I have read it is possible to have some problems with the linking but I am not sure. Should I add CAN and ArduPi library in cmakefile?
If you need more information about the code just tell me.
Best regards,
Upvotes: 2
Views: 2574
Reputation: 41
Problem solved, I've modified the make file by adding the CAN and arduPi libraries and linked them to the main file.
This is how it looks like the file:
#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}")
Thank you Tsyvarev.
Best regards, Matei
Upvotes: 2