Makefile变量打印为空,尽管定义了结构。

huangapple go评论58阅读模式
英文:

Makefile variable printing empty despite definition structure

问题

我正在开发一个C++库,遵循以下结构:

ROOTDIR = ~/path/to/proj
BLDDIR = $(ROOTDIR)/build
INCDIR = $(ROOTDIR)/include
SRCDIR = $(ROOTDIR)/src
LIBSRCDIR = $(SRCDIR)/lib
TESTSRCDIR = $(SRCDIR)/test
OBJDIR = $(ROOTDIR)/obj
LIBOBJDIR = $(OBJDIR)/lib
TESTOBJDIR = $(OBJDIR)/test
LIBDIR = $(ROOTDIR)/lib
BINDIR = $(ROOTDIR)/bin

文件定义如下:

MKFILE = $(BLDDIR)/Makefile
HDRFILES = $(wildcard $(INCDIR)/*.hpp)
LIBSRCFILES := $(wildcard $(LIBSRCDIR)/*.cpp)
TESTSRC = $(TESTSCRCDIR)/test.cpp
LIBOBJFILES := $(patsubst $(LIBSRCDIR)/%.cpp, $(LIBOBJDIR)/%.o, $(LIBSRCFILES))
TESTOBJ := $(TESTOBJDIR)/test.o
LIBFILE = $(LIBDIR)/$(NAME)-$(VERSION).a
TESTFILE = $(BINDIR)/test
ZIPFILE = $(ROOTDIR)/$(NAME).$(VERSION).zip

我已经测试并确认一切正常工作,但不知何故$(TESTSRC)为空,尽管Make可以设置$(TESTOBJ)。我尝试在层次结构中设置变量定义,以确保一切都按层生成,但这个变量仍然为空。

编辑 1:

  • Make 正确找到所有目录
  • 我确保文件扩展名正确
  • 该变量没有被覆盖

编辑 2:
我遇到的具体错误是:
make: *** No rule to make target /test.cpp', needed by ..../test.o

..../test.o在正确的目录中,并且独立定义,不依赖于像libsrc一样的patsubst。

英文:

I am working on a C++ library where I am following the structure below:

ROOTDIR = ~/path/to/proj
BLDDIR = $(ROOTDIR)/build
INCDIR = $(ROOTDIR)/include
SRCDIR = $(ROOTDIR)/src
LIBSRCDIR = $(SRCDIR)/lib
TESTSRCDIR = $(SRCDIR)/test
OBJDIR = $(ROOTDIR)/obj
LIBOBJDIR = $(OBJDIR)/lib
TESTOBJDIR = $(OBJDIR)/test
LIBDIR = $(ROOTDIR)/lib
BINDIR = $(ROOTDIR)/bin

And the file definitions are:

MKFILE = $(BLDDIR)/Makefile
HDRFILES = $(wildcard $(INCDIR)/*.hpp)
LIBSRCFILES := $(wildcard $(LIBSRCDIR)/*.cpp)
TESTSRC = $(TESTSCRCDIR)/test.cpp
LIBOBJFILES := $(patsubst $(LIBSRCDIR)/%.cpp, $(LIBOBJDIR)/%.o, $(LIBSRCFILES))
TESTOBJ := $(TESTOBJDIR)/test.o
LIBFILE = $(LIBDIR)/$(NAME)-$(VERSION).a
TESTFILE = $(BINDIR)/test
ZIPFILE = $(ROOTDIR)/$(NAME).$(VERSION).zip

I have tested & confirmed that everything works, but for some reason $(TESTSRC) is printing empty even though Make is able to set $(TESTOBJ). I tried setting up the variable definitions in the hierarchy to ensure everything is generated in level, but that one variable remains empty.

EDIT 1:

  • Make is finding all of the directories properly
  • I have made sure that the file extension is correct
  • The variable is not being overwritten

EDIT 2:
The specific error I"mg getting is:
make: *** No rule to make target /test.cpp', needed by ..../test.o

..../test.o is in the right directory & defined separately without being dependent on a patsubst like the libsrc.

答案1

得分: 1

TESTSRCDIR = $(SRCDIR)/test

and:

TESTSRC = $(TESTSCRCDIR)/test.cpp

英文:

Read carefully:

TESTSRCDIR = $(SRCDIR)/test
    ^^^

and:

TESTSRC = $(TESTSCRCDIR)/test.cpp
                ^^^

huangapple
  • 本文由 发表于 2023年2月19日 12:12:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定