Can't use -flto with -std=c99

Mac Mollison mollison@cs.unc.edu
Mon Jul 1 19:14:00 GMT 2013


My application builds fine with -flto, but only if I do not also specify
-std=c99.

If someone can help me, that would be wonderful. I have created a very
simple test, below, to demonstrate the problem.

main.c:
#include <stdio.h>
#include <stdlib.h>
#include "foo.h"
void main(int argc, char** argv) {
	int input = atoi(argv[1]);
	printf("%d\n", foo(input));
}


foo.h:
inline int foo(int x);


foo.c:
#include "foo.h"
inline int foo(int x) {
	while (x < 900) {
		x += x;
	}
	return x;
}


Makefile:
CFLAGS += -flto -std=c99
LDFLAGS += -flto -std=c99

main : main.o foo.o
main.o : main.c foo.h
foo.o : foo.c foo.h

.PHONY : clean

clean :
	$(RM) main main.o foo.o


Results of running make:

cc -flto -std=c99   -c -o main.o main.c
In file included from main.c:3:0:
foo.h:1:12: warning: inline function ‘foo’ declared but never defined [enabled by default]
 inline int foo(int x);
            ^
foo.h:1:12: warning: inline function ‘foo’ declared but never defined [enabled by default]
cc -flto -std=c99   -c -o foo.o foo.c
cc -flto -std=c99  main.o foo.o   -o main
/tmp/ccTDIBGZ.ltrans0.ltrans.o:ccTDIBGZ.ltrans0.o:function main: error: undefined reference to 'foo'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1

Without the -std=c99 flags, make runs successfully and without warnings.



More information about the Gcc-help mailing list