构建Windows移植版Faster-RCNN时遇nvcc报错:'--ptxas-options=-v': expected a number
I’ve run into this exact nvcc error before when porting Faster-RCNN to Windows with CUDA 10.1, so let’s walk through the fixes step by step:
Root Cause
The --ptxas-options=-v flag works smoothly on Linux, but Windows’ nvcc parser can misinterpret the shorthand -v as a numerical argument instead of the verbose flag. This is a quirk of how CUDA’s compiler handles parameter formatting across operating systems.
Step-by-Step Solutions
1. Fix the Compiler Flag in Your Python Config Script
Locate the build configuration script (usually setup.py or a related .py config file for Faster-RCNN) and find the section where nvcc arguments are defined.
Before (problematic line):
extra_compile_args = {'nvcc': ['--ptxas-options=-v']}
After (fixed version):
extra_compile_args = {'nvcc': ['--ptxas-options=--verbose']}
Alternatively, you can use Windows-style parameter formatting:
extra_compile_args = {'nvcc': ['--ptxas-options=/v']}
2. Use the Correct Command Prompt Environment
Never run the build command in a regular Windows Command Prompt. Instead:
- Open the Developer Command Prompt for VS 2019 (search for it in the Start Menu)
- Activate your Python 3.7 virtual environment (if using one)
- Run your build command from here
This ensures VS 2019’s C++ build tools and CUDA 10.1’s environment variables are properly loaded, avoiding weird parsing issues.
3. Verify CUDA + VS 2019 Compatibility
Double-check these details to rule out environment mismatches:
- Confirm CUDA 10.1 is fully installed with all components (run
nvcc --versionin the dev prompt to verify) - Ensure VS 2019 has the Desktop development with C++ workload installed (this includes the required compilers and libraries CUDA needs)
- Check that your
CUDA_PATHenvironment variable points to the correct CUDA 10.1 installation directory
4. Validate Python Dependencies
Make sure your Python 3.7 environment has compatible versions of:
- PyTorch (match the version supported by your Faster-RCNN fork and CUDA 10.1)
- NumPy
- Other required packages listed in the Faster-RCNN repo’s requirements file
内容的提问来源于stack exchange,提问作者talha06

