简体   繁体   English

循环依赖在 makefile 中下降

[英]Circular dependency dropped in makefile

I am having problems with my makefile It looks like this我的makefile出现问题 它看起来像这样

name = project-name

testfiles = $(wildcard tst/*.cxx)
sourcefiles = $(wildcard src/*.cpp)
headerfiles = $(wildcard inc/*.hpp)

tests = $(testfiles:%=%.o)
sources = $(sourcefiles:%=%.o)
headers = $(headerfiles:%=%.gch)

location = /usr/local/include

flags = -Iinc -std=c++17 -pedantic -Wall

all: $(name)

%/:
    mkdir -p $@

clean:
    rm -f $(tests) $(sources) $(headers) $(name) test

install: $(name)
    install $^ $(location)/$<

run-%: %
    ./$<

test: $(tests)
    g++ -o $@ $^

$(name): $(sources)
    g++ -o $@ $^

pch: $(headers)

%.gch: %
    g++ -o $@ $< $(flags)

tst/catch.cxx.o: tst/catch.cxx inc/catchmain.hpp.gch
    g++ -o $@ -c $< $(flags)

tst/receive.cxx.o: tst/receive.cxx inc/catchtest.hpp.gch inc/server.hpp.gch
    g++ -o $@ -c $< $(flags)

src/server.cpp.o: src/server.cpp inc/server.hpp.gch inc/iostream.hpp.gch
    g++ -o $@ -c $< $(flags)

My folder structure is like this (image attached)我的文件夹结构是这样的(附图片)

.
├── inc
│   ├── catchmain.hpp
│   ├── catchtest.hpp
│   ├── iostream.hpp
│   └── server.hpp
├── makefile
├── src
│   └── server.cpp
└── tst
    ├── catch.cxx
    └── receive.cxx

And when I run当我跑步时

make test

It shows that it dropped a circular dependency .它表明它丢弃了一个循环依赖 I don't see what might cause that.我看不出是什么原因造成的。

# The output of `make test`
make: Circular tst/catch.cxx <- tst/catch.cxx.o dependency dropped.
g++ -o inc/catchmain.hpp.gch inc/catchmain.hpp -Iinc -std=c++17 -pedantic -Wall
g++ -o tst/catch.cxx.o -c tst/catch.cxx -Iinc -std=c++17 -pedantic -Wall
make: Circular tst/receive.cxx <- tst/receive.cxx.o dependency dropped.
g++ -o inc/catchtest.hpp.gch inc/catchtest.hpp -Iinc -std=c++17 -pedantic -Wall
g++ -o inc/server.hpp.gch inc/server.hpp -Iinc -std=c++17 -pedantic -Wall
g++ -o tst/receive.cxx.o -c tst/receive.cxx -Iinc -std=c++17 -pedantic -Wall
g++ -o test tst/catch.cxx.o tst/receive.cxx.o

I just changed the extension from cxx to cpp and everything works without any errors.我刚刚将扩展名从cxx更改为cpp ,一切正常,没有任何错误。 Weird诡异的

You had Circular dependency because你有Circular dependency ,因为

%: %.o

is a gnu make implicit rule是一个 gnu make 隐式规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM