CMake can't link some libraries

I’m new to both CMake and the Torizoncore in VScode.
I’m trying to create an application to receive via udp and deserialize a bitstream and relay to the uart port.
I’m using the libraries:
Ncurses, Boost and libserial.
Here’s is my CMakeLists.txt

cmake_minimum_required (VERSION 2.8)
project (gnsspvt-monitor-uart CXX C)
set (CMAKE_CXX_STANDARD 11)
include_directories(${CMAKE_SOURCE_DIR})

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

set(CURSES_NEED_NCURSES TRUE)
set(Curses_NO_SYSTEM_PATHS TRUE)
set(CURSES_USE_MULTITHREADED ON)
find_package(CURSES REQUIRED)
include_directories(${CURSES_INCLUDE_DIRS})

find_package(LIBSERIAL REQUIRED)

add_library(monitoring_lib ${CMAKE_SOURCE_DIR}/monitor_pvt_udp_source.cc)

add_executable(gnsspvt-monitor-uart ${CMAKE_SOURCE_DIR}/main.cc)

target_include_directories(gnsspvt-monitor-uart PRIVATE Boost::headers Boost::asio Boost::filesystem 
Boost::system Boost::serialization)
target_link_libraries(gnsspvt-monitor-uart monitoring_lib ${Boost_LIBRARIES} ${LIBSERIAL_LIBRARIES} ${CURSES_LIBRARIES})
target_link_libraries(gnsspvt-monitor-uart -lpthread -lserial)

And the Error msg:
image

in devpackage: libserial-dev:#%platform.debian-arch%# libboost-all-dev:#%platform.debian-arch%# libncurses-dev:#%platform.debian-arch%# ncurses-libmenu:#%platform.debian-arch%# ncurses-libform:#%platform.debian-arch%# libboost1.74-dev:arm64

in extrapackage: libncurses-dev libboost-all-dev libboost-dev libboost-system-dev libprotobuf-dev libncurses5-dev libserial1

Question 1: How do i add the curses library and the libserial, build and run in the torizoncore?
Question 2: How do i run the code as debug mode with CMake? i’ve tried but received a error msg: Error Executing preLaunchTask.

Greetings @CaioGM,

I have some initial questions about your environment/setup. First of all what version of our VSCode extension are you running? Also are you running on a Windows or Linux PC environment?

Question 1: How do i add the curses library and the libserial, build and run in the torizoncore?

First of all looking at the screenshot of your error message, I’m a bit confused. Are you running cmake on the command-line outside of the extension? What’s the error from the VSCode extension itself?

Question 2: How do i run the code as debug mode with CMake? i’ve tried but received a error msg: Error Executing preLaunchTask.

Wait so you get this error when trying to hit F5 to build, run, and debug your project? Does this always happen? Does it happen with the default project template, or only after you do your changes?

Best Regards,
Jeremias

Hi Jeremias,

First of all what version of our VSCode extension are you running? Also are you running on a Windows or Linux PC environment?

Toradex Torizon Support v1.5.1. Linux (Ubuntu 22.04 LTS).

Are you running cmake on the command-line outside of the extension? What’s the error from the VSCode extension itself?

Yes. At first, I tried to hit F5 but received the “Error Executing preLaunchTask” message. To work around and see if there was something in the CMakeLists.txt, I was using the embedded terminal in VScode.
I’m certain that I have misconfigured something here.
For reference, here is the launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Torizon-Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "",
            "miDebuggerServerAddress": "",
            "stopAtEntry": true,
            "cwd": "${workspaceRoot}",
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb-multiarch",
            "targetArchitecture": "arm64",
            "setupCommands": [
                {
                    "description": "Setting architecture",
                    "text": "set architecture %{torizon.gdb-arch}",
                    "ignoreFailures": false
                }
            ]
        },
        {
            "name": "C/C++: aarch64-linux-gnu-gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: aarch64-linux-gnu-gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

I was using the embedded terminal in VScode.
I’m certain that I have misconfigured something here.

The extension works by building your code in an SDK container rather than directly on your host system. So I think the error you’re seeing here is due to that, since you’re not meant to build it like this on the terminal. For now I would say ignore this error and let’s focus on the preLaunch Task error.

Yes. At first, I tried to hit F5 but received the “Error Executing preLaunchTask” message.

I created a new CMake based project in our extension and it builds fine by default. Therefore I think there’s either some configuration issue like you said, or the project wasn’t setup correctly somehow.

With our extension when you create a C/C++ based project it should re-open the project inside a devcontainer. You’ll know this worked when the VSCode window looks like this:

Notice the bottom-left corner of the window. The part that says “Dev Container:…”. This means that my project is running inside a Dev container, which is to be expected. Does this look the same/similar on your side?

Best Regards,
Jeremias

Creating a C/C++ based project from the start, at first there’s error in app creation.

Here is the error log.

[2023-05-31T16:47:33.254Z] Dev Containers 0.292.0 in VS Code 1.78.2 (b3e4e68a0bc097f0ae7907b217c1119af9e03435).
[2023-05-31T16:47:33.254Z] Start: Resolving Remote
[2023-05-31T16:47:33.287Z] Setting up container for folder or workspace: /home/hetech/Documents/gnss-monitor
[2023-05-31T16:47:33.311Z] Start: Check Docker is running
[2023-05-31T16:47:33.311Z] Start: Run: docker version --format {{.Server.APIVersion}}
[2023-05-31T16:47:33.334Z] Stop (23 ms): Run: docker version --format {{.Server.APIVersion}}
[2023-05-31T16:47:33.335Z] Server API version: 1.43
[2023-05-31T16:47:33.335Z] Stop (24 ms): Check Docker is running
[2023-05-31T16:47:33.337Z] Start: Run: docker volume ls -q
[2023-05-31T16:47:33.360Z] Stop (23 ms): Run: docker volume ls -q
[2023-05-31T16:47:33.360Z] Start: Run: docker inspect --type container eae98a1ad40dd179a3febfd6715b81442cbcf6ee7e32e902912cfb494b31496d
[2023-05-31T16:47:33.379Z] Stop (19 ms): Run: docker inspect --type container eae98a1ad40dd179a3febfd6715b81442cbcf6ee7e32e902912cfb494b31496d
[2023-05-31T16:47:33.380Z] Start: Run: docker rm -f eae98a1ad40dd179a3febfd6715b81442cbcf6ee7e32e902912cfb494b31496d
[2023-05-31T16:47:33.406Z] Stop (26 ms): Run: docker rm -f eae98a1ad40dd179a3febfd6715b81442cbcf6ee7e32e902912cfb494b31496d
[2023-05-31T16:47:33.410Z] Command failed: docker rm -f eae98a1ad40dd179a3febfd6715b81442cbcf6ee7e32e902912cfb494b31496d
[2023-05-31T16:47:33.411Z] Error response from daemon: removal of container eae98a1ad40dd179a3febfd6715b81442cbcf6ee7e32e902912cfb494b31496d is already in progress
[2023-05-31T16:47:33.411Z] Exit code 1

And if i click the retry, the hello world example seems to build and run just fine.

Does this look the same/similar on your side?

Mine seems a bit different

And if i click the retry, the hello world example seems to build and run just fine.

I’m not sure why you had the issue initially, but it sounds like everything is fine now then?

Mine seems a bit different

I think that’s mostly just a color scheme difference. I can see you’re in the dev container and the Torizon extension is running. At least from this it seems like everything is operating as expected.

Best Regards,
Jeremias

i’ve fixed the other problems but this one remains:

Message from the Output Console.

[main] Building folder: GPIO-task 
[main] Configuring project: GPIO-task 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_INSTALL_PREFIX:STRING=/workspaces/GPIO-task/appconfig_0/work/GPIO-task -DCMAKE_CC_COMPILER:FILEPATH=/usr/bin/aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/aarch64-linux-gnu-g++ -DCMAKE_TOOLCHAIN_FILE:FILEPATH=torizon-toolchain.cmake -S/workspaces/GPIO-task -B/workspaces/GPIO-task/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Warning at /usr/share/cmake-3.18/Modules/FindBoost.cmake:1187 (message):
[cmake]   New Boost version may have incorrect or missing dependencies and imported
[cmake]   targets
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:1311 (_Boost_COMPONENT_DEPENDENCIES)
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:1919 (_Boost_MISSING_DEPENDENCIES)
[cmake]   CMakeLists.txt:7 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Warning at /usr/share/cmake-3.18/Modules/FindBoost.cmake:1187 (message):
[cmake]   New Boost version may have incorrect or missing dependencies and imported
[cmake]   targets
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:1311 (_Boost_COMPONENT_DEPENDENCIES)
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:1919 (_Boost_MISSING_DEPENDENCIES)
[cmake]   CMakeLists.txt:7 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Warning at /usr/share/cmake-3.18/Modules/FindBoost.cmake:1187 (message):
[cmake]   New Boost version may have incorrect or missing dependencies and imported
[cmake]   targets
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:1311 (_Boost_COMPONENT_DEPENDENCIES)
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:1919 (_Boost_MISSING_DEPENDENCIES)
[cmake]   CMakeLists.txt:7 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Warning at /usr/share/cmake-3.18/Modules/FindBoost.cmake:2018 (message):
[cmake]   No header defined for asio; skipping header check (note: header-only
[cmake]   libraries have no designated component)
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:7 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
[cmake]   Could NOT find Boost (missing: system serialization asio) (found version
[cmake]   "1.74.0")
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
[cmake]   /usr/share/cmake-3.18/Modules/FindBoost.cmake:2177 (find_package_handle_standard_args)
[cmake]   CMakeLists.txt:7 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/workspaces/GPIO-task/build/CMakeFiles/CMakeOutput.log".
[proc] The command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_INSTALL_PREFIX:STRING=/workspaces/GPIO-task/appconfig_0/work/GPIO-task -DCMAKE_CC_COMPILER:FILEPATH=/usr/bin/aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/aarch64-linux-gnu-g++ -DCMAKE_TOOLCHAIN_FILE:FILEPATH=torizon-toolchain.cmake -S/workspaces/GPIO-task -B/workspaces/GPIO-task/build -G "Unix Makefiles" exited with code: 1

it can’t find the boost libraries, but i’ve placed the name of the package in the devpackage (which worked for the other libraries). but for boost, nothing.
How can i solve this?
My CMakeLists.txt for reference:

cmake_minimum_required(VERSION 3.0.0)

# set the project name
project(GPIO-task VERSION 1.0)


find_package(Boost REQUIRED COMPONENTS system serialization asio)
find_package(CURSES REQUIRED)
find_package(LIBSERIAL REQUIRED)

include_directories(${Boost_INCLUDE_DIRS} ${CURSES_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})

add_library(monitoring_lib ${CMAKE_SOURCE_DIR}/monitor_pvt_udp_source.cc)

# add the executable
add_executable(GPIO-task GPIO-task.cpp)

target_link_libraries(GPIO-task PRIVATE monitoring_lib ${Boost_LIBRARIES} ${LIBSERIAL_LIBRARIES} ${CURSES_LIBRARIES} pthread serial)

# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS GPIO-task DESTINATION bin)

What do your devpackages look like exactly? I tried to analyze this further but when I include the boost libraries myself and then attempt to re-build the SDK container I get this:

The following packages have unmet dependencies:

 libopenmpi-dev:arm64 : Depends: gfortran-10:arm64 but it is not going to be installed or
                                 gfortran-mod-15:arm64
                        Recommends: libcoarrays-openmpi-dev:arm64 but it is not going to be installed

E: Unable to correct problems, you have held broken packages.

It seems like trying to install the boost development libraries for arm64 leads to some kind of broken package dependency chain.

Best Regards,
Jeremias

Hi Jeremias,

This error occurred to me when I was trying to compile the code with the default CMakeLists.txt file.
I figured that sometimes it’s easier to add the library by other means and compile the program with the default CMakeLists.txt.

I’ve eventually solved the problem using calling CPM tool in the CMakeLists.txt and installing the libraries in the Dev container and changing the Dockerfile. (Which I’ve read that you shouldn’t do it).

My CMakeLists.txt looks like this now.

cmake_minimum_required(VERSION 3.0.0)

# set the project name
project(gnss-pvt-monitor VERSION 1.0)

include(cmake/CPM.cmake)

set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost REQUIRED)

find_package(Protobuf REQUIRED)
if(${Protobuf_VERSION} VERSION_LESS "3.0.0")
     message(FATAL_ERROR "Fatal error: Protocol Buffers >= v3.0.0 required.")
endif()

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_SOURCE_DIR}/monitor_pvt.proto)

add_library(monitorPvt-lib ${CMAKE_SOURCE_DIR}/HEtechSerial.cpp ${CMAKE_SOURCE_DIR}/gnss_pvt_udp_source.cc ${PROTO_SRCS})

target_include_directories(monitorPvt-lib
    PUBLIC
        ${CURSES_INCLUDE_DIRS}
        ${CMAKE_BINARY_DIR}
)

include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake)

CPMAddPackage(
  NAME Boost
  VERSION 1.82.0
  GITHUB_REPOSITORY "boostorg/boost"
  GIT_TAG "boost-1.82.0"
)

# add the executable
add_executable(gnss-pvt-monitor gnss-pvt-monitor.cpp)

target_link_libraries(gnss-pvt-monitor
    PUBLIC
        monitorPvt-lib
        ${CURSES_LIBRARIES}
        protobuf::libprotobuf
        pthread
)

# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS gnss-pvt-monitor DESTINATION bin)

It takes time to finish and probably install way more things that I need, but in the short term it works.

Glad you were able to work something out.