I have the following simple C program.
#include <stdio.h>
INLINE void print(const char *s) {
printf("%s\n", s);
}
int main() {
print("Hello World!");
return 0;
}
But I got the following error if I define INLINE
as inline
. I don't understand the first run fails. My understanding is that the print()
function should be inlined in main()
at the compile time, so there should not be a link error complaining about the undefined reference to print
. Could anybody help me understand why inlining would make it not working? clang
also gives a similar error. Thanks.
$ gcc -DINLINE=inline -o main.exe main.c
/tmp/mktemp/ccSbK5B8.o: In function `main':
main.c:(.text+0xc): undefined reference to `print'
collect2: error: ld returned 1 exit status
$ gcc -DINLINE= -o main.exe main.c
EDIT: But with -O2 the keyword static
is not required. why?