链接器输入文件未使用的c ++ g ++ make文件 [英] Linker input file unused c++ g++ make file

查看:100
本文介绍了链接器输入文件未使用的c ++ g ++ make文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚造成这个错误的原因是什么:
$ b

  i686-apple -darwin11-llvm-g ++  -  4.2:-lncurses:链接器输入文件未使用,因为链接没有完成

我的make文件如下所示:

  CC = g ++ 

LIB_FLAGS = -l ncurses

FLAGS = $(LIB_FLAGS)

DEPENDENCIES = window.o element.o

#FINAL OUTPUTS
main:main.cpp $(依赖项)
$(CC)$(FLAGS)-o main.out main.cpp $(依赖)

#模块
window.o:main.h类/窗口。 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

所有东西都编译好,但我只是好奇是什么导致了这个错误信息,它的意思是什么......

当你编译(-c标志)你的源文件时,不要给链接标志。看看这个例子makefile(非常类似于makefile文档)

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

.SUFFIXES:.cpp .o

.cpp。 o:
$(CPP)$(CPPFLAGS)-c $ <
$ b $ o:
$(CPP)$(CPPFLAGS)$ ^ -o $ @

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

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


clean:
rm -f * .o main


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..

解决方案

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

这篇关于链接器输入文件未使用的c ++ g ++ make文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆