std::variant undefined references

Hey, I've recently tried to use the c++17 std::variant feature.
It seems to work fine with std::visit but on some compilers (specifically clang for android ndk)

I get undefined references when trying to use functions from one of my type for the variant.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Resource.h

class AudioResource
{
public:
    void Load() const;
}

using ResourceVariant = std::variant<AudioResource,... others...>;

Resource.cpp
#include "Resource.h"

void AudioResource::Load() const {.... implementation .. }


Loader.h
#include "Resource.h"

Loader.cpp
#include "Loader.h"

void Loader::Load(const ResourceVaraint& v)
{
   std::visit([&](const auto& r)
    {
       r.Load();
    }, v);
}

Results in linker error:
error: undefined reference to 'AudioResource::Load() const'

it seems to work for windows.
are there any restrictions on std::variant member functions when trying to use them with std::visit? it seems to be fine when the definition of AudioResource::Load is directly in the header.

Has anyone any idea?
Last edited on
based on the error would say that you didn't put Resource.cpp into your project.
provide a minimal testcase and your build commands
@ne555 interesting, I'm using cmake with GLOB recurse. But maybe you're right and something is just fucked up with my project (even though I've did several clean runs), since I haven't really found any restrictions in the variant proposals etc
Last edited on
Topic archived. No new replies allowed.