I am trying to compile and run a simple HelloWorld program via VSCode on Windows 10 but it fails to compile, even when following their tutorial.
The only feedback I receive is:
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g c:\Users\admin\programming\helloworld.cpp -o c:\Users\admin\programming\helloworld.exe" terminated with exit code: 1.
I don't even receive any further information what exactly has failed. How can this can be fixed? Quite curiously, the same command
& 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g c:\Users\admin\programming\helloworld.cpp -o c:\Users\admin\programming\helloworld.exe
performs perfectly well when I invoke it in a separate powershell.
C:\Users\admin\programming\Helloworld.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
C:\Users\admin\programming.vscode\tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
C:\Users\admin\programming.vscode\c_cpp_properties.json
{
"configurations": [
{
"name": "GCC",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"cppStandard": "c++17"
}
],
"version": 4
}
Can you try returning zero in your program?
return 0;
Maybe the program is actually compiling and running but the non-zero return is interpreted as a failure.
Related
I'm very new to c++. I use VSCode and Ubuntu 18.04. I'm trying to use onnxruntime api in c++ to deploy my net model file.
Firstly I just tested including the onnxruntime api header file
#include <iostream>
#include <ctime>
#include <vector>
#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
using namespace std;
int main() {
auto start_time = clock();
cout << "hello world" << endl;
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "test");
auto end_time = clock();
printf("Proceed exit after %.2f seconds\n", static_cast<float>(end_time - start_time) / CLOCKS_PER_SEC);
printf("Done!\n");
return 0;
}
And there's error in compiling my code. The output is
[test.cc 2023-01-05 10:08:28.381]
,,test.cc:4:10: fatal error: onnxruntime/core/session/onnxruntime_cxx_api.h: no such file or directory
#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
My onnxruntime directory is '/home/jiahao/git/onnxruntime/include/' and I have added it in tasks.json and c_cpp_properties.json.
Here is my c_cpp_properties.json
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/home/jiahao/git/onnxruntime/include/",
"/home/jiahao/git/onnxruntime/include/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
And here is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I", "/home/jiahao/git/onnxruntime/include/",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/g++"
}
]
}
When I Ctrl+click the include line in my code, I will be directed to the correct onnxruntime_cxx_api.h. So I thought the include path is right but I don't know why I cann't compile my code.
I have solved this question. I downloaded the release version of onnxruntime. And in the release package I found header files and .so file. I added the include path in c_cpp_properties.json like this:
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/include/",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/include/**",
"/usr/include/eigen3/"
],
"browse": {
"path": [
"${workspaceRoot}",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/lib/",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/lib/**"
]
},
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
And I added the include path, .so file path and lib name in tasks.json. Here I also used eigen3 library
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I", "/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/include",
"-I", "/usr/include/eigen3",
"-L", "/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/lib",
"-l", "onnxruntime",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/g++"
}
]
}
Now I can compile and run my code correctly.
I have a number of question for VS Code Settings
i am trying out to build a test.cpp file with cJSON.c and cJSON.h (from cJSON library) included in it. The code as below
#include <iostream>
#include <sstream>
#include "cJSON.h"
int main()
{
std::cout << "ello world" <<std::endl;
cJSON *fmt = NULL;
cJSON* root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject());
cJSON_AddStringToObject(fmt, "type", "rect");
cJSON_AddNumberToObject(fmt, "width", 1920);
cJSON_AddNumberToObject(fmt, "height", 1080);
cJSON_AddFalseToObject (fmt, "interlace");
cJSON_AddNumberToObject(fmt, "frame rate", 24);
char *tmp_json = cJSON_Print(root);
std::stringstream myStreamString;
myStreamString << tmp_json;
std::string myString = myStreamString.str();
std::cout << " json string is " << myString << std::endl;
cJSON_Delete(root);
free(tmp_json );
return 0;
}
First, I have an error whenever I tried to rebuild test.cpp (ie I have successfully build it one time round)
Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g /home/xx/test/* -o /home/xx/test/test
g++: fatal error: input file ‘/home/xx/test/test’ is the same as output file
compilation terminated.
I can solve only the problem by deleting the previous build or test and then rebuild
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Wonder did I fail to set anything extra in the settings? Is this the way on how mixed c++/c development should be compiled?
Thanks
Regards
Using such an input "${workspaceFolder}/*" causes inclusion of the previously built program test to the compiler arguments.
Use two globs:
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.c",
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
]
I have so far failed to get VS Code to compile a simple helloworld.cpp file with MingW-64 (v8.1.0). I'm doing this on windows 10 for the first time, and have had issues at pretty much every stage of trying to get MingW-64 to work with VS Code in one way or another, following this tutorial roughly: https://code.visualstudio.com/docs/cpp/config-mingw
I have setup my environment variables to include the path to mingw64, and can see the version numbers in terminal, no issue.
When I run my code, the terminal shows that my build finished successfully, debug returns "ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000139." and the output window just shows that it ran the .exe and .cpp file and completed. I can't see that it has printed to terminal at all.
Extensions;
C/C++,
code runner,
ESLint,
npm
HelloWorld.cpp;
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:\\mingw64\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\mingw64\\bin",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "C:\\mingw64\\bin\\g++",
"args": [
"-g",
"-o",
"a.exe",
"HelloWorld.cpp"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
I am following this procedure. And I am using MS visual studio code with minGW compiler with code runner extension. I've built b2 engine successfully I suppose. Here is the output
boost-install.generate-cmake-config-version- C:\Program Files\boost\lib\cmake\boost_math_tr1l-1.70.0\boost_math_tr1l-config-version.cmake boost-install.generate-cmake-variant- C:\Program Files\boost\lib\cmake\boost_math_tr1l-1.70.0\libboost_math_tr1l-variant-mgw92-mt-d-x32-1_70-static.cmake boost-install.generate-cmake-config-
C:\Program Files\boost\lib\cmake\boost_math-1.70.0\boost_math-config.cmake boost-install.generate-cmake-config-version-
C:\Program Files\boost\lib\cmake\boost_math-1.70.0\boost_math-config-version.cmake ...
failed updating 678 targets... ...skipped 278 targets... ...updated 16845 targets...
Task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp.exe build active file",
"command": "C:\\MinGW\\bin\\cpp.exe",
"args": [
"-g",
"${file}",
"-o",
"-L",
"-1",
"-IC:\\Program Files\\boost\\include\\boost-1_70",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
And c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\Program Files\\boost\\include\\boost-1_70"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x86"
}
],
"version": 4
}
Following is the code I am trying to run:
#include <bits/stdc++.h>
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " ");
}
But getting the following error:
PS C:\Users\dwiti\OneDrive\Documents\My Bluetooth> cd "c:\Users\dwiti\OneDrive\Documents\My Bluetooth\" ; if ($?) { g++ worthless.cpp -o worthless } ; if ($?) { .\worthless }
worthless.cpp:2:10: fatal error: boost/lambda/lambda.hpp: No such file or directory
2 | #include <boost/lambda/lambda.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Note- I am using MinGW g++ compiler and have successfully added the respected environment paths as well. And I have already tried all the previous answers solution but they are not working out for me due to some reason which I don't understand. Please do help me out in resolving this issue.
Thanks!.
I'am trying to compile a basic "Hello World" code in Visual Studio Code. But I'm new at coding, so I can't understand what does "The terminal process terminated with exit code: 1" means.
This is my task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:/MinGW/bin/g++",
"args": [
"-g", "main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
This one is c_cpp_properties.json file:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}/",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
And this is the program I'm trying to execute:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
How can I fix this problem?
If you have an error, you should google the error message.
First hit, which comes down to: VSCode cannot find the compiler. VSCode is just an IDE: it doesn't ship with a compiler.
Read this page on how to setup VSCode to work with C++.