Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Project - two libraries use same typedef identifier for different types

Tags:

c

typedef

I'm working on a project using the MODBUS2 lib, and I want to add the FatFs lib to it to interface with an SD card. Both libraries use identifier SHORT for short and int respectively, and the compiler throws this error:

#258 invalid redeclaration of type name "SHORT" 

How can I work around this?

like image 665
VC-C Avatar asked Jan 17 '18 16:01

VC-C


1 Answers

You need to restructure your project in such a way that no translation unit of your library would have to include headers from both libraries (translation unit is a fancy name for a C file).

One approach is to write your own thin "wrapper" functions around MODBUS2 and FatFs functionality. Each wrapper would have to include headers for the library that it wraps, so there would be no compile-time collision. Then the main module of your library would program to your "wrappers", without including MODBUS2 or FatFs headers at all.

like image 94
Sergey Kalinichenko Avatar answered Sep 22 '22 18:09

Sergey Kalinichenko