libpcan.h double define error
Posted: 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:
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.
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"
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.