Makefile不检查头文件中的更新

问题描述

我认为我的makefile非常好,但是后来我尝试仅更新头文件并重新编译我的库,但是它没有任何改变。

如何使其工作并重新编译h文件中的代码

我的制作文件

SHELL = /bin/sh
SOURCE_FILES_Dirs = -I./../frmwrk/ -I./../Utils/
CXX = g++
CXXFLAGS = $(SOURCE_FILES_Dirs) -std=c++17 -rdynamic -fPIC -g -Wall
LDFLAGS = -shared

LIBS_DIR = ../../libs/
LIB_NAME = libIni.so
TARGET  = $(LIBS_DIR)$(LIB_NAME)
SOURCES = $(shell echo *.cpp)
HEADERS = $(shell echo *.h)
OBJECTS = $(SOURCES:.cpp=.o)
LINK_LIBS = -lFrmwrk -lUtils

PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin

all: $(TARGET)

$(TARGET): $(OBJECTS) $(HEADERS)
    $(CXX) $(CXXFLAGS) -L$(LIBS_DIR) $(LDFLAGS) -o $(TARGET) $(OBJECTS) $(HEADERS) $(LINK_LIBS)

clean:
    rm -f *.o $(TARGET)/*.so
    rm -rf $(TARGET)

解决方法

const PosterGrid = (props: PosterGridProps): JSX.Element => {
  const { moviePosters } = props;
  const [selected,setSelected] = useState<null | number>(null);
const moviePosterCardsTop = moviePosters
    .map((value,index) => (
      <PosterCard isSelected={index === selected} setSelected={() => setSelected(index)} moviePoster={value} />
    ))
    .slice(0,3);
  const moviePosterCardsBottom = moviePosters
    .map((value,index) => (
      <PosterCard isSelected={index === selected} setSelected={() => setSelected(index)} moviePoster={value} />
    ))
    .slice(3);

  return (
    <div style={styles.container}>
      <div style={styles.topPosterCardsContainer}>{moviePosterCardsTop}</div>
      <div style={styles.bottomPosterCardsContainer}>{moviePosterCardsBottom}</div>
    </div>
  );

这仅在更改头文件时才强制进行重新链接。 interface HomePageProps { theme: Theme; } const HomePage = (props: HomePageProps): JSX.Element => { const { theme } = props; const styles: Styles = { container: { background: theme.BACKGROUND,height: '100%',width: '100%',},}; return ( <div style={styles.container}> <Header theme={theme} /> {/*Calling in the two components seperately,how do I pass in the values for the props below,if I just call in the Question component that is supposed to connect the other two components together? */} <QuestionHeader question="Which movie do you like best?" /> <PosterGrid moviePosters={[ { posterUrl: 'https://images-na.ssl-images-amazon.com/images/I/61rv%2BRnsu6L._AC_.jpg',title: 'Avenger',videoUrl: '',description: 'Avenger',actors: ['Thor','Bob','Joe'],完全不知道哪个C ++源文件包括哪个头文件。 $(TARGET): $(OBJECTS) $(HEADERS) [relink command] 仅知道头文件中显式声明的依赖项。这里唯一说明的依赖性是可执行文件make对头文件具有依赖性。

例如,为了在包含make时强制重新编译$(TARGET),因为main.o declarations.h main.cpp,您必须明确:

#includes

无论何时declarations.h发生变化,这都将引导main.o: declarations.h make重建main.o

由于哪些头文件无法缩放而手动跟踪需要重建哪些对象模块。 main.cpp当然不了解任何与C ++相关的知识,因此您必须手动跟踪所有依赖关系,但这又无法扩展。

这里的解决方案是迁移到一些更高级别的构建工具,例如GNU autoconf和automake,它们将为您编写declarations.h,并附带一堆使用编译器标志转储依赖项的规则,并进行更新自动为您制定规则。您始终可以使用相同的编译器标志(有些标志可以自行构建所有脚手架,而无需autoconf和automake。但是为什么要麻烦,当autoconf automake会为您做这些事情吗?