Reputation: 1
I have been using Code Runner for one single C++ file. However, I'm having issues when I try to compile more than one file together using the extension. As I read in a post and in other forums, the extension automatically reads the include statements and compiles all the necesary files if they are in the same folder. I don't know why that isn't working in my case. This is the extension configuration (I put the entire settings.json just in case):
"code-runner.fileDirectoryAsCwd": true,
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"zig": "zig run",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "csi -script",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runghc",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded",
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
"FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"sml": "cd $dir && sml $fileName",
"mojo": "mojo run"
},
"tabnine.experimentalAutoImports": true,
"security.workspace.trust.untrustedFiles": "open",
"code-runner.defaultLanguage": "c++",
"code-runner.enableAppInsights": false,
"code-runner.runInTerminal": true
}
This is the file I was tring to compile ('func.h' is in the same folder):
#include <iostream>
#include "func.h"
using namespace std;
int main(){
print();
return 0;
}
And this is the error I get:
cc301Ipx.o:tempCodeRunnerFile.cpp:(.text+0xe): undefined reference to `print()'
I tried changing the extension configuration but I couldn't solve the problem.
Upvotes: 0
Views: 296
Reputation: 1
"cd $dir && g++ *.cpp -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
Upvotes: 0