简体   繁体   中英

Visual Studio Code unable to compile cpp and Cuda (cu) files together

I have c++ program with multiple cpp files in VS code. Recently I learned some CUDA programming and tried to add a cuda functionality to this program. However, the nvcc compiler fails. If I try renaming the cu file to cpp I get an error:

expected primary-expression before ')' token cuda_hello<<<1, 1>>>();

I understand this is because the nvcc then ignores that the file has cuda codes. So is there a way I can compile the cpp and cu files separately and then combine them or some other solution in VS code itself, maybe by changing the tasks.json file.

I was able to resolve this. Make sure that your nvcc is up to date (v 11) and update the tasks.json arguments as follows:

"args": [
                "-std=c++17",
                "*.cu",
                "*.cpp",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],

Make sure CUDA codes are present in *.cu formats.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM