0

I have an issue, when I'm trying to build an app using toolchain for RPi. Toolchain is installed with tutorial from git repository. Also there is OpenCV 3.4.1. I will put here code from my file cpp and cmakelists files.

myClient.cpp:

#include <sys/socket.h>
#include "opencv2/opencv.hpp"
#include <arpa/inet.h>
#include <net/if.h>
#include <unistd.h>
#include <string.h>
#include <cstdlib>
#include <pthread.h>

void run();
void * capture(void *);

int main()
{
    run();
}

void run()
{
    int sockSystemCall, acceptSystemCall,
                bindSystemCall, portNumber;
    char buffer[256];
    pthread_t thread_id;
    struct sockaddr_in serverAddress, clientAddress;
    int clientAddSize;

    portNumber = 3305;

    sockSystemCall = socket(AF_INET, SOCK_DGRAM, 0);

    if(sockSystemCall < 0)
        exit(0);

    // sin_family contains code for address family
    serverAddress.sin_family = AF_INET;
    // sin_addr.s_addr contains ip address
    serverAddress.sin_addr.s_addr = INADDR_ANY;
    // sin_port contains port number
    serverAddress.sin_port = htons(portNumber);

    // bind the server and check if it runs
    bindSystemCall = bind(sockSystemCall, (struct sockaddr *) &serverAddress,
            sizeof(serverAddress) );

    if(bindSystemCall < 0)
        exit(0);

    // listen for connections
    listen(sockSystemCall, 5);

    // accept first incoming and exit if there is an issue
    clientAddSize = sizeof(clientAddress);
    acceptSystemCall = accept(sockSystemCall, (struct sockaddr *) &clientAddress,
                                        (socklen_t *)&clientAddSize);

    if(acceptSystemCall < 0)
        exit(0);

    pthread_create( &thread_id, nullptr, capture, &acceptSystemCall);
}

void * capture(void * pointer)
{
    int serverFor = *(int *)pointer;
    int rows, columns;
    int numberOfDevice = 0;
    cv::VideoCapture captureDevice(numberOfDevice);

    // now it will gain data from camera and send it to server 
    cv::Mat image, grayImage;

    rows = 640;
    columns = 480;
    // CV_8UC1 because i will use utf-8
    image = cv::Mat::zeros(rows, columns, CV_8UC1);

    if( !image.isContinuous() )
        image = image.clone();

    size_t imgSize = image.total() * image.elemSize();
    ssize_t bytes;

    while( true )
    {
        captureDevice >> image;

        cvtColor(image, grayImage, CV_BGR2GRAY);

        bytes = send(serverFor, grayImage.data, imgSize, 0);

        if( bytes < 0 )
            break;
    }

}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.6)# CMake version check
project(clientRPi)                 # Create project
set(CMAKE_CXX_STANDARD 11)         # Enable c++11 standard

set(SOURCE_FILES myClient.cpp)     # Add myClient.cpp file of project root
                                   #directory as source file
add_executable(clientRPi ${SOURCE_FILES}) # Add executable target with source
                                            #files listed in SOURCE_FILES variable

find_package(Threads)
target_link_libraries(clientRPi ${CMAKE_THREAD_LIBS_INIT})

find_package(OpenCV REQUIRED)
target_link_libraries(clientRPi ${OpenCV_LIBS})

# specify system version
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

# Specify the cross compiler
SET(CMAKE_C_COMPILER $ENV{HOME}/Development/toolchains/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/Development/toolchains/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++)

# Where is the target environment
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/Development/toolchains/rootfs)

# Search for programs only in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# Search for libraries and headers only in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

and text of an issue is here:
[ 50%] Building CXX object CMakeFiles/clientRPi.dir/myClient.cpp.o<br/> [100%] Linking CXX executable clientRPi<br/> /usr/local/lib/libopencv_stitching.so.3.4.1: file not recognized: Nieznany format pliku<br/> collect2: error: ld returned 1 exit status<br/> CMakeFiles/clientRPi.dir/build.make:128: recipe for target 'clientRPi' failed<br/> make[3]: *** [clientRPi] Error 1<br/> CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/clientRPi.dir/all' failed<br/> make[2]: *** [CMakeFiles/clientRPi.dir/all] Error 2<br/> CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/clientRPi.dir/rule' failed<br/> make[1]: *** [CMakeFiles/clientRPi.dir/rule] Error 2<br/> Makefile:118: recipe for target 'clientRPi' failed<br/> make: *** [clientRPi] Error 2

For this project I'm using CLion. Don't really now how to handle it. Everything is new for me, so please ignore bad code. I would appreciate every answer.

Mateusz
  • 37
  • 6
  • https://stackoverflow.com/questions/28247606/can-someone-explain-why-my-cmake-file-fails-to-build-my-cpp-file – pvy4917 Nov 08 '18 at 21:20
  • 1
    When cross-compile, you need not only toolchain for target platform, but also the libraries. The library `/usr/local/lib/libopencv_stitching.so.3.4.1` is suited for host platform, but not for the target. – Tsyvarev Nov 08 '18 at 21:31

0 Answers0