我的makefile如何使用其文件夹之外的源来执行可执行文件 [英] How can my makefile make executable with source outside of its folder

查看:146
本文介绍了我的makefile如何使用其文件夹之外的源来执行可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

我有以下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:=


(patsubst%。cpp,%。o,


(SRCS))
all:


hi 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:


这篇关于我的makefile如何使用其文件夹之外的源来执行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆