libpcan.h double define error

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
hjusti
Posts: 1
Joined: Fri 9. Feb 2024, 14:14

libpcan.h double define error

Post by hjusti » Fri 9. Feb 2024, 14:29

I was using libpcan.h in a project without any issues. The CAN part was already finished, and I was working on another protocol when suddenly my project wouldn't build anymore. It was throwing the following error:

Code: Select all

/usr/include/pcan.h:32:2: error: #error "double define for DWORD, WORD, BYTE found"
   32 | #error "double define for DWORD, WORD, BYTE found"
/usr/include/libpcan.h:34:2: error: #error "double define for LPSTR, HANDLE found"
   34 | #error "double define for LPSTR, HANDLE found"
Upon investigation, I discovered that another library I was using also defined some of these types.

Analyzing lipcan.h and pcan.h, I noticed that the way they define the types could be improved, since instead of checking if a definition already exists and simply not redefining it, they try to define it again, which causes the error.
The solution for my case was simply to check if the type definitions matched and to reverse the order of including the necessary headers, leaving libpcan.h before the other library in question, since it does handle include guards properly.

My suggestion is to improve the definition handling and protections of libpcan.h so that this kind of workaround is not necessary.

Thank you.

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: libpcan.h double define error

Post by PEAK-Support » Fri 9. Feb 2024, 14:53

we will think about it - but maybe it is a problem that also could be solved in a different way...
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply