"/utf-8" option for the host function in cuda + msvc

I’m having an issue with character set incompatibility and don’t know how to fix it.

I compiled the .cu file on the Windows platform, where the fmtlib functions were used in the host function and the utf-8 character set was specified. The character set is specified to msvc via the -Xcompiler “/utf-8” option.
Here is the compile command:

"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\bin\\nvcc" -c -G -g -lineinfo -Xcompiler "-FS -Zi -Fdbuild\\xmake\\windows\\x64\\debug\\compile.test_code_cuda.pdb" -O0 -Ivcpkg_installed\x64-windows\include "-IC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\include" -DFMT_HEADER_ONLY -std=c++20 -rdc=true --extended-lambda --expt-relaxed-constexpr -Xcompiler \"/utf-8\" -v -keep -m64 -gencode arch=compute_61,code=sm_61 -o build\xmake\.objs\test_code_cuda\windows\x64\debug\src\main.cu.obj src\main.cu

And here is the error:

D:\Code\Mycode\code_demo_test\cuda\vcpkg_installed\x64-windows\include\fmt\base.h(458): error: static assertion failed with "Unicode support requires compiling with /utf-8"

It is known that if the .cpp file using the same fmtlib functions was compiled directly with msvc, the problem does not occur after using the “/utf-8” option.

what happens if you do:

-Xcompiler "/utf-8"

instead of:

This is just a display difference from build tools. Here are the commands generated by VS2022 during compilation, and the same error occurred.

D:\Code\Mycode\code_demo_test\cuda>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin\nvcc.exe"  --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64" -x cu -rdc=true  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include" -I"D:\Code\Mycode\code_demo_test\cuda\/vcpkg_installed\x64-windows\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include"  -G   --keep-dir test_code_cuda1\x64\Debug  -maxrregcount=0   --machine 64 --compile -cudart shared --std=c++20  --expt-relaxed-constexpr -gencode arch=compute_61,code=sm_61 -g  -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -DFMT_HEADER_ONLY -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdtest_code_cuda1\x64\Debug\vc143.pdb" -o D:\Code\Mycode\code_demo_test\cuda\test_code_cuda1\x64\Debug\main.cu.obj "D:\Code\Mycode\code_demo_test\cuda\src\main.cu" -Xcompiler "/utf-8"
1 Like

See also Compilation Error with nvcc using CUDA 11.8 on Windows when the file is saved as UTF-8

Hi,

Did you solve the issue? Thanks!

Sway

I’ve tried many times and still haven’t solved the problem.

I tried the latest fmtlib. There is a cuda test, but i can’t compile it neither. It looks weird. Not sure the problem is something to do with NVCC or fmtlib.

HI @Robert_Crovella,

Do you have any idea on this issue? Thanks.

Sway

The latest fmtlib introduced stricter Unicode checking. When the .cpp files are in utf-8 format, we need to explicitly pass the “/utf-8” option in msvc to enable the character set. So I guess that the format of intermediate files generated by nvcc or the wrong passing of “/utf-8” option may cause this problem.

the observation may be connected to using -std=c++20 as well.

I changed c++20 to c++17, and the previous error still occurs.