Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker input file unused c++ g++ make file

I am unable to figure out what is causing this error that I keep getting upon making my project:

i686-apple-darwin11-llvm-g++-4.2: -lncurses: linker input file unused because linking not done

And my make file looks like this:

CC = g++

LIB_FLAGS = -l ncurses

FLAGS = $(LIB_FLAGS)

DEPENDENCIES = window.o element.o

# FINAL OUTPUTS
main: main.cpp $(DEPENDENCIES)
    $(CC) $(FLAGS) -o main.out main.cpp $(DEPENDENCIES)

# MODULES
window.o: main.h classes/window.cpp
    $(CC) $(FLAGS) -c classes/window.cpp

element.o: main.h classes/element.cpp
    $(CC) $(FLAGS) -c classes/element.cpp

# CLEAN
clean:
    rm -rf *.o
    rm main.out

Everything compiles okay, but I'm just curious what is causing this error message and what it means..

like image 653
JonMorehouse Avatar asked Dec 16 '22 19:12

JonMorehouse


2 Answers

You are passing linker options to a compiler invocation together with -c, which means that linking is not performed and thereby -l options are unused. In your case, your LIB_FLAGS should not be in FLAGS, but instead specified in the the main: ... rule:

main: main.cpp
        $(CC) $(FLAGS) $(LIB_FLAGS) ...
like image 85
JesperE Avatar answered Dec 28 '22 06:12

JesperE


Do not give link flags when you compile (-c flag) your source files. Take a look for this example makefile (very similar as in makefile docs)

CPP = g++
CPPFLAGS =-Wall -g
OBJECTS = main.o net.o
PREFIX = /usr/local

.SUFFIXES: .cpp .o

.cpp.o:
        $(CPP) $(CPPFLAGS) -c $<

.o:
        $(CPP) $(CPPFLAGS) $^ -o $@

main: $(OBJECTS)
main.o: main.cpp
net.o: net.cpp net.h


.PHONY:
install: main
        mkdir -p $(PREFIX)/bin
        rm -f $(PREFIX)/bin/main
        cp main $(PREFIX)/bin/main


clean:
        rm -f *.o main
like image 22
Maxim Avatar answered Dec 28 '22 06:12

Maxim