如何使用g ++创建具有特定名称的目标文件 [英] How do I use g++ to create object file with a specific name

查看:56
本文介绍了如何使用g ++创建具有特定名称的目标文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个makefile,目标之一是exptrtest.o如何使用g ++创建一个具有该名称的对象文件,我的cpp文件的名称是exprtest.cpp而不是exptrtest.cpp?

I am making a makefile and one of the targets is exptrtest.o how do I use g++ to create an objectfile with that name, the name of my cpp file is exprtest.cpp not exptrtest.cpp?

exptrtest.o: exprtest.cpp
    g++ -Wall -g -c exprtest.cpp

更清楚地说,这是我的makefile:

to make it more clear, this is my makefile:

all: exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
    g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
exptrtest.o: exprtest.cpp
    g++ -Wall -g -c exptrtest.o exprtest.cpp
driver.o: driver.cpp scanner.hpp driver.hpp
    g++ -Wall -g -c driver.cpp
parser.tab.o: parser.tab.hpp parser.tab.cpp
    bison parser.ypp
    g++ -Wall -g -c parser.tab.cpp
scanner.o: scanner.cpp scanner.hpp
    flex -t scanner.ll > scanner.cpp
    g++ -Wall -g -c scanner.cpp
clean:
    rm parser.tab.hpp parser.tab.cpp scanner.cpp

我遇到了错误:"g ++:错误:exptrtest.o:没有这样的文件或目录make: * [exprtest]错误1"

I'm getting the error: "g++: error: exptrtest.o: No such file or directory make: * [exprtest] Error 1"

推荐答案

-o 选项与 -c 结合使用.

exptrtest.o: exprtest.cpp
    g++ -Wall -g -c exprtest.cpp -o exptrtest.o

这篇关于如何使用g ++创建具有特定名称的目标文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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