You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在无CMake的大学HCP服务器仅用Make编译CMake项目

Fixing "make: /usr/local/bin/cmake: Command not found" When Using CMake-Generated Makefiles Without CMake

Absolutely! That error pops up because the Makefile CMake creates still has hardcoded checks that try to run CMake every time you execute make—which obviously fails on your server where CMake isn't installed. Let's go through a few solid solutions to get a standalone Makefile that only needs make to work.

Why Your Current Makefile Fails

CMake-generated Makefiles include a target called cmake_check_build_system that runs CMake to verify the build configuration hasn't changed. When you run make on the server, this target tries to call the missing cmake command, hence the error code 127.

Solution 1: Modify the CMake-Generated Makefile (Quick Fix)

You can tweak the Makefile you already have to remove the CMake dependency:

  1. Open the Makefile you generated locally.
  2. Find the cmake_check_build_system rule—it'll look something like this:
    cmake_check_build_system:
    	$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
    
  3. Replace it with an empty or no-op rule to skip the check:
    cmake_check_build_system:
    	@echo "Skipping CMake build system check"
    
  4. Next, find the top-level all target (usually the first rule) and remove cmake_check_build_system from its dependencies. For example, change:
    all: cmake_check_build_system all
    
    To:
    all: my_program  # Replace with your actual executable target name
    
  5. Save the modified Makefile, re-upload it to the server, and run make—it should now work without needing CMake.

Solution 2: Write a Custom Makefile (Best for Small Projects)

If your project isn't overly complex, writing a manual Makefile is the most reliable way to avoid any CMake dependencies. Here's a simple example for a C++ project:

# Compiler and flags
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++17 -I./include  # Add your header dirs here

# Object files (list all .cpp files converted to .o)
OBJECTS = main.o utils.o helper.o

# Final executable name
TARGET = my_app

# Default target: build the executable
all: $(TARGET)

# Link object files into the executable
$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) -o $@ $^

# Compile .cpp files into .o objects
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# Clean up build files
clean:
	rm -f $(OBJECTS) $(TARGET)

Just adjust the variables (OBJECTS, TARGET, CXXFLAGS) to match your project structure, upload this Makefile along with your source code, and run make on the server—no CMake required.

Solution 3: Generate a CMake-Free Makefile Locally

You can tell CMake to generate a Makefile that skips the dependency checks right from the start. When running CMake locally, add the CMAKE_SKIP_RULE_DEPENDENCY flag:

cmake -DCMAKE_SKIP_RULE_DEPENDENCY=ON ../path/to/source

This flag disables the rules that require CMake to be present during the make step. The resulting Makefile can be uploaded to the server and used directly with make.

Which Solution Should You Pick?

  • Use Solution 1 if you need a quick fix for an existing CMake-generated Makefile.
  • Use Solution 2 if your project is small enough to manage with a manual Makefile—it's more transparent and avoids any CMake-related quirks.
  • Use Solution 3 if you want to stick with CMake for local configuration but need a server-friendly Makefile output.

内容的提问来源于stack exchange,提问作者mehrdad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:23:42