modelica-3rdparty / Modelica_DeviceDrivers

Free library for interfacing hardware drivers to Modelica models. There is support for joysticks, keyboards, UDP, TCP/IP, LCM, MQTT, shared memory, AD/DA converters, serial port and other devices.
BSD 3-Clause "New" or "Revised" License
77 stars 31 forks source link

Fix linker errors due to multiply defined symbols #385

Closed henrikt-ma closed 10 months ago

henrikt-ma commented 11 months ago

This fixes problems on Linux when spreading out the generated code for external functions over multiple translation units.

In general, I think the more clean way of fixing the problem would be to have each external C function definition be included (by means of Include annotation) by at most one Modelica external function, but the "trick" used here of making the definitions static is less invasive.

bernhard-thiele commented 11 months ago

With the patch we have

#if defined(MDDSHAREDLIBRARY)
# if defined(_MSC_VER)
#  define DllImport __declspec( dllimport )
#  define DllExport __declspec( dllexport )
# else
#  define DllImport
#  define DllExport static
# endif /* _MSC_VER */
#else
# define DllImport
# define DllExport static
#endif /* MDDSHAREDLIBRARY */

which means on Linux DllExport will always be replaced by static. Why not directly write static before the corresponding functions in MDDJoystic.h and MDDRealtimeSynchronize.h?

henrikt-ma commented 11 months ago

Why not directly write static before the corresponding functions in MDDJoystic.h and MDDRealtimeSynchronize.h?

Yes, that would make sense. I'll just need some time to test the new variant locally before pushing to this PR.

henrikt-ma commented 11 months ago

Why not directly write static before the corresponding functions in MDDJoystic.h and MDDRealtimeSynchronize.h?

Yes, that would make sense. I'll just need some time to test the new variant locally before pushing to this PR.

Done.