Skip to content

fix: template specializations in ArtnetWiFi.h cause multiple definition linker errors in multi-file C++ projects (v0.9.1)#151

Merged
hideakitai merged 1 commit intohideakitai:mainfrom
costyn:fix/missing-inline-keyword
Oct 19, 2025
Merged

fix: template specializations in ArtnetWiFi.h cause multiple definition linker errors in multi-file C++ projects (v0.9.1)#151
hideakitai merged 1 commit intohideakitai:mainfrom
costyn:fix/missing-inline-keyword

Conversation

@costyn
Copy link
Contributor

@costyn costyn commented Oct 19, 2025

Hello again,

I've been running into a linker issue, when using the 0.9.1 in my C++ project.

Below is the analysis of Claude Code, please take it with a grain of salt, it could be garbage and I'm doing it wrong. If so, my apologies. But, adding the inline keywords fixes the issue for my build.

Thank you for a cool library!


The template specializations for getLocalIP, getSubnetMask, getMacAddress, and isNetworkReady in ArtnetWiFi.h (lines 102, 108, 114, 120) (and the other .h files) are missing the inline keyword, causing ODR (One Definition Rule) violations when the header is included in multiple translation units.

Error Example:

multiple definition of `IPAddress art_net::getLocalIP<WiFiUDP>()'

Affected Code (ArtnetWiFi.h):

template <>
IPAddress getLocalIP<WiFiUDP>()  // <-- Missing 'inline'
{
    return LocalIP<ArtnetWiFiClass>::get(WiFi);
}

Fix: Add inline keyword to all four template specializations (lines 102, 108, 114, 120):

template <>
inline IPAddress getLocalIP<WiFiUDP>()
{
    return LocalIP<ArtnetWiFiClass>::get(WiFi);
}

Why this happens:
Simple Arduino sketches (single .ino file) work fine because they compile to one translation unit
Multi-file C++ projects fail because the template specializations get compiled into multiple object files
The linker sees duplicate symbols and fails

Impact of fix:
✅ No behavior change for existing working code
✅ No performance impact
✅ Fixes multi-file C++ projects (PlatformIO, Arduino with multiple .cpp files)
✅ Standard C++ practice for header-only template specializations

@costyn costyn changed the title Template specializations in ArtnetWiFi.h cause multiple definition linker errors in multi-file C++ projects (v0.9.1) fix: template specializations in ArtnetWiFi.h cause multiple definition linker errors in multi-file C++ projects (v0.9.1) Oct 19, 2025
Copy link
Owner

@hideakitai hideakitai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. LGTM

@hideakitai hideakitai merged commit 5a500a7 into hideakitai:main Oct 19, 2025
28 checks passed
@costyn costyn deleted the fix/missing-inline-keyword branch October 20, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants