jacketizer / libnmea

Lightweight C library for parsing NMEA 0183 sentences
MIT License
260 stars 92 forks source link

PARSER_COUNT undeclared #59

Closed fliescher closed 1 year ago

fliescher commented 1 year ago

I got an error thrown when compiling a C/C++ project for a STM32 platform. I excluded the parser.h/c files from the compiler paths as I don't want to use the dynamic parser. In parser_static.c I get the following error: parser_static.c:49:30: error: 'PARSER_COUNT' undeclared here

How to fix this?

igrr commented 1 year ago

This macro should be defined here: https://github.com/jacketizer/libnmea/blob/91fd4338a8f648de9b174d7aac954fedce8852aa/CMakeLists.txt#L143 Perhaps you aren't using the CMake files provided in the project? In case it helps, here's an example of a CMakeLists file to compile libnmea for another embedded platform, ESP32: https://github.com/igrr/libnmea-esp32/blob/5e80d96e0e9d6ecdf8401abd90c243a720147814/CMakeLists.txt#L34

fliescher commented 1 year ago

I see, thanks for the hint!

You're right, I'm not using the CMake files but the source and header files only.

If I understand it correctly, the parser_count variable is basically the number of gpxyz.h files I'm including/using?! So for example if I only include gprmc.h and gpvtg.h I can just set the count variable to 2?!

igrr commented 1 year ago

Yes, that's correct, you can simply define PARSER_COUNT to the number of parsers you are compiling.

There is another problem if you aren't using CMakeLists or a Makefile, though, which is the symbol renaming: https://github.com/jacketizer/libnmea/blob/91fd4338a8f648de9b174d7aac954fedce8852aa/CMakeLists.txt#L145-L157

This renames the functions defined in each parser's object file from e.g. init to nmea_gpxyz_init. This allows linking multiple parsers into the same binary. (The original design where each parser object file has functions with the same name is used for the other scenario, where each parser is built into a shared library.)

If you are copying the files into your own project, you can rename each of the functions in gpxyz.c to parser_gpxyz_*. This should let you compile and link the program successfully, i think.

fliescher commented 1 year ago

After some days off I'm now able to compile the project including your libnmea. Thanks for your hints and especially for providing this library!