clang linker error

compiles fine with g++ -std=c++11

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

struct X
{
    static constexpr const char* STRINGS[] = {
        "blah"
        // ...
    };
};

int main() { std::cout << X::STRINGS[0]; }


/tmp/static-ebfb2f.o: In function `main':
static.cpp:(.text+0x6): undefined reference to `X::STRINGS'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

struct X
{
    static constexpr const char* STRINGS[] = {
        "blah"
        // ...
    };
};

int main() { std::cout << X::STRINGS[0]; }


What exactly are you trying to do?
Print a string that says "blah"?

closed account (3hM2Nwbp)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

struct X
{
    static constexpr const char* STRINGS[] = {
        "blah"
        // ...
    };
};

// If I recall, an external definition is still required for proper linkage.
constexpr const char* X::STRINGS[];

int main() { std::cout << X::STRINGS[0]; }
What exactly are you trying to do?
Print a string that says "blah"?

lol

@Luc Lieber Thanks, it worked perfectly !
Topic archived. No new replies allowed.