我已經在NetBeans上編寫了C++程序,現在我想在命令行上的Linux上運行它。我怎麼寫Makefile,寫它的邏輯是什麼?編寫C++程序的Makefile
我有3個.cpp文件和2個.hpp文件。
這就是我試圖做:
# Makefile
# the C++ compiler
CXX = g++
CC = $(CXX)
# options to pass to the compiler
CXXFLAGS = -Wall -ansi -O2 -g
Run: Run.cpp Assessment3.o Student.o
$(CXX) $(CXXFLAGS) Run.cpp Assessment3.o Student.o -o Run
Run: Run.cpp Assessment3.hpp Assessment3.o Student.o
$(CXX) $(CXXFLAGS) Run.cpp Assessment3.o Student.o -o Run
Assessment3.o: Assessment3.cpp Assessment3.hpp
$(CXX) $(CXXFLAGS) -c Assessment3.cpp
Student.o: Student.cpp Assessment3.o
$(CXX) $(CXXFLAGS) -c Student.cpp
它給了我「失蹤分隔符。停止。'命令行錯誤。這並不是說這是一個錯誤。 乾杯
您需要縮進'$(CXX)...'行 - 最好使用製表符,儘管make的大多數現代版本都可以使用空格或製表符(舊版本需要製表符)。但請參閱下面的答案以獲取更簡單的版本。 –
對「make missing separator」進行網絡搜索將導致大量網頁描述此問題及其解決方案。在這裏問這個問題真的不是什麼工作,而不是搜索? – eriktous