VS Code will not build c++ programs with multiple .ccp source files

前端 未结 7 1933
后悔当初
后悔当初 2020-11-29 07:58

Note that I\'m using VS Code on Ubuntu 17.10 and using the GCC Compiler.

I\'m having trouble building a simple program which makes use of additional .ccp files. I\'m

7条回答
  •  一生所求
    2020-11-29 08:09

    This is a windows answer for the same problem:

    I was struggling with this as well until I found the following answer at https://code.visualstudio.com/docs/cpp/config-mingw :

    You can modify your tasks.json to build multiple C++ files by using an argument like "${workspaceFolder}\\*.cpp" instead of ${file}. This will build all .cpp files in >your current folder. You can also modify the output filename by replacing "${fileDirname}\\${fileBasenameNoExtension}.exe" with a hard-coded filename (for >example "${workspaceFolder}\\myProgram.exe").

    Note that the F in workspaceFolder is capitalized.

    As an example, in my tasks.json file in my project, the text in between the brackets under "args" originally appeared as follows:

    "-g",
      "${file}",
      "-o",
      "${fileDirname}\\${fileBasenameNoExtension}.exe"
    

    This gave me reference errors because it was only compiling one and not both of my files.

    However, I was able to get the program to work after changing that text to the following:

    "-g",
    "${workspaceFolder}\\*.cpp",
    "-o",
    "${fileDirname}\\${fileBasenameNoExtension}.exe"
    

提交回复
热议问题