Sample code (x.c): int main(void) { int return_pcap_debug(void) { extern int pcap_debug; return pcap_debug; } return 0; } Compiled with (-Os, -O1, -O2 are all the same): gcc x.c -o x Produces: /tmp/ccJy8Ead.o(.text+0xa): In function `return_pcap_debug.0': : undefined reference to `pcap_debug' collect2: ld returned 1 exit status But, when compiled with: gcc -O3 x.c -o x The code compiles. This is an over-optimisation, and is pretty silly, especially since the returned value in the inlined block is an extern. If you link the code against something that does export pcap_debug, it links properly.
This is not over optimizing as return_pcap_debug is an function inside a function which is a gcc extension but the function is not used as all (aka like a static funciton), so gcc is removing the function. Note that at -O2 (because of -funit-at-a-time) gcc 3.4.0 will remove the function also.