How do you use libsocketcan2 library in the Torizon extension for VSCode?
I tried to add it in extrapackages in the configurations tab of the Torizon extension.
Hello @gclaudino.tx , I am good . How are you?
Yes with the libsocketcan-dev in devpackages and libsocketcan2 in extra packages, the red squiggles under my .cpp file for the #include <libsocketcan.h> declaration have gone.
However, after running the build task from Terminal → Run build Task (Ctrl+Shift+B), there is still a compilation error for the can_set_bitrate() function as follows. It appears to be a linker error.
/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/bin/ld: /tmp/ccd0ANtR.o: in function `main':
/workspaces/cant2/cant2.cpp:56: undefined reference to `can_set_bitrate'
collect2: error: ld returned 1 exit status
The terminal process "/bin/bash '-c', 'aarch64-linux-gnu-g++ -g cant2.cpp -o cant2'" terminated with exit code: 1.
Thanks for the update. I’m good too . Can you please share a bigger extract of your code so that we could see how did you use the can_set_bitrate()? There seems to be something on your code as the library is now loaded.
If you want, you can do this either here on the community directly or at support@toradex.com or through a private message here.
You can add the -lsocketcan command on the tasks.json file. This shall be done both on the “args” of build_debug and build_release. You’ll probably end with something like:
However, I’d like to suggest you use a build framework such as CMake or Makefile for future projects as it can help you with some of the project development.
I updated the tasks.json file and then ran the code in a debug container within VSCode and it worked fine.
I also changed to a release configuration and ran the code in a release container within VSCode, it worked fine.
However, when I try to invoke the release container outside VSCode using a command docker run from SSH terminal ( using Putty), the container does not run successfully.
It is invoked but I get an error as below.
apalis-imx8-07013612:~$ docker run cant2_arm64v8-debian-no-ssh_bullseye_release_9462f5c5-4e70-46e8-86a6-bae0e204d3c3
Error in socket bind: No such device
Not able to understand why this is happening, as in within VSCode inside the development container, I can see the program running but not via Putty.
Thanks for the update. Can you please try running the container on your module using the output that F1 Torizon: export docker command line provides on the extension? You may be missing some of the parameters to run your project properly.