CUDA配置环境(三):nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 已解决

这篇具有很好参考价值的文章主要介绍了CUDA配置环境(三):nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 已解决。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

解决在QT中编写CUDA程序出现nvcc fatal : Could not set up the environment for Microsoft Visual Studio using的问题

问题详情

在QT编写CUDA代码,在已经配好.pro文件中的代码,并且CUDA安装没有问题,还可以在VS2017中正常运行CUDA程序时,一开始debug的时候我遇到了以下问题: Could not set up the environment for Microsoft Visual Studio using,

nvcc fatal   : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)
				/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'

我在网上找了好久的解决办法,国外的社区还有国内的社区,都没有详细可靠的解决方案,总结下来他们的方法大致包括检查系统的环境变量,CUDA的路径不能有空格,nvcc的输入太长等,但这些都不能解决这个问题。

这确实花费了我很长的时间还有精力,因此我发布出我的解决方案,后面也有详细的解决过程,希望我的分享可以帮助到你。

解决方案

下面我会给出解决方案,想直接解决问题的看完这一部分就行了,想了解我解决问题的过程的可以看第三部分。
下面是解决方案:找到报错中的文件路径,可以参考我的路径:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build
找到相应的文件,用记事本打开vcvarsall.bat,复制其中的代码到vcvars64.bat,最终vcvars64.bat中的内容为:


@if not "%VSCMD_DEBUG%" GEQ "3" echo off

@REM -------------------------------------------------------------------------
:parse_args
set __VCVARSALL_STORE=
set __VCVARSALL_WINSDK=
set __VCVARSALL_PARSE_ERROR=
set __VCVARSALL_TARGET_ARCH=
set __VCVARSALL_HOST_ARCH=
set __VCVARSALL_VER=

@REM Parse command line arguments.  This implementation does not care about
@REM argument order.

if "%VSCMD_DEBUG%" GEQ "1" (
    @echo [DEBUG:%~nx0] init with arguments '%*'
)

set __VCVARSALL_PARSE_ERROR=0
set "__VCVARSALL_ARGS_LIST=%*"
call :parse_loop
set __VCVARSALL_ARGS_LIST=

if "%VSCMD_DEBUG%" GEQ "1" (
    @echo [DEBUG:%~nx0] Command line parse completed with values:
    @echo [DEBUG:%~nx0] __VCVARSALL_TARGET_ARCH='%__VCVARSALL_TARGET_ARCH%'
    @echo [DEBUG:%~nx0] __VCVARSALL_HOST_ARCH='%__VCVARSALL_HOST_ARCH%'
    @echo [DEBUG:%~nx0] __VCVARSALL_WINSDK='%__VCVARSALL_WINSDK%'
    @echo [DEBUG:%~nx0] __VCVARSALL_STORE='%__VCVARSALL_STORE%'
    @echo [DEBUG:%~nx0] __VCVARSALL_HELP='%__VCVARSALL_HELP%'
    @echo [DEBUG:%~nx0] __VCVARSALL_PARSE_ERROR='%__VCVARSALL_PARSE_ERROR%'
)

if "%__VCVARSALL_CLEAN_ENV%" NEQ "" goto :call_vsdevcmd
if "%__VCVARSALL_PARSE_ERROR%" NEQ "0" goto :usage_error
if "%__VCVARSALL_HELP%" NEQ "" goto :usage

@REM -------------------------------------------------------------------------
:check_platform
@REM This script is installed to ...\VC\Auxiliary\Build.
@REM vsdevcmd is installed to    ...\Common7\Tools.
if not exist "%~dp0..\..\..\Common7\Tools\vsdevcmd.bat" goto missing

@REM Assemble the arguments to pass to vsdevcmd.bat
if "%__VCVARSALL_TARGET_ARCH%" == "" goto :usage_error
if "%__VCVARSALL_HOST_ARCH%" == "" goto :usage_error

set "__VCVARSALL_VSDEVCMD_ARGS=-arch=%__VCVARSALL_TARGET_ARCH% -host_arch=%__VCVARSALL_HOST_ARCH%"
if "%__VCVARSALL_WINSDK%" NEQ "" (
    set "__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -winsdk=%__VCVARSALL_WINSDK%"
)
if "%__VCVARSALL_STORE%" NEQ "" (
    set "__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -app_platform=UWP"
)
if "%__VCVARSALL_VER%" NEQ "" (
    set "__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -vcvars_ver=%__VCVARSALL_VER%"
)
if "%__VCVARSALL_SPECTRE%" NEQ "" (
    set "__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -vcvars_spectre_libs=%__VCVARSALL_SPECTRE%"
)

goto :call_vsdevcmd

@REM -------------------------------------------------------------------------
@REM Call vsdevcmd.bat to setup the command prompt environment

:call_vsdevcmd

@REM This temporary environment variable is used to control setting of VC++ 
@REM command prompt-specific environment variables that should not be set
@REM by the VS Developer Command prompt (specifically vsdevcmd\ext\vcvars.bat). 
@REM The known case this effects is the Platform environment variable, which 
@REM will override platform target for .NET builds.
set VSCMD_VCVARSALL_INIT=1

@REM Special handling for the /clean_env argument
if "%__VCVARSALL_CLEAN_ENV%" NEQ "" (
    call "%~dp0..\..\..\Common7\Tools\vsdevcmd.bat" /clean_env
    goto :end
)

call "%~dp0..\..\..\Common7\Tools\vsdevcmd.bat" %__VCVARSALL_VSDEVCMD_ARGS%

if "%ERRORLEVEL%"=="0" (
    @REM Print the target command prompt architecture...
    if "%__VCVARSALL_HOST_ARCH%" NEQ "%__VCVARSALL_TARGET_ARCH%" (
        echo [%~nx0] Environment initialized for: '%__VCVARSALL_HOST_ARCH%_%__VCVARSALL_TARGET_ARCH%'
    ) else (
        echo [%~nx0] Environment initialized for: '%__VCVARSALL_TARGET_ARCH%'
    )
)
goto :end

:parse_loop
for /F "tokens=1,* delims= " %%a in ("%__VCVARSALL_ARGS_LIST%") do (
    if "%VSCMD_DEBUG%" GEQ "2" (
        @echo [DEBUG:%~nx0] inner argument {%%a}
    )
    call :parse_argument %%a
    set "__VCVARSALL_ARGS_LIST=%%b"
    goto :parse_loop
)

exit /B 0

:parse_argument

@REM called by :parse_loop and expects the arguments to either be:
@REM 1. a single argument in %1
@REM 2. an argument pair from the command line specified as '%1=%2'

set __local_ARG_FOUND=
@REM Architecture
if /I "%1"=="x86" (
    set __VCVARSALL_TARGET_ARCH=x86
    set __VCVARSALL_HOST_ARCH=x86
    set __local_ARG_FOUND=1
)
if /I "%1"=="x86_amd64" (
    set __VCVARSALL_TARGET_ARCH=x64
    set __VCVARSALL_HOST_ARCH=x86
    set __local_ARG_FOUND=1
)
if /I "%1"=="x86_x64" (
    set __VCVARSALL_TARGET_ARCH=x64
    set __VCVARSALL_HOST_ARCH=x86
    set __local_ARG_FOUND=1
)
if /I "%1"=="x86_arm" (
    set __VCVARSALL_TARGET_ARCH=arm
    set __VCVARSALL_HOST_ARCH=x86
    set __local_ARG_FOUND=1
)
if /I "%1"=="x86_arm64" (
    set __VCVARSALL_TARGET_ARCH=arm64
    set __VCVARSALL_HOST_ARCH=x86
    set __local_ARG_FOUND=1
)
if /I "%1"=="amd64" (
    set __VCVARSALL_TARGET_ARCH=x64
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="x64" (
    set __VCVARSALL_TARGET_ARCH=x64
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="amd64_x86" (
    set __VCVARSALL_TARGET_ARCH=x86
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="x64_x86" (
    set __VCVARSALL_TARGET_ARCH=x86
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="amd64_arm" (
    set __VCVARSALL_TARGET_ARCH=arm
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="x64_arm" (
    set __VCVARSALL_TARGET_ARCH=arm
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="amd64_arm64" (
    set __VCVARSALL_TARGET_ARCH=arm64
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="x64_arm64" (
    set __VCVARSALL_TARGET_ARCH=arm64
    set __VCVARSALL_HOST_ARCH=x64
    set __local_ARG_FOUND=1
)
if /I "%1"=="-vcvars_ver" (
    set "__VCVARSALL_VER=%2"
    set __local_ARG_FOUND=1
)
if /I "%1"=="/vcvars_ver" (
    set "__VCVARSALL_VER=%2"
    set __local_ARG_FOUND=1
)
if /I "%1"=="--vcvars_ver" (
    set "__vcvarsall_ver=%2"
    set __local_ARG_FOUND=1
)
if /I "%1"=="-vcvars_spectre_libs" (
    set "__VCVARSALL_SPECTRE=%2"
    set __local_ARG_FOUND=1
)
if /I "%1"=="/vcvars_spectre_libs" (
    set "__VCVARSALL_SPECTRE=%2"
    set __local_ARG_FOUND=1
)
if /I "%1"=="--vcvars_spectre_libs" (
    set "__vcvarsall_SPECTRE=%2"
    set __local_ARG_FOUND=1
)
if /I "%1"=="help" (
    set __VCVARSALL_HELP=1
    set __local_ARG_FOUND=1
)
if /I "%1"=="/help" (
    set __VCVARSALL_HELP=1
    set __local_ARG_FOUND=1
)
if /I "%1"=="-help" (
    set __VCVARSALL_HELP=1
    set __local_ARG_FOUND=1
)
if /I "%1"=="/?" (
    set __VCVARSALL_HELP=1
    set __local_ARG_FOUND=1
)
if /I "%1"=="-?" (
    set __VCVARSALL_HELP=1
    set __local_ARG_FOUND=1
)

@REM -- /clean_env --
@REM Mostly used for internal testing to restore the state of
@REM the command line environment to its state prior to vcvarsall.bat
@REM being executed.
if /I "%1"=="/clean_env" (
    set __VCVARSALL_CLEAN_ENV=/clean_env
    set __local_ARG_FOUND=1
)
if /I "%1"=="-clean_env" (
    set __VCVARSALL_CLEAN_ENV=/clean_env
    set __local_ARG_FOUND=1
)

@REM Windows SDK Version
if /I "%1"=="8.1" (
    set "__VCVARSALL_WINSDK=8.1"
    set __local_ARG_FOUND=1
)

set __temp1=%1
if /I "%__temp1:~0,3%"=="10." (
    set "__VCVARSALL_WINSDK=%1"
    set __local_ARG_FOUND=1
)
set __temp1=

@REM Store/UWP
if /I "%1"=="store" (
    set "__VCVARSALL_STORE=-app_platform=UWP"
    set __local_ARG_FOUND=1
)
if /I "%1"=="uwp" (
    set "__VCVARSALL_STORE=-app_platform=UWP"
    set __local_ARG_FOUND=1
)

if "%__local_ARG_FOUND%" NEQ "1" (
    set /A __VCVARSALL_PARSE_ERROR=__VCVARSALL_PARSE_ERROR+1
    if "%2"=="" (
        @echo [ERROR:%~nx0] Invalid argument found : %1
    ) else (
        @echo [ERROR:%~nx0] Invalid argument found : %1=%2
    )
)
set __local_ARG_FOUND=
exit /B 0

:usage_error
echo [ERROR:%~nx0] Error in script usage. The correct usage is:
goto :usage

:usage
echo Syntax:
echo     %~nx0 [arch] [platform_type] [winsdk_version] [-vcvars_ver=vc_version] [-vcvars_spectre_libs=spectre_mode]
echo where : 
echo     [arch]: x86 ^| amd64 ^| x86_amd64 ^| x86_arm ^| x86_arm64 ^| amd64_x86 ^| amd64_arm ^| amd64_arm64
echo     [platform_type]: {empty} ^| store ^| uwp 
echo     [winsdk_version] : full Windows 10 SDK number (e.g. 10.0.10240.0) or "8.1" to use the Windows 8.1 SDK.   
echo     [vc_version] : {none} for default VS 2017 VC++ compiler toolset ^|
echo                    "14.0" for VC++ 2015 Compiler Toolset ^|
echo                    "14.1x" for the latest 14.1x.yyyyy toolset installed (e.g. "14.11") ^|
echo                    "14.1x.yyyyy" for a specific full version number (e.g. 14.11.25503)
echo     [spectre_mode] : {none} for default VS 2017 libraries without spectre mitigations ^|
echo                      "spectre" for VS 2017 libraries with spectre mitigations
echo:
echo The store parameter sets environment variables to support Universal Windows Platform application 
echo development and is an alias for 'uwp'.
echo:
echo For example:
echo     %~nx0 x86_amd64
echo     %~nx0 x86_amd64 10.0.10240.0
echo     %~nx0 x86_arm uwp 10.0.10240.0
echo     %~nx0 x86_arm onecore 10.0.10240.0 -vcvars_ver=14.0
echo     %~nx0 x64 8.1
echo     %~nx0 x64 store 8.1
echo:
echo Please make sure either Visual Studio or C++ Build SKU is installed.
goto :end

:missing
echo The specified configuration type is missing.  The tools for the
echo configuration might not be installed.
goto :end

:end
set __VCVARSALL_TARGET_ARCH=
set __VCVARSALL_HOST_ARCH=
set __VCVARSALL_STORE=
set __VCVARSALL_WINSDK=
set __VCVARSALL_PARSE_ERROR=
set __VCVARSALL_CLEAN_ENV=
set VSCMD_VCVARSALL_INIT=
set __VCVARSALL_VSDEVCMD_ARGS=
set __VCVARSALL_HELP=
set __VCVARSALL_VER=
set __VCVARSALL_SPECTRE=

这样问题就解决了,可以顺利Debug

解决过程

(1)在一开始debug的时候我遇到了以下问题: Could not set up the environment for Microsoft Visual Studio using

nvcc fatal   : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'

我在网上找了好久的解决办法,国外的社区还有国内的社区,都没有详细可靠的解决方案,总结下来大致的方法包括检查系统的环境变量,CUDA的路径不能有空格,nvcc的输入太长等,但这些都不能解决这个问题。

(2)在尝试了很长时间之后,我还是决定根据报错信息入手,我找到了出现问题的vcvars64.bat这个文件,默认路径在:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build
并用记事本打开,其中的内容如下,只有这一行:

@call "%~dp0vcvarsall.bat" x64 %*

(3)之后我在QT的工具->选项->Kits->编译器,发现QT中的编译器使用都是与上述vcvars64.bat同一路径下的vcvarsall.bat文件。
CUDA配置环境(三):nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 已解决
(4)因此我首先想要改变我的.pro文件调用vcvars文件的代码,有关的代码如下:

SYSTEM_TYPE = 64 

改变等号右边的值,可以改变调试时使用的vavars文件的后缀,但是他只能接收数字输入,所以也无法使其调用vcvarsall.bat,因此只能另辟蹊径,考虑将vcvarsall.bat的内容复制到vcvars64.bat,达到调用vcvarsall.bat的效果。

(5)最终解决方案,用记事本打开vcvarsall.bat复制其中的代码到vcvars64.bat文章来源地址https://www.toymoban.com/news/detail-438846.html

到了这里,关于CUDA配置环境(三):nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 已解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred……

    本人使用 idea 创建 web 工程后,运行 tomcat 服务器时出现报错: 并且 tomcat 出现错误信息: 本人尝试更换 JDK 版本,但并没有什么变化。最后发现是忘了修改 Project Structure... 中的 SDK 。 由于需要修改配置的地方较多,很容易漏掉一小步,下面整理了比较全面的需要修改的地方

    2024年02月07日
    浏览(62)
  • A fatal error occurred. The required library hostfxr.dll could not be found.错误处理

    一个可控制台程序使用.NET 6开发,发行版运行出现如下错误: A fatal error occurred. The required library hostfxr.dll could not be found. If this is a self-contained application, that library should exist in [D:xxxServer]. If this is a framework-dependent application, install the runtime in the global location [C:Program Files (x86)d

    2024年02月12日
    浏览(56)
  • NotImplementedError: Could not run ‘torchvision::nms‘ with arguments from the ‘CUDA‘ backend.

    问题描述:在跑YOLOV5S代码时,出现了下面这个错误。 原因分析:网上说的是cuda的版本和torch的版本不对应。但是自己明明是在pytorch的官网上下载的呀,并且自己的电脑上的cuda版本是11.8,但是pytorch官网上的cuda的最高版本是11.7,我复制里面的命令安装的,但是运行还是出现

    2024年02月16日
    浏览(52)
  • Error: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Progra

    本人学化学的小白,自学JAVA。本来电脑第一次本来装JDK17的时候,应该是装成功了,后来eclipse出了点问题,我以为是JDK17的问题,就卸载重装, 结果就悲剧了。 每次重装都有问题,win命令行输入java -v都显示下面错误。 在csdn里搜到好多方法 这个原因是因为在安装JDK的时候在

    2023年04月09日
    浏览(50)
  • NotImplementedError: Could not run ‘torchvision::nms‘ with arguments from the ‘CUDA‘ backend解决办法

    NotImplementedError: Could not run \\\'torchvision::nms\\\' with arguments from the \\\'CUDA\\\' backend. This could be because the operator doesn\\\'t exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resoluti

    2024年02月17日
    浏览(48)
  • win10+2019+cuda11.6 nvcc fatal : Cannot find compiler ‘cl.exe‘ in PATH

    第一步: 在系统变量无名称变量 Path 列表中添加如下 2 个位置 C:Program Files (x86)Microsoft Visual Studio2019CommunityVCToolsMSVC*14.27.29110*(根据自己环境该码不同)binHostx64x64 C:Program Files (x86)Microsoft Visual Studio2019CommunityCommon7IDE 第二步: 在系统变量中新建一个变量起名为 LIB,

    2024年02月09日
    浏览(43)
  • Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program wi

    win10安装java(jdk或jre) 环境报错: Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program wil 一,下包安装java 二,解决报错 大功告成 环境报错: Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program wil 在官网下载jdk包 官网地址 直接下

    2024年02月07日
    浏览(47)
  • Ubuntu22.04 系统 解决输入nvcc -V 显示sudo apt-get install nvidia-cuda-toolkit安装 即CUDA环境配置问题

    参考: ubuntu解决没有nvcc命令的错误_nvcc没有_妖妖灵誓言的博客-CSDN博客 Linux 进入root管理员权限_linux进入管理员模式命令_Xav Zewen的博客-CSDN博客 Linux 进入root管理员权限_linux进入管理员模式命令_Xav Zewen的博客-CSDN博客   ----------------------------------------------解决输入nvcc -V-------

    2024年02月03日
    浏览(58)
  • Jmeter启动报错处理方法:Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurr

    一、切到jemter/bin路径,双击‘ApacheJMeter.jar’文件 二、切到jemter/bin路径,双击’jmeter.sh’文件 以上两种方法均可尝试。 网上CSDN、简书都说是内存不足改bat文件加,加全局变量,怀疑JDK版本和环境变量配置,装过无数遍,最终都不好使。这两种方法绕过了仅执行bat文件启动,

    2024年02月11日
    浏览(69)
  • Linux查看CUDA版本以及nvcc: command not found

    在日常使用中,在配置镜像以及使用开源网站时经常需要查询CUDA版本,版本也确实十分的重要。一般的我们有三种常见的查询方式。 查看当前Cuda的版本,即实际安装的Cuda版本 nvcc -V(nvcc --version) nvcc 是The main wrapper for the NVIDIA CUDA Compiler suite. Used to compile and link both host and

    2024年02月04日
    浏览(41)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包