commaai / panda

code powering the comma.ai panda
MIT License
1.54k stars 783 forks source link

Fix openpilot build #2039

Closed maxime-desroches closed 2 months ago

maxime-desroches commented 2 months ago

In c++, const have internal linkage by default. In c, const have external linkage by default.

We recently switched to explicitly declaring PANDA_CAN_CNT with external linkage (with the extern keyword) in order to comply with misra8.4. This does not affect anything in panda, since again in c const have external linkage by default and panda is a c project.

Because we are still defining variable in header (PANDA_CAN_CNT in can.h) and declaring them with external linkage now, we get redefinition errors when compiling pandad in openpilot because can.h is included in multiple translation units (pandad.cc, main.cc). This was not a problem before since pandad is a c++ process, which mean that all those variables were already declared with internal linkage.