riebl / artery

OMNeT++ V2X simulation framework for ETSI ITS-G5
GNU General Public License v2.0
202 stars 128 forks source link

Cmake static variable cannot load library #310

Closed Matk3z closed 9 months ago

Matk3z commented 9 months ago

Hi,

As part of my research project around PKI in its systems, I'm trying to load a bunch of certificate file paths and share it between every car node in the simulation. To implement this behavior, I created a StaticCertificateLoader Class in src/artery/application with two static stack attribute (unsed_certificate and used_certificate). Then in the class ctor I populated the unused_certificate with everything in my certificate's folder using directory_iterator from boost file system.

image

image

I added StaticCertificateLoader.cc in /artery/src/CmakeLists.txt, and I'm pretty sure it's being compiled as it appears in cmake traces. However, when I run my scenario I got this classic error:
<!> Error: Cannot load library '/home/mathi/artery/build/scenarios/simple-security/libartery_simple-security.so': /home/mathi/artery/build/scenarios/simple-security/libartery_simple-security.so: undefined symbol: _ZN6artery23StaticCertificateLoader19unused_certificatesB5cxx11E

I notice that if I declare my two stacks as not static, it runs fine. This leads me to two questions:

  1. Is there a way to run this code with these two stacks as static?
  2. Do you know about a proper way to debug this? This is not the first time I got this error, and every time it's a pain to debug it as there is no clear error message. I've tried to compile with --verbose but it didn't give me any more information

Thank you for all your work on Vanetza and Artery those are amazing pieces of software! Mathias

Matk3z commented 9 months ago

Really sorry I have opened this issue for nothing, I've fixed my own mistake. I'm not really proficient in c++ and for whatever reason you need to declare static member variables in source file and not in header file. I don't know how I didn't find the solution earlier (altough coming from the Rust world such a non descriptive error for such an easy mistake is a bit frustrating...).

riebl commented 9 months ago

I agree, the error message is not very helpful for C/C++ beginners. But as you have found the reason on your own, you will know next time :-)