How to use Open source c++ CANopen library on linux based machine

100 views Asked by At

I am working on a big project but I will try to keep it simple and concise: I am trying to use an open source CANopen c++ library on my controller which is linux based. I mainly work on Eclipse or Ubuntu wsl and create .so files that I copy into my controller using scp. The toolchain and SDK are controller specific. I tried using this library : https://github.com/rtlabs-com/c-open/tree/master It was a tedious process as I am following another tutorial for another library and I am not used to programming in c++ or using cmake files.

I am having an issue building and using the canopen library on my controller

Any help would be much appreciated

At my current state I finished configuring everything and I need to include the header file of C-open into my program header file to be able to use it. I wasn't sure which library to use so I ended up creating this cmake file:

set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)

find_path(CANOPEN_INCLUDE_DIR
    NAMES co_obj.h co_api.h co_rtk.h
    PATHS external/c-open/include
)
find_library(CANOPEN_LIBRARY
    NAMES canopen
    PATHS build/axcf2152/external/CANopen
)

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(CANOPEN
    DEFAULT_MSG
    CANOPEN_INCLUDE_DIR CANOPEN_LIBRARY
)

if(CANOPEN_FOUND)
    set(CANOPEN_LIBRARIES ${CANOPEN_LIBRARY})
    set(CANOPEN_INCLUDE_DIRS ${CANOPEN_INCLUDE_DIR})
endif()

if(CANOPEN_FOUND AND NOT TARGET CANOPEN::CANOPEN)
    add_library(CANOPEN::CANOPEN UNKNOWN IMPORTED)
    set_target_properties(CANOPEN::CANOPEN PROPERTIES
        IMPORTED_LOCATION "${CANOPEN_LIBRARY}"
        INTERFACE_INCLUDE_DIRECTORIES "${CANOPEN_INCLUDE_DIR}"
    )
endif()

mark_as_advanced(
    CANOPEN_INCLUDE_DIR CANOPEN_INCLUDE_DIRS
    CANOPEN_LIBRARY CANOPEN_LIBRARIES)

And added #include "co_obj.h" into my program header.

There was 3 files in the include of the git repo I provided: See pic 1

My issue is that I am unaware which file to include into my hpp program to use the CANopen library as building the project with co_onj.h included gives me an error: See pic2

0

There are 0 answers