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

执行make vstart命令遇Makefile错误及NUL字符警告求助

Fixing "missing separator" and "NUL character seen" Errors in Makefile

Looks like you're hitting two related issues here—let's break this down and fix it step by step.

Why This Happens

The NUL character seen warning is the root cause of your problem. Null characters are invisible, but they completely mess up Make's ability to parse your file. When Make encounters these hidden weird characters, it can't properly recognize the required Tab separators for command lines, which triggers the missing separator error—even if you swear your indentation is correct.

Common causes include:

  • Copy-pasting the Makefile from a source that added hidden formatting (like a rich text editor or web page)
  • Saving the file with an encoding that includes a byte order mark (BOM)
  • Accidentally inserting null characters via your editor's odd settings

Step-by-Step Fixes

  1. Inspect for hidden characters
    Run this terminal command to reveal every character in your Makefile, including invisible ones:

    cat -A Makefile
    

    Look for ^@ (this is how null characters show up). Delete any lines or positions where you spot these.

  2. Verify Tab indentation
    Make requires that all commands under a rule (like the clean target) are indented with a single Tab character, not spaces. Double-check your editor settings to disable "Tab to spaces" conversion while working on Makefiles.

  3. Recreate the Makefile cleanly
    Sometimes the easiest fix is to start fresh:

    • Open a plain text editor (vim, nano, VS Code with "Plain Text" mode enabled)
    • Paste or type the corrected Makefile content below (ensuring no hidden characters are included)
    • Save it as Makefile with UTF-8 encoding (no BOM)

Corrected Example Makefile

Here's the properly formatted version of the Google Mock/Test Makefile you provided, with no hidden characters and correct Tab indentation:

# 一个用于构建Google Mock和Google Test并在用户测试中使用的示例Makefile。本文件是自包含的,因此您无需使用Google Test源码树中的Makefile。请根据您的环境和项目调整此文件,您可能需要将其移至项目的根目录。
#
# 用法说明:
#
# make [all] - 构建所有内容。
# make TARGET - 构建指定目标。
# make clean - 删除make生成的所有文件。
#
# 请根据您的项目需要调整以下变量定义,但GMOCK_HEADERS和GTEST_HEADERS除外,您可以在自己的目标中使用它们,但不应修改。
#
# 指向Google Test的根目录,相对于本文件的位置。
# 如果您移动了本文件,或者想使用位于其他位置的Google Test副本,请记得调整此路径。
GTEST_DIR = ../../googletest
# 指向Google Mock的根目录,相对于本文件的位置。
# 如果您移动了本文件,请记得调整此路径。
GMOCK_DIR = ..
# 用户代码的位置。
USER_DIR = ../test
# 传递给预处理器的标志。
# 将Google Test和Google Mock的头文件目录设置为系统目录,这样编译器不会在这些头文件中生成警告。
CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include
# 传递给C++编译器的标志。
CXXFLAGS += -g -Wall -Wextra -pthread
# 本Makefile生成的所有测试。请记得将您创建的新测试添加到列表中。
TESTS = gmock_test
# 所有Google Test头文件。通常您不应修改此定义。
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
                $(GTEST_DIR)/include/gtest/internal/*.h
# 所有Google Mock头文件。请注意,所有Google Test头文件也包含在此处,因为它们被Google Mock头文件引用。
# 通常您不应修改此定义。
GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \
                $(GMOCK_DIR)/include/gmock/internal/*.h \
                $(GTEST_HEADERS)
# 维护类构建目标。
all : $(TESTS)
clean :
	rm -f $(TESTS) gmock.a gmock_main.a *.o
# 构建gmock.a和gmock_main.a。这些库同时包含Google Mock和Google Test。
# 测试程序应链接gmock.a或gmock_main.a,具体取决于它是否定义了自己的main()函数。
# 如果您的测试仅使用Google Test的功能(而非Google Mock),也是可以的。
# 通常您不应调整此类内部变量(以下划线结尾标识)。
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
GMOCK_SRCS_ = $(GMOCK_DIR)/src/*.cc $(GMOCK_HEADERS)
# 为简单起见,避免依赖Google Mock和Google Test的实现细节,下面指定的依赖是保守的,未优化。
# 这没问题,因为Google Mock和Google Test编译速度快,普通用户的源码很少更改。
gtest-all.o : $(GTEST_SRCS_)
	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
	    -c $(GTEST_DIR)/src/gtest-all.cc
gmock-all.o : $(GMOCK_SRCS_)
	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
	    -c $(GMOCK_DIR)/src/gmock-all.cc
gmock_main.o : $(GMOCK_SRCS_)
	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
	    -c $(GMOCK_DIR)/src/gmock_main.cc
gmock.a : gmock-all.o gtest-all.o
	$(AR) $(ARFLAGS) $@ $^
gmock_main.a : gmock-all.o gtest-all.o gmock_main.o
	$(AR) $(ARFLAGS) $@ $^
# 构建示例测试程序。
gmock_test.o : $(USER_DIR)/gmock_test.cc $(GMOCK_HEADERS)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_test.cc
gmock_test : gmock_test.o gmock_main.a
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@

Final Checks

After setting up the corrected Makefile:

  • Run make clean to remove any leftover build files
  • Then run make or make vstart (assuming vstart is a target you've defined) to test the build

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:48:19