本人在实验室服务器上复现代码,配置环境的时候遇到gcc与cuda版本不兼容的问题,但是又没有root权限。因此在网上搜寻资料以解决。
——————————————————————————
因为没有root权限(sudo),而gcc和g++又是安装在系统路径下,在进行实验或者复现代码的时候需要更换gcc版本(比如需要和不同的cuda版本兼容,具体兼容见链接https://stackoverflow.com/questions/6622454/cuda-incompatible-with-my-gcc-version),但是又没有root权限。
因此考虑在conda环境下安装兼容版本的gcc,用它来进行编译和环境配置。
操作前:
安装一些包(需要gcc编译)时报错:
/usr/local/cuda/include/crt/host_config.h:132:2: error: #error -- unsupported GNU version! gcc versions later than 11 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. 132 | #error -- unsupported GNU version! gcc versions later than 11 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. | ^~~~~ [2/2] c++ -MMD -MF
也就是cuda和gcc版本不兼容,高于11版本号的gcc都不被当前cuda版本号支持(我的cuda版本号是11.8)
具体操作步骤如下:
直接运行
conda install -c conda-forge cxx-compiler
操作后
运行代码不再报错:
成功!!!