簡體   English   中英

循環依賴在 makefile 中下降

[英]Circular dependency dropped in makefile

我的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)

我的文件夾結構是這樣的(附圖片)

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

當我跑步時

make test

它表明它丟棄了一個循環依賴 我看不出是什么原因造成的。

# 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

我剛剛將擴展名從cxx更改為cpp ,一切正常,沒有任何錯誤。 詭異的

你有Circular dependency ,因為

%: %.o

是一個 gnu make 隱式規則

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM