Created
September 8, 2018 11:45
-
-
Save Thalhammer/cd743d519721fd45bd86b559c9fb844f to your computer and use it in GitHub Desktop.
ODR Violation error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609 | |
Copyright (C) 2015 Free Software Foundation, Inc. | |
This is free software; see the source for copying conditions. There is NO | |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
test.h:8:3: warning: type ‘struct test2_t’ violates one definition rule [-Wodr] | |
} test2_t; | |
^ | |
test.h:8:3: note: a different type is defined in another translation unit | |
} test2_t; | |
^ | |
test.h:6:23: note: the first difference of corresponding definitions is field ‘t’ | |
std::vector<test1_t> t; | |
^ | |
test.h:6:23: note: a field of same name but different type is defined in another translation unit | |
std::vector<test1_t> t; | |
^ | |
/usr/include/c++/5/bits/stl_vector.h:214:11: note: type ‘struct vector’ defined in anonymous namespace can not match type ‘struct vector’ | |
class vector : protected _Vector_base<_Tp, _Alloc> | |
^ | |
/usr/include/c++/5/bits/stl_vector.h:214:11: note: the incompatible type defined in anonymous namespace in another translation unit | |
class vector : protected _Vector_base<_Tp, _Alloc> | |
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir test && cd test | |
cat > main.cpp <<EOF | |
#include "test.h" | |
int main() { | |
test2_t t; | |
t.test(); | |
} | |
EOF | |
cat > test.cpp <<EOF | |
#include "test.h" | |
void test2_t::test() {} | |
EOF | |
cat > test.h << EOF | |
#pragma once | |
#include <vector> | |
typedef struct { | |
typedef struct { | |
} test1_t; | |
std::vector<test1_t> t; | |
void test(); | |
} test2_t; | |
EOF | |
g++ --version | |
g++ -flto -c -o test.o test.cpp -std=c++11 | |
g++ -flto -c -o main.o main.cpp -std=c++11 | |
g++ -flto *.o -o test | |
cd .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment