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
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
I'm getting the error: "g++: error: exptrtest.o: No such file or directory make: * [exprtest] Error 1"
Use file-name as the name of the file produced by g++ (usually, this is an executable file).
g++ -o target_name file_name: Compiles and links file_name and generates executable target file with target_name (or a. out by default).
A computer programmer generates object code with a compiler or assembler. For example, under Linux, the GNU Compiler Collection compiler will generate files with a .o extension which use the ELF format. Compilation on Windows generates files with a . obj extension which use the COFF format.
The main difference between object file and executable file is that an object file is a file generated after compiling the source code while an executable file is a file generated after linking a set of object files together using a linker. C is a general-purpose, high-level programming language.
Use the -o
option in conjunction with -c
.
exptrtest.o: exprtest.cpp g++ -Wall -g -c exprtest.cpp -o exptrtest.o
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With