c++ - Makefile 编译问题
问题描述
我正在尝试使用制作的 makefile 编译我的 .cpp 文件,但它不会编译。我有 2 个目录 ex1 和 ex2。帮助将不胜感激,并提前感谢!
生成文件:
output: Main.o Gamer.o Manager.o Person.o EncryptionDerived.o
g++ Main.o Gamer.o Manager.o Person.o EncryptionDerived.o -o output -I.
./Main.o: ./ex1/Main.cpp
g++ -c ./ex1/Main.cpp
./Gamer.o: ./ex1/Gamer.cpp
g++ -c ./ex1/Gamer.cpp
./Manager.o: ./ex1/Manager.cpp
g++ -c ./ex1/Manager.cpp
./Person.o: ./ex1/Person.cpp
g++ -c ./ex1/Person.cpp
./EncryptionDerived.o: ./ex2/EncryptionDerived.cpp
g++ -c ./ex2/EncryptionDerived.cpp
clean:
rm -rf *.o output
run:
./output
这就是我从命令行得到的
./makefile: line 1: ./Main.o:: No such file or directory
./makefile: line 4: ./Gamer.o:: No such file or directory
./makefile: line 7: ./Manager.o:: No such file or directory
./makefile: line 10: ./Person.o:: No such file or directory
./makefile: line 13: ./EncryptionDerived.o:: No such file or directory
./makefile: line 16: clean:: command not found
./makefile: line 19: all:: command not found
./makefile: line 21: output:: command not found
g++.exe: error: Main.o: No such file or directory
g++.exe: error: Gamer.o: No such file or directory
g++.exe: error: Manager.o: No such file or directory
g++.exe: error: Person.o: No such file or directory
g++.exe: error: EncryptionDerived.o: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.
./makefile: line 24: run:: command not found
./makefile: line 25: ./output: No such file or directory
解决方案
尝试这个:
output: Main.o Gamer.o Manager.o Person.o EncryptionDerived.o
g++ Main.o Gamer.o Manager.o Person.o EncryptionDerived.o -o output -I.
Main.o: ex1/Main.cpp
g++ -c ex1/Main.cpp
Gamer.o: ex1/Gamer.cpp
g++ -c ex1/Gamer.cpp
Manager.o: ex1/Manager.cpp
g++ -c ex1/Manager.cpp
Person.o: ex1/Person.cpp
g++ -c ex1/Person.cpp
EncryptionDerived.o: ex2/EncryptionDerived.cpp
g++ -c ex2/EncryptionDerived.cpp
clean:
rm -rf *.o output
run:
./output
推荐阅读
- javascript - 如何“Alt+向左箭头”木偶页面.keyboard
- android - 约束布局中的条件定位
- google-apps-script - 如何在 Google 测验中添加正确答案的多项选择题
- c# - 内容验证错误预期类型:数组
- snowflake-cloud-data-platform - Snowflake 如何进行瞬时调整大小?
- sql-server - 如何使用 pyodbc 将 CONTAINSTABLE 参数化查询传递给 SQL Server,条件是包含术语“AND”-ed 一起?
- laravel - Laravel Swagger PHP 找不到常量数组
- r - 如何命名行
- rust - 合并排序代码未在 rust 中提供所需的输出
- django - 在 AJAX 调用中使用 CSRF 会导致 Uncaught TypeError: Cannot read property 'value' of null