Missing includes?

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
Torsten Robitzki
Posts: 11
Joined: Mon 23. Nov 2020, 18:09

Missing includes?

Post by Torsten Robitzki » Thu 11. Aug 2022, 20:04

Hi,
I currently try to build the PEAK CAN drivers for Linux in a Docker container. The driver builds without problems, but the pcan libraries triggers compilation errors:
***
*** Making pcan libraries
***
*** gcc version: 10.2.1
***
gcc -DNO_RT -I. -I../driver -fPIC -Wall -Wcast-align -Wredundant-decls -DPCANFD_OLD_STYLE_API -c src/libpcan.c -o obj/libpcan.o
src/libpcan.c: In function 'LINUX_CAN_Read_Timeout':
src/libpcan.c:433:17: error: storage size of 't' isn't known
433 | struct timeval t;
| ^
src/libpcan.c:434:2: error: unknown type name 'fd_set'
434 | fd_set fdRead;
| ^~~~~~
src/libpcan.c:449:2: warning: implicit declaration of function 'FD_ZERO' [-Wimplicit-function-declaration]
449 | FD_ZERO(&fdRead);
| ^~~~~~~
...


I've fixed that, by including <sys/time.h> (according to <sys/time.h>). There are more, similar problems. Is there a general way to fix this?

best regards,
Torsten

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Missing includes?

Post by F.Vergnaud » Fri 12. Aug 2022, 11:08

Hello Torsten,

Can you please specify which Linux distribution and version you are using? It seems like "select.h" is not included (or some of your system headers don't include it).
(Note that the <sys/select.h> header also defines the timeval structure)
Thank you
Best regards,
Fabrice

Torsten Robitzki
Posts: 11
Joined: Mon 23. Nov 2020, 18:09

Re: Missing includes?

Post by Torsten Robitzki » Fri 12. Aug 2022, 14:07

Hi Fabrice,
# uname -a
Linux 685b04ac64b0 5.10.104-linuxkit #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022 aarch64 Linux
If you want to investigate into this, you could use this Dockerfile:

Code: Select all

# Create /kernel-dev.tar according to https://github.com/linuxkit/linuxkit/blob/master/docs/kernels.md
FROM linuxkit/kernel:5.10.104 AS ksrc
FROM linuxkit/kernel:5.10.104-builder AS build

RUN apk add build-base
RUN apk add linux-headers
RUN apk add bsd-compat-headers
RUN apk add udev
RUN apk add kmod

COPY --from=ksrc /kernel-dev.tar /
RUN tar xf kernel-dev.tar

RUN wget https://www.peak-system.com/fileadmin/media/linux/files/peak-linux-driver-8.15.1.tar.gz
RUN tar -zxvf /peak-linux-driver-8.15.1.tar.gz && rm /peak-linux-driver-8.15.1.tar.gz

# Patch various problems in the PEAK library
RUN sed -i '0 a #include <sys/time.h>' /peak-linux-driver-8.15.1/lib/src/libpcan.c
RUN sed -i '0 a #include <sys/time.h>' /peak-linux-driver-8.15.1/lib/src/libpcanfd.c
RUN sed -i 's/__useconds_t/useconds_t/g' /peak-linux-driver-8.15.1/test/src/transmitest.cpp
RUN sed -i 's/uint/unsigned/g' /peak-linux-driver-8.15.1/test/src/parser.cpp
RUN sed -i 's/uint/unsigned/g' /peak-linux-driver-8.15.1/test/src/pcanfdtst.c
RUN sed -i '44 a #include <sys/time.h>' /peak-linux-driver-8.15.1/test/src/pcan-settings.c
RUN sed -i 's/PTHREAD_MUTEX_RECURSIVE_NP/PTHREAD_MUTEX_RECURSIVE/g' /peak-linux-driver-8.15.1/libpcanbasic/pcanbasic/src/libpcanbasic.c
RUN sed -i '30 a #include <sys/select.h>' /peak-linux-driver-8.15.1/libpcanbasic/examples/console/c/src/pcaneventread.c
RUN sed -i '30 a #include <sys/select.h>' /peak-linux-driver-8.15.1/libpcanbasic/examples/console/c/src/pcaneventwrite.c
RUN sed -i '26 a #include <sys/time.h>' /peak-linux-driver-8.15.1/libpcanbasic/examples/console/NativeC\+\+/08_EventDrivenRead/08_EventDrivenRead.cpp

RUN cd /peak-linux-driver-8.15.1 && make -C driver
RUN cd /peak-linux-driver-8.15.1 && ( make -C driver install || echo "Ingnoring installation Error (driver)")
RUN cd /peak-linux-driver-8.15.1 && make pcanbasic
RUN cd /peak-linux-driver-8.15.1 && ( make -C libpcanbasic install || echo "Ingnoring installation Error (pcanbasic)")
best regards,
Torsten

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Missing includes?

Post by F.Vergnaud » Fri 12. Aug 2022, 16:03

Sorry but we don't do any support for docker images.

Since you're starting from a raw kernel, you should take care that you've installed all the requirements from the PCAN Linux documentation.
make, gcc
The kernel headers (or Linux headers) package of the running Linux or the sources tree of a cross-compiled Kernel
g++ and libstdc++
libpopt-dev package
Note: The g++ compiler as well as the libpopt-dev package are only required for building some user space
applications from the test directory.
Best regards,
Fabrice

Post Reply