I am new to embedded linux development. Following the online available documents, I have been able to successfully create and debug C# and Python applications. However, when I start a new C/C++ Project from the extension, I get the following error:
The remote/Dev Containers were installed. I spent approximately 3 days resolving the issue. However, I finally tried with the ApolloX extension and it seems to be working now.
Would you be able to point me towards a sample of uart communication using C++? I have found python and C# samples and they are working.
Also, in the V1 extension, there is a way to share resources such as uarts with the containers using the extension. There seems to be no way to do this from the V2 extension. Any articles regarding this would also be welcome.
The remote/Dev Containers were installed. I spent approximately 3 days resolving the issue. However, I finally tried with the ApolloX extension and it seems to be working now.
Glad you were able to overcome the issue using ApolloX, though it is a strange behavior on V1 of the extension. I’ll report this to the extension team. Thanks for the feedback!
Also, in the V1 extension, there is a way to share resources such as uarts with the containers using the extension. There seems to be no way to do this from the V2 extension. Any articles regarding this would also be welcome.
You mean giving the container access to the UART devices? On ApolloX you do so by altering the docker-compose.yml file in your project, similar to the example in this article: How to Use UART on Torizon OS | Toradex Developer Center
Would you be able to point me towards a sample of uart communication using C++? I have found python and C# samples and they are working.
I don’t think we have a sample C/C++ code for UART in our developer site, though this article UART (Linux) | Toradex Developer Center has a sample C code to set the baud rate.
I did a quick search and found this outside article Linux Serial Ports Using C/C++ | mbedded.ninja that could be useful for learning serial communication with C/C++. Given that it is for Linux in general, its content should apply when developing for TorizonCore, though I can’t guarantee it.
However, when I call the library from the code, the compiler is unable to build.
I have tried to manually copy the headers from /usr/include to the project/includes folder but it seems unnatural and gives other errors.
Can you provide any pointers? I have tried adding libserial-dev into deps.json in the .conf folder and torizonPackages.json in the app folder.
I must add, the link you shared based on termios, it works and I can open the requisite ports and communicate with them. But just for knowledge, I wanted to use an external library for development, in case I need to use any others in future.
I finally seem to be able to start a C/C++ project using Toradex v1 extension. The trick was to disconnect from WSL (if connected) > install torizon extension v1 in windows mode > create new C/C++ application > then it created a dev container to work in.
With the external library, I have added it to devpackages and extrapackages and the libserial is accessible from the visual studio code. However, I am unable to build the project using external library (libserial). I am using cmakelists and have included the headers. The following is the current cmakelists file:
cmake_minimum_required(VERSION 3.0.0)
# set the project name
project(AppTest17WinSide VERSION 1.0)
# add the executable
add_executable(AppTest17WinSide
AppTest17WinSide.cpp
/usr/include/libserial/SerialPort.h
/usr/include/libserial/SerialStream.h
)
# find_library(LIBSERIAL_LIBRARY SerialPort.h HINTS /usr/include/libserial/)
# target_link_libraries(AppTest17WinSide PUBLIC ${LIBSERIAL_LIBRARY})
# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS AppTest17WinSide DESTINATION bin)
I have tried to manually copy the headers from /usr/include to the project/includes folder but it seems unnatural and gives other errors.
Can you provide any pointers? I have tried adding libserial-dev into deps.json in the .conf folder and torizonPackages.json in the app folder.
In order to add an external library to your ApolloX project you have to add it to your SDK container and in your debug/release container as well. For instance, in order to add LibSerial you have to change the following files:
Dockerfile.sdk: Add libserial-dev:arm64 in the apt-get install command, similar to this:
Dockerfile.debug (debug container) and Dockerfile (release container): Similar to above, add libserial-dev or libserial1 to the apt-get install command.
You also have to include the library flag to your Makefile, as otherwise you’ll get the undefined reference errors. To do this add -lserial to LDFLAGS in your Makefile:
LDFLAGS := -lserial
Once that’s done you can try to compile and deploy your program. You can ignore any include errors related to your library, as it will be installed in the containers.
EDIT: For the code above I also had to add /dev/ttyUSB0 as a device in docker-compose.yml:
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
As for the V1 issues, if devpackages has libserial-dev:arm64 and extrapackages has libserial1 or libserial-dev then the problem can be a linking issue similar to the one you faced before. I don’t know for sure how to do this with CMake, but try to find an equivalent option to the -lserial Makefile flag I mentioned above.
This keyword seems to be the solution to every problem in cmake and the ApolloX extension as well. May I ask how you found it?
in my cmakelists I was adding:
The -l<library_name> expression is a gcc/g++ option when compiling, telling the compiler to search for a library called <library_name> during the linking stage. This is usually needed when using an external library in C/C++ projects.
<library-name> is the name of the .so or .a file without the lib part at the beginning. So for libserial.so, <library-name> would be serial.
You can find more information about this option in these external links:
Hello lucas! I hope I can bother you regarding another question.
I have been able to develop my application using many libraries the way you taught me. However, I am at a point where I need to work with a library named RTKLIB to work with some RTCM messages.
since the library isnt available on package feeds, the only way to work with the library is by building yourself. How can I configure my project in a way to build and include this library. currently, I have it cloned into my appconfig_0 folder. I started trying to follow External libraries with Torizon visual studio extension - #8 by matheus.castello but lost the way when they instruct to “Include in Project”
since the library isnt available on package feeds, the only way to work with the library is by building yourself. How can I configure my project in a way to build and include this library. currently, I have it cloned into my appconfig_0 folder. I started trying to follow External libraries with Torizon visual studio extension - #8 by matheus.castello but lost the way when they instruct to “Include in Project”
Keep in mind that the link you referenced above is for Visual Studio, not Visual Studio Code, so the procedures there don’t necessarily apply to your case.
Are you using V2 of the IDE extension (previously known as ApolloX)? If that’s the case and you are working with our C++ project template you have a Makefile in which you can add compilation instructions for the external library. You probably need to add the library source files to your VSCode project then add the appropriate instructions in the Makefile.
While I can’t help you with the Makefile itself I’d recommend that you see these links for more details on how to use it:
You said that RTKLIB isn’t available in the feeds, but I did find a package named librtklib-dev on the bookworm feeds: Debian -- Details of package librtklib-dev in bookworm. If the container images you’re using are based on bookworm you can try using that as a possible alternative.
Well I sorted it out using another cmakelists file for the RTKLIB and added a sub-directory to it in my main cmakelists file and it built the RTKLIB code along with the main app. then I could also use the headers etc as needed.
Glad to hear that you could solve the issue. It would be nice if you can post the CMakeLists.txt file just so that it could help others who might run into the same problem.