I have the following three files:
inline_header.h
#ifndef INLINE_HEADER_H
#define INLINE_HEADER_H
inline int func1() {
return 1;
}
#endif
source1.c
#include "inline_header.h"
source2.c
#include "inline_header.h"
int main() {
func1();
}
When I compile only source2.cwith gcc source2.c, it compiles. However, when I try to compile with gcc source1.c source2.c, I get a multiple-definition error as follows:
/tmp/cchsOaHF.o: In function `func1':
source2.c:(.text+0x0): multiple definition of `func1'
/tmp/ccEyUW0T.o:source1.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
I am compiling with gcc 4.8.4 on Ubuntu 14.04.
I tried to find this and found a similar question to several definitions of an inline function . However, in his case, the error is caused by overriding its built-in function. In my case, I am not redefining it (or at least not explicitly ...).
source
share