c++commandcommand-prompt
I am very new to c++ and using the command prompt.
I have multiple .cpp and .h files that run fine on my IDE (Code::blocks) running GNU GCC as the compiler. It displays what I need it too but when I try to use the command prompt and type "g++ file1.cpp file2.cpp …." then "./a.out
I get the error "'.' is not recognized as an internal or external command, operable program or batch file."
I have
cygwin64 with the proper g++, cdb, make packages installed and the path setup.
what have I messed up?
Best Solution
In command-prompt you just add executable filename (e.g. out.exe)
In powershell run the executable file like .\out.exe.
The command :
g++ -c [source file].cpp produces object file [source file].oAnd The command :
g++ -o [executable file] [object file].o produces object file [executable]For example Compiling "hello.cpp" into executable "hello.exe" in one step and running it :
Z:\cpp> g++ -o hello.exe hello.cpp Z:\cpp> hello.exe
Create the exe file using object files :
Z:\cpp> g++ -c file1.cpp Z:\cpp> g++ -c file2.cpp Z:\cpp> g++ -o out.exe file1.o file1.o Z:\cpp> out.exe
I am trying to set up the VScode with C++ Compiler
By following this tutorial
enter link description here
and the problem I got is (By running the code with code runner)
'g++' is not recognized as an internal or external command,
operable program or batch file.
enter image description here
and if I run with the debug option I got this problem
The preLaunchTask 'build & run file' terminated with exit code 1.enter image description here
This is my "c_cpp_properties.json"
{ "configurations": [ { "name": "Win32", "intelliSenseMode": "clang-x64", "defines": [ "_DEBUG", "UNICODE", "__GNUC__=7", "__stdcall=attribute((stdcall))", "__cdecl=__attribute__((__cdecl__))", "__cplusplus=201703L" ], "includePath": [ "${workspaceFolder}/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include" ], "browse": { "path": [ "${workspaceFolder}/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include" ], "limitSymbolsToIncludedHeaders": false, "databaseFilename": "" }, "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4}
This is my "launch.json"
{ "version": "0.2.0", "configurations": [ { "name": "Run C/C++", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW64/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "build & run file" }, { "name": "Debug C/C++", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW64/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "build & debug file" } ] }And this is my "tasks.json"
{ "version": "2.0.0", "tasks": [ { "label": "build & debug file", "type": "shell", "command": "g++", "args": [ "-g", "-o", "${fileBasenameNoExtension}", "${file}" ], "group": { "kind": "build", "isDefault": true } }, { "label": "build & run file", "type": "shell", "command": "g++", "args": [ "-o", "${fileBasenameNoExtension}", "${file}" ], "group": { "kind": "build", "isDefault": true } } ] }I just want to study C++ and I try a lot of way on the Internet for days and I still can't fix it Please help.
Thank you.