zpl-c / enet

⚡️ ENet reliable UDP networking library
https://blog.zpl.pw
MIT License
703 stars 60 forks source link

Linker error, multiple definitions. #29

Closed nitrix closed 3 years ago

nitrix commented 3 years ago

Hello,

Due to these definitions [1] being present outside of the implementation (ENET_IMPLEMENTATION), #include-ing enet.h in multiple translation unit for the same project results in multiple definitions and a linker error [2].

The symbols have to be marked either static (so that they keep internal linkage) or moved to the ENET_IMPLEMENTATION of your single-header library.

[1] https://github.com/zpl-c/enet/blob/5bd2ae50e0b593164172421913ce76ec3a0908e4/include/enet.h#L214-L219

[2]

[build] C:\msys64\mingw64\bin\ld: cmake/enet/libenet.a(server.c.obj):C:/***/lib/enet/include/enet.h:217: multiple definition of `enet_v6_anyaddr'; CMakeFiles\client.dir/objects.a(client.c.obj):C:/***/lib/enet/include/enet.h:217: first defined here
[build] C:\msys64\mingw64\bin\ld: cmake/enet/libenet.a(server.c.obj):C:/***/lib/enet/include/enet.h:218: multiple definition of `enet_v6_noaddr'; CMakeFiles\client.dir/objects.a(client.c.obj):C:/***/lib/enet/include/enet.h:218: first defined here
[build] C:\msys64\mingw64\bin\ld: cmake/enet/libenet.a(server.c.obj):C:/***/lib/enet/include/enet.h:214: multiple definition of `enet_v4_anyaddr'; CMakeFiles\client.dir/objects.a(client.c.obj):C:/***/lib/enet/include/enet.h:214: first defined here
[build] C:\msys64\mingw64\bin\ld: cmake/enet/libenet.a(server.c.obj):C:/***/lib/enet/include/enet.h:215: multiple definition of `enet_v4_noaddr'; CMakeFiles\client.dir/objects.a(client.c.obj):C:/***/lib/enet/include/enet.h:215: first defined here
[build] C:\msys64\mingw64\bin\ld: cmake/enet/libenet.a(server.c.obj):C:/***/lib/enet/include/enet.h:216: multiple definition of `enet_v4_localhost'; CMakeFiles\client.dir/objects.a(client.c.obj):C:/***/lib/enet/include/enet.h:216: first defined here
[build] C:\msys64\mingw64\bin\ld: cmake/enet/libenet.a(server.c.obj):C:/***/lib/enet/include/enet.h:219: multiple definition of `enet_v6_localhost'; CMakeFiles\client.dir/objects.a(client.c.obj):C:/***/lib/enet/include/enet.h:219: first defined here

Cheers, Alex.

zpl-zak commented 3 years ago

I believe we can close this as you've implemented a fix in #30. Thank you once again!