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?
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].o
And 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