Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to suppress "linker file unused" when compiling

part of my makefile looks like this ...

ifdef vis 
flg += -framework GLUT -framework OpenGL -Dvis
obj += camfun.o glfuns.o
endif

...

all: driver.cpp header.h $(obj) 
  $(cc) -o $(exe) driver.cpp $(obj) $(flg) $(lib)

funs.o: header.h funs.cpp
  $(cc) -c funs.cpp $(flg)

glfuns.o: header.h glfuns.cpp
  $(cc) -c glfuns.cpp $(flg)

camfun.o: header.h camfun.cpp
  $(cc) -c camfun.cpp $(flg)

which gives me the following warning upon compilation:

g++ -c camfun.cpp -Wno-write-strings -O2 -framework GLUT -framework OpenGL -Dvis
i686-apple-darwin10-g++-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: GLUT: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-g++-4.2.1: OpenGL: linker input file unused because linking not done

now, i know i am getting that warning because i definitely should (the -c option specifically tells it not to link)! but i want to turn it off, i know i am linking too much and i'm ok with that. how do i turn off that warning?

like image 587
drjrm3 Avatar asked Mar 15 '12 21:03

drjrm3


1 Answers

You can't turn off the warning, except by not passing those flags. It's not that you're linking "too much", it's that by giving -c you're not linking at all. Any flags that are supposed to be passed to the linker will show a warning if you give them to a command that doesn't run the linker. If you don't want those warnings, then don't pass linker flags to your compiler. Separate out your flags in your makefile into two different variables: one set that goes to both compiler and linker (often people use CFLAGS for this but it's just a convention) and one set that goes just to the linker (often LDFLAGS).

Also you shouldn't link in the all target: have a separate target for the executable so that if you run make twice in a row without changes, the second invocation will do nothing.

And in POSIX, command options should generally come before arguments not afterwards.

And of course, using pattern rules helps avoid redundancy.

For example:

ifdef vis 
ccflg += -Dvis
ldflg += -framework GLUT -framework OpenGL
obj += camfun.o glfuns.o
endif

...

all: $(exe)

$(exe): driver.cpp header.h $(obj) 
        $(cc) -o $(exe) $(ccflg) $(ldflg) driver.cpp $(obj) $(lib)

%.o: %.cpp header.h
        $(cc) -c $(ccflg) $<
like image 66
MadScientist Avatar answered Oct 24 '22 09:10

MadScientist