AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[makefile](coding)

Martin Hope
go go go go
Asked: 2025-04-25 06:10:16 +0800 CST

进行测试打印:测试是最新的

  • 6

为什么我的make test不工作?

我有这个简单的 makefile,运行时

# make test
make: 'test' is up to date.

从哪里来'test' is up to date.!?

生成文件

BINARY_HTTP=http

build:
    @go build -o bin/${BINARY_HTTP} cmd/${BINARY_HTTP}/main.go

run: build
ifdef skip-user
    @./bin/${BINARY_HTTP}/main -skip-user
else
    @./bin/${BINARY_HTTP}/main
endif

test:
    @echo "test"
    @go test -count=1 ./test

如果test将 makefile 中的命令更改为其他类似命令,wee该命令还能正常工作吗?为什么?

# make wee
test

生成文件

BINARY_HTTP=http

build:
    @go build -o bin/${BINARY_HTTP} cmd/${BINARY_HTTP}/main.go

run: build
ifdef skip-user
    @./bin/${BINARY_HTTP}/main -skip-user
else
    @./bin/${BINARY_HTTP}/main
endif

wee:
    @echo "test"
    @go test -count=1 ./test
makefile
  • 1 个回答
  • 33 Views
Martin Hope
TobiR
Asked: 2025-04-09 15:34:45 +0800 CST

在 Makefile 中使用 foreach 分别编译子目录

  • 5

我有以下 Makefile 示例:

BUILD = build
PATH_POT3 = src/pot/pot3/
MPIFC = mpiifort
FFLAGS = -O3

MOL_LIST = $(shell find $(PATH_POT3) -mindepth 1 -maxdepth 1 -type d)

$(foreach MOL,$(MOL_LIST), \
  $(eval LIST_MOL := $(shell find $(MOL) -name "*.f90")) \
  $(info Fortran files: $(LIST_MOL)) \
  $(foreach SRC,$(LIST_MOL), \
    $(eval OBJ := $(BUILD)/$(notdir $(SRC:.f90=.o))) \
    $(OBJ): $(SRC) ; \
    $(info Compiling: $(SRC)) \
    $(info Output: $(OBJ)) \
    $(MPIFC) $(FFLAGS) -c $(SRC) -o $(OBJ) \
  ) \
)

all: $(foreach MOL,$(MOL_LIST),\
    $(foreach SRC,$(shell find $(MOL) -name "*.f90"),\
        $(BUILD)/$(notdir $(SRC:.f90=.o))\
    )\
)

这里我想PATH_POT3以顺序的方式(一个接一个地)编译每个子目录的(递归)内容。遗憾的是,这种构造并没有提供预期的结果,因为它只编译列表中的第一个目标文件,而跳过了所有其他目标文件。Makefile 为我的测试用例打印了以下信息:

Fortran files: src/pot/pot3/ar3/pot_ar3.f90 src/pot/pot3/ar3/ar43/pot_ar43.f90
Compiling: mpiifort -O3 -c src/pot/pot3/ar3/pot_ar3.f90 -o build/pot_ar3.o
Output: build/pot_ar3.o
Compiling: mpiifort -O3 -c src/pot/pot3/ar3/ar43/pot_ar43.f90 -o build/pot_ar43.o
Output: build/pot_ar43.o
Fortran files: src/pot/pot3/ar33/pot_ar33.f90 src/pot/pot3/ar33/pot_ar333.f90 src/pot/pot3/ar33/ar53/pot_ar53.f90
Compiling: mpiifort -O3 -c src/pot/pot3/ar33/pot_ar33.f90 -o build/pot_ar33.o
Output: build/pot_ar33.o
Compiling: mpiifort -O3 -c src/pot/pot3/ar33/pot_ar333.f90 -o build/pot_ar333.o
Output: build/pot_ar333.o
Compiling: mpiifort -O3 -c src/pot/pot3/ar33/ar53/pot_ar53.f90 -o build/pot_ar53.o
Output: build/pot_ar53.o
make: 'build/pot_ar3.o' is up to date.

一切似乎都设置正确,但编译仅针对执行build/pot_ar3.o。

我应该如何更改此文件以获得所需的行为?

makefile
  • 1 个回答
  • 27 Views
Martin Hope
vbulash
Asked: 2025-04-08 01:02:15 +0800 CST

Makefile 条件 `ifeq` - 哪里出错了

  • 5

我的 makefile 是:

LOGGER=Mongo
# Mongo logger
LOGGER_MONGO_BINARY=loggerMongoApp
LOGGER_MONGO_FOLDER=logger-service-mongo
# Redis logger
LOGGER_REDIS_BINARY=loggerRedisApp
LOGGER_REDIS_FOLDER=logger-service-redis

build_logger:
    ifeq ("${LOGGER}", "Mongo")
    LOGGER_BINARY=${LOGGER_MONGO_BINARY}
    LOGGER_FOLDER=${LOGGER_MONGO_FOLDER}
    else ifeq ("${LOGGER}", "Redis")
    LOGGER_BINARY=${LOGGER_REDIS_BINARY}
    LOGGER_FOLDER=${LOGGER_REDIS_FOLDER}
    endif

    @echo Building logger binary (${LOGGER}-based)...
    chdir ..\${LOGGER_FOLDER} \
        && set GOOS=linux \
        && set GOARCH=amd64 \
        && set CGO_ENABLED=0 \
        && go build -o ${LOGGER_BINARY} ./cmd/api
    @echo Done!

在 makefile 中我想要获得条件逻辑。

make build_logger结尾为:

ifeq ("Mongo", "Mongo")
process_begin: CreateProcess(NULL, ifeq (Mongo, Mongo), ...) failed.
make (e=2): ═х єфрхЄё  эрщЄш єърчрээ√щ Їрщы.
make: *** [Makefile:43: build_logger] Error 2

里面的短信内容是“找不到指定的文件”。怎么回事?

makefile
  • 1 个回答
  • 30 Views
Martin Hope
Ultra Junkie
Asked: 2025-03-04 18:59:59 +0800 CST

如果所有文件位于不同的文件夹中但具有相似的结构(依赖于语言),我该如何在 Make 中定义依赖关系?

  • 6

我想在 makefile 中使用工具msgfmt从 .po 源生成 .mo 文件。.po 源针对每种语言,位于如下文件夹结构中:

$(projectpath)/locale/de/LC_MESSAGES
$(projectpath)/locale/fr/LC_MESSAGES
$(projectpath)/locale/en/LC_MESSAGES

生成的.mo 文件应位于类似的文件夹结构中:

$(buildpath)/locale/de/LC_MESSAGES
$(buildpath)/locale/fr/LC_MESSAGES
$(buildpath)/locale/en/LC_MESSAGES

在 makefile 中,我已成功为源和目标创建了 2 个变量:

PO_FILES := $(wildcard $(projectpath)/locale/*/LC_MESSAGES/*.po)
MO_FILES := $(subst $(projectpath)/locale/,$(buildpath)/locale/,$(subst .po,.mo,$(PO_FILES)))

并且我还能够为 MO_FILES 创建目标目录。

DIRS := $(sort $(dir $(MO_FILES)))

但是,我在定义依赖关系以触发生成时失败了。

以下选项不起作用:

%.mo:%.po
$(buildpath)/locale/%/LC_MESSAGES/%.mo: $(projectpath)/locale/%/LC_MESSAGES/%.po

我也尝试了其他几个组合,结果相同。Make 声称它没有制定目标的规则。

makefile
  • 2 个回答
  • 32 Views
Martin Hope
Jeremy L.
Asked: 2025-02-04 02:55:06 +0800 CST

在变量名称中查找子字符串

  • 5

我正在尝试检查变量是否包含特定字符串。我尝试了此处发布的解决方案:Makefile:包含字符串,但对我来说,它似乎不起作用。

@echo $(findstring 2025, $(basename $(<F)))`

返回2025,但是:

ifeq ($(findstring 2025, $(basename $(<F))),2025)
    @echo $(findstring 2025, $(basename $(<F)))
endif

不返回2025。为什么?

makefile
  • 2 个回答
  • 25 Views
Martin Hope
wvxvw
Asked: 2025-01-14 02:31:14 +0800 CST

在 Make 规则中将源和目标配对

  • 5

我已经很久没有使用过 Make 了,我记得有一个技巧可以做到这一点,但我的记忆力不行,而且词汇量太笼统,无法进行搜索……

所以:

SOURCES := $(wildcard */*.org)
JIRAS := $(patsubst %.org,%.jira,$(SOURCES))

.PHONY : all

all : $(JIRAS)

$(JIRAS) : $(SOURCES)
# $< is wrong here, because it will always be the first source
    emacs $< --batch -l $(CURDIR)/org2jira -f export-to-jira --kill

正如评论所暗示的,这$<部分是错误的。我认为有一种方法可以将其拆分为两个规则,然后 Make 会在匹配的文件上成对调用它,但在尝试了一些组合之后,我就是想不起来它是什么。

如果方便的话,所需的代码可以写在 Shell 中:

find . -type f -name '*.org' -exec emacs {} --batch -l $(pwd)/org2jira -f export-to-jira --kill \;

注意:我不关心解决方案是否特定于 GNUMake。

makefile
  • 1 个回答
  • 14 Views
Martin Hope
Hakim
Asked: 2024-12-18 19:46:07 +0800 CST

自动生成的依赖文件中没有配方

  • 6

*.d我已经使用 make(使用)自动生成了依赖文件( ) g++ -MMD,在这些文件中,我看到创建的规则没有任何配方。此外,从我的测试中,我注意到后续构建(*.d创建后)仍将使用我自己在 Makefile 中定义的配方:

CPPFLAGS := -Iinclude
CXXFLAGS := -std=c++20 -Wall -Wextra -Werror -MMD

%.o: %.cpp
    # recipe below used when building from dependency files!
    $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o$@ $<

-include $(DEPS_FILES)

文档中是否提到过,带有空配方的规则只会向现有规则添加先决条件?我之所以问这个问题,是因为我注意到它不使用此处定义的隐式规则。

makefile
  • 1 个回答
  • 28 Views
Martin Hope
S. Schlegel
Asked: 2024-12-10 05:04:28 +0800 CST

如何将 MariaDB 链接插入到现有 Makefile 中

  • 5

我有一个现有的且可以运行的 Makefile,并且想要添加 MariaDB (mysql.h)。我的问题是:

gcc -o example MariaDBTest.c $(mariadb_config --include --libs)

运行良好。但是我如何/在哪里可以将其插入到我的 Makefile 中:

CC = gcc -Wno-unknown-pragmas -Wall -Wextra
PKGCONFIG = $(shell which pkg-config)
CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-3.0 --libs) -lbcm2835 -rdynamic -lm
DEPS = LinkedList.h StructDefinitions.h
%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)
OBJ = reTerminal.c \
    Sensors/CpuGpuTemp.c Sensors/ReadSensores.c Sensors/TempSensorExtern.c \
    Connectivity/ClientSide.c Connectivity/ServerSide.c \
    GUI/MainApp.c GUI/MainAppWindow.c GUI/BasicFrame.c GUI/SimpleFrame.c \
    Data/MariaDBTest.c
Main: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS)

系统:Linux/RasPi5

makefile
  • 1 个回答
  • 29 Views
Martin Hope
zapta
Asked: 2024-11-29 02:29:05 +0800 CST

makefile .PHONY 是否适用于目标别名?

  • 6

考虑下面的 Makefile,命令clean被声明为PHONY并且有一个备用名称c。

PHONY 属性是否也适用于make c或仅适用于make clean?

.PHONY: clean

clean c:
  rm -rf *.o
makefile
  • 1 个回答
  • 42 Views
Martin Hope
Bronumski
Asked: 2024-11-10 01:15:12 +0800 CST

没有目标或先决条件的多个 make 规则

  • 6

我可能用错了术语,所以请随时纠正我。我们一段时间以来一直在滥用 make 进行大量构建。99% 的时间都是使用虚假目标。我们有 docker build 项目,我们为每个版本化的 docker 文件调用 docker build。文件结构看起来像这样:

6/Dockerfile
8/Dockerfile

获取项目中的 docker 文件列表很容易。

DOCKERFILES:=$(wildcard */Dockerfile)

目前我们正在使用这种方法来构建docker文件:

.PHONY: all
all: lint init build-images
.PHONY: lint
lint:
    $(foreach image, $(DOCKERFILES),$(call dockerLint,$(image),$(_DOCKER_BUILD_ARCH)))

.PHONY: init
init:
    $(foreach image, $(DOCKERFILES),$(call initVariablesForImage,$(image)))

.PHONY: build-images
build-images:
    $(foreach image, $(DOCKERFILES),$(call dockerBuildPush,$(image),$(_DOCKER_BUILD_ARCH)))

但是,为了更好地理解 make 并避免 foreach,是否可以定义与 Dockerfile 匹配的多个规则并运行相关配方?我使用单个规则取得了一些成功,但一旦我尝试执行多个配方,它就会失败。

.PHONY: test
test: $(DOCKERFILES)

$(DOCKERFILES):*
    $(info ***** build $@)

输出结果如下:

***** build 6/Dockerfile
***** build 8/Dockerfile

我预计这种方法是错误的,因为当我尝试引入其他目标时,我会收到覆盖警告或循环引用:

warning: overriding commands for target `8/Dockerfile'
warning: ignoring old commands for target `8/Dockerfile'

...

make: Circular 6/Dockerfile <- 6/Dockerfile dependency dropped.
make: Circular 7/Dockerfile <- 7/Dockerfile dependency dropped.
make: Circular 8/Dockerfile <- 8/Dockerfile dependency dropped.

我想停下来看看我想要实现的目标是否可行。我们现有的方案是可行的,但探索替代方案以查看我们能否提出更清晰的实现方案会更好。

makefile
  • 1 个回答
  • 42 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve