我的makefile如何使用其文件夹之外的源来执行可执行文件 [英] How can my makefile make executable with source outside of its folder
问题描述
嗨所有
我有以下makefile
TARGET:= test.so
DEFINES:=
CC := g ++
CFLAGS:= -Wall -O3 -c -fpic -I $(INCLUDES)
LDFLAGS:= -lrt -ldl -lpthread -s -shared -fpic
SRCS:= ./main.cpp \
../../src/test.cpp
INCLUDES = -I ../../ inc
##### ######################
OBJS:= $(patsubst%。cpp,%。o,$(SRCS))
all :$(TARGET)
$(TARGET):$(OBJS)
$(CC)$(LDFLAGS)-o $ @ $ ^
%.o:%。cpp
$(CC)$(CFLAGS)$(DEFINES)$(INCLUDES)-c $<
clean:
rm -rf $(TARGET)* .o ./.depend
依赖:.depend
.depend:$(SRCS)
rm -rf ./.depend
$(CC)$(CFLAGS)$(DEFINES)-MM $ ^>> ./。depend
include .depend
.PHONY:all clean
运行后我得到以下错误
g ++:错误:../../ src / test.o :没有这样的文件或目录
我尝试过:
它是对的,我的test.o文件是在main.o
旁边构建的,当我在终端中单独运行以下命令时我的.so成功构建了
g ++ -lrt -ldl -lpthread -s -shared -fpic -o test.so main.o test.o
how我的makefile可以实现这种行为吗?
(INCLUDES)
LDFLAGS:= -lrt -ldl -lpthread -s -shared -fpic
SRCS:= ./main.cpp \
../../src/test.cpp
INCLUDES = -I ../../ inc
## #########################
OBJS:=
hi all 这篇关于我的makefile如何使用其文件夹之外的源来执行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
(SRCS))
all:
I have the following makefile
TARGET := test.so
DEFINES :=
CC := g++
CFLAGS := -Wall -O3 -c -fpic -I$(INCLUDES)
LDFLAGS := -lrt -ldl -lpthread -s -shared -fpic
SRCS := ./main.cpp \
../../src/test.cpp
INCLUDES = -I../../inc
###########################
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
%.o: %.cpp
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $<
clean:
rm -rf $(TARGET) *.o ./.depend
depend: .depend
.depend: $(SRCS)
rm -rf ./.depend
$(CC) $(CFLAGS) $(DEFINES) -MM $^>>./.depend
include .depend
.PHONY: all clean
after running make I got the below error
g++: error: ../../src/test.o: No such file or directory
What I have tried:
it is right, My test.o file is built beside the main.o
when I ran the following command separately in terminal my .so was built successfuly
g++ -lrt -ldl -lpthread -s -shared -fpic -o test.so main.o test.o
how can my makefile implement this behavior?(INCLUDES)
LDFLAGS := -lrt -ldl -lpthread -s -shared -fpic
SRCS := ./main.cpp \
../../src/test.cpp
INCLUDES = -I../../inc
###########################
OBJS :=
(patsubst %.cpp,%.o,
(SRCS))
all: