当前位置: 技术问答>linux和unix
makefile 运行出错,请指导
来源: 互联网 发布时间:2017-01-31
本文导语: 应该是文件包含的方法除了问题,请问应该怎么写 makefile文件名称为makefile,运行后提示: make: *** No rule to make target `main.cpp', needed by `main.o'. Stop. 将文件放在/usr/src/code下面,其中包含: include ------...
应该是文件包含的方法除了问题,请问应该怎么写
makefile文件名称为makefile,运行后提示:
make: *** No rule to make target `main.cpp', needed by `main.o'. Stop.
将文件放在/usr/src/code下面,其中包含:
include
------- file.h
src
-------man.cpp(#include "file.h",file.cpp(#include "file.h",
nakefile为
object = main.o file.o
inlcude = -I“/usr/src/code/maketest/include/*.h"
src = -I”/usr/src/code/maketest/src/*.cpp"
execute(object)
g++ -o execute $(object)
main.o:main.cpp
g++ -c (inlcude) $(src) main.cpp $
file.o:file.cpp file.h
g++ -c $(inlcude) $(src) file.cpp
#clean:
#rm execute $(object)
请问是出了什么问题,请指导,谢谢!!!
makefile文件名称为makefile,运行后提示:
make: *** No rule to make target `main.cpp', needed by `main.o'. Stop.
将文件放在/usr/src/code下面,其中包含:
include
------- file.h
src
-------man.cpp(#include "file.h",file.cpp(#include "file.h",
nakefile为
object = main.o file.o
inlcude = -I“/usr/src/code/maketest/include/*.h"
src = -I”/usr/src/code/maketest/src/*.cpp"
execute(object)
g++ -o execute $(object)
main.o:main.cpp
g++ -c (inlcude) $(src) main.cpp $
file.o:file.cpp file.h
g++ -c $(inlcude) $(src) file.cpp
#clean:
#rm execute $(object)
请问是出了什么问题,请指导,谢谢!!!
|
试试这个:
inlcude = -I"/usr/src/code/maketest/include/*.h"
src = -I"/usr/src/code/maketest/src/*.cpp"
COMPILE=g++ $(inlcude) $(src) -c
MAKEEXE=g++
EXE=execname
object = main.o file.o
all: $(EXE)
$(EXE): $(object)
$(MAKEEXE) $(object) -o $(EXE)
main.o: main.cpp
$(COMPILE) main.cpp
file.o: file.h file.cpp
$(COMPILE) file.cpp
clean:
rm -f *.o core $(EXE) $(object)
inlcude = -I"/usr/src/code/maketest/include/*.h"
src = -I"/usr/src/code/maketest/src/*.cpp"
COMPILE=g++ $(inlcude) $(src) -c
MAKEEXE=g++
EXE=execname
object = main.o file.o
all: $(EXE)
$(EXE): $(object)
$(MAKEEXE) $(object) -o $(EXE)
main.o: main.cpp
$(COMPILE) main.cpp
file.o: file.h file.cpp
$(COMPILE) file.cpp
clean:
rm -f *.o core $(EXE) $(object)
|
试试这个
文件位置关系('o'为空格):
.
|-- include
|ooo`-- file.h
|-- Makefile
`-- src
oooo|-- file.cpp
oooo`-- main.cpp
INCLUDE=-I"./include/"
CC=g++
COMPILE=$(CC) $(INCLUDE)
OBJS=main.o file.o
main : main.o file.o
file.o: ./src/file.cpp
$(COMPILE) ./src/file.cpp -c
main.o: ./src/main.cpp
$(COMPILE) ./src/main.cpp -c
文件位置关系('o'为空格):
.
|-- include
|ooo`-- file.h
|-- Makefile
`-- src
oooo|-- file.cpp
oooo`-- main.cpp