Created
April 25, 2020 22:03
-
-
Save domiyanyue/dea6addec8a7bded5af98b6e193b71e0 to your computer and use it in GitHub Desktop.
error2 ODR
This file contains hidden or 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
muti_file# g++ -c main.cpp | |
muti_file# g++ -c main.cpp -o main.o | |
muti_file# g++ -c util.cpp -o util.o | |
muti_file# g++ main.o util.o -o a.out | |
util.o: In function `foo()': | |
util.cpp:(.text+0x0): multiple definition of `foo()' | |
main.o:main.cpp:(.text+0x0): first defined here | |
collect2: error: ld returned 1 exit status |
This file contains hidden or 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
#include "util.h" | |
int foo(){ | |
return 2; | |
} | |
int main(){ | |
return foo(); | |
} |
This file contains hidden or 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
#include "util.h" | |
int foo(){ | |
return 1; | |
} |
This file contains hidden or 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
int foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment