Skip to content

Instantly share code, notes, and snippets.

@domiyanyue
Created April 25, 2020 22:03
Show Gist options
  • Save domiyanyue/dea6addec8a7bded5af98b6e193b71e0 to your computer and use it in GitHub Desktop.
Save domiyanyue/dea6addec8a7bded5af98b6e193b71e0 to your computer and use it in GitHub Desktop.
error2 ODR
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
#include "util.h"
int foo(){
return 2;
}
int main(){
return foo();
}
#include "util.h"
int foo(){
return 1;
}
int foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment