代码之家  ›  专栏  ›  技术社区  ›  Vlastimil Burián

BSD在我的Makefile上出错,而GNU make没有提到任何问题

  •  1
  • Vlastimil Burián  · 技术社区  · 1 年前

    BSD make 我的错误 Makefile 而GNU 制作 没有提到任何问题,我想知道是否有可能使其与它兼容?我现在并不打算移植该程序,但我认为未来一切皆有可能。非常感谢。


    产生的确切错误:

    bmake: don't know how to make .force_rebuild. Stop
    

    我的 Makefile :

    # Use the latest version of the compiler on Debian 12 OS, arm64 platform:
    CXX=g++-12
    
    # Use the official standard;
    # Optimize for speed;
    # Stop on all warnings;
    # Do not include debug symbols:
    CXXFLAGS=-std=c++17 -O3 -Wall -Wextra -Werror -Wpedantic -pedantic-errors
    
    # The name of the resulting executable file:
    APP_NAME=auto-fan-control
    
    # The name of the C++ source code file:
    SRC_FILE=$(APP_NAME).cpp
    
    # Possibly not doing anything when using GNU make;
    # You may see this for an explanation:
    # https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-POSIX_002dconforming-mode_002c-setting
    .POSIX:
    
    # You may see this for an explanation:
    # https://stackoverflow.com/a/70199176/1997354
    # Force re-build work-around:
    .PHONY: .force_rebuild
    $(APP_NAME): .force_rebuild
    
    $(APP_NAME): $(SRC_FILE)
        @printf '%s' 'Compiling...'
        @$(CXX) $(CXXFLAGS) $(SRC_FILE) -o $(APP_NAME)
        @printf '%s\n' ' Done.'
        @strip -s $(APP_NAME)
        @printf '%s\n' 'Running program... '
        @./$(APP_NAME)
    

    在我的测试PC上,我的GNU 制作 版本为:

    $ apt-cache policy make
    make:
      Installed: 4.3-4.1build2
      Candidate: 4.3-4.1build2
      Version table:
     *** 4.3-4.1build2 500
            500 https://archive.ubuntu.com/ubuntu noble/main amd64 Packages
            100 /var/lib/dpkg/status
    

    它构建了我的二进制文件,运行得很好:

    $ learn-cpp 
    /home/vlastimil/Development/cpp/rpi4-temperature-moninor--and-fan-control
    $ make
    Compiling... Done.
    Running program... 
    25.0°C
    
    1 回复  |  直到 1 年前
        1
  •  3
  •   3CxEZiVlQ    1 年前

    我对此表示怀疑 Makefile 在GNU make中取得成功。目标 .force_rebuild 正如报道的那样,它缺失了,GNU make和BSD bmake都失败了。在引用的链接中添加目标 Makefile .

    .PHONY: .force_rebuild
    .force_rebuild:
    
    $(APP_NAME): .force_rebuild