使用CMake编译工程软件FlameMaster时遭遇Error 141编译失败问题求助
Error 141 from flex is usually a clue that the flex process got terminated by an unhandled signal—most commonly SIGPIPE, but sometimes it’s a crash in flex itself or even an out-of-memory issue. Let’s walk through how to diagnose and fix this step by step:
1. Double-Check Flex Version Compatibility
The build log shows it’s using flex 2.5.35, and older projects like FlameMaster often have strict dependencies on specific flex versions. Newer releases (2.6.x and above) can introduce breaking changes that cause flex to crash mid-compile.
- First, check what flex version you have installed:
flex --version - If you’re running a newer version, install flex 2.5.35 specifically. On macOS, Homebrew has a formula for this:
brew install flex@2.5.35 # Make sure this version takes priority over your system flex export PATH="/usr/local/opt/flex@2.5.35/bin:$PATH" - Wipe your build directory, re-run CMake, and try building again.
2. Test Flex Manually on the Source File
The error happens when generating src/FlameMan/lexer.yy.C from a flex source file (look for .l or .lex files in that directory). Malformed flex rules or syntax errors can cause flex to crash silently with error 141.
- Navigate to the FlameMan source directory and run flex directly on the input file to get detailed error messages:
Replacecd src/FlameMan flex -o lexer.yy.C your_lexer_source.lyour_lexer_source.lwith the actual name of the flex file (you’ll find it in that folder). This will show you exactly where flex is failing—whether it’s a missing brace, invalid regex, or other syntax issue.
3. Tweak CMake’s Flex Configuration
Sometimes CMake’s flex integration passes incorrect flags that cause crashes. Check the project’s CMakeLists.txt for flex-related directives:
- Look for lines using
FLEX_TARGETor similar. Try adding verbose output to flex to see what commands are being executed:set(FLEX_FLAGS "-v") # Enable verbose debug output from flex FLEX_TARGET(FlameManScanner path/to/your/lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.yy.C) - Re-run CMake and build again—this verbose output will help you spot if flex is being passed invalid arguments or choking on specific rules.
4. Rule Out System Resource Issues
On macOS, processes can sometimes be terminated if they hit memory limits or stack size restrictions.
- Try increasing the stack size temporarily before running make:
ulimit -s unlimited make --build . --target install --config Release - Monitor your system’s memory usage while building—if flex is consuming an unusual amount of RAM, that could be the culprit (though this is rare for most lexer files).
5. Verify SDK and Compiler Compatibility
You’ve set the macOS 10.14 SDK, but make sure your chosen compiler (/usr/bin/c++) plays nice with this older SDK.
- Check your compiler version:
If you’re using a newer Xcode version (11+), the 10.14 SDK might have compatibility issues with the latest clang. Try switching to an SDK that matches your current macOS version, or install an older Xcode version that supports 10.14 properly./usr/bin/c++ --version
内容的提问来源于stack exchange,提问作者not_testpilot

