The example program is here:
test.h
#pragma once
#include <bitset>
class Foo{
public:
constexpr static std::bitset<9> hori1{0b111000000};
bool Bar(const std::bitset<9> cells);
};
test.cpp
#include <bitset>
#include "test.h"
bool Foo::Bar(const std::bitset<9> cells){
return hori1.any();
}
int main(){
return 0;
}
When compiling this program without the --std=c++11
everything works fine.
$ g++ -c test.cpp
$ g++ test.o
But when the flag is included, I get this:
$ g++ -c --std=c++11 test.cpp
$ g++ test.o
/usr/bin/ld: test.o: warning: relocation against `_ZN3Foo5hori1E' in read-only section `.text'
/usr/bin/ld: test.o: in function `Foo::Bar(std::bitset<9ul>)':
test.cpp:(.text+0x17): undefined reference to `Foo::hori1'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
Why is this happening only in C++11? As far as I know, test.h is correctly included and therefore hori1
should be visible from within Foo
. Any help is appreciated.