How to create .exe from .cpp file in code blocks?

I was just starting to learn C ++, and I found this method to display the code outputs. This worked when I first compiled Structure of programme.cpp:

#include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } 

He gave me the .exe, which I opened, ran and got the perfect "Hello World!". but when I tried to compile the second, Variables.cpp:

 #include <iostream> using namespace std; int main () { int a, b; int result; a=5; b=2; a=a+1; result=ab; cout << result; return 0; } 

I did not receive .exe at all, so I could not figure out how to open it. I tried recompiling Structure of programme.cpp (after deleting all related files), but now it will no longer create .exe. The only files created are Structure of programme.o and Variables.o (in the obj \ Debug subdirectory).

The only question I could find seemed to be this , but the problem seems a bit different, and I tried to delete one of the files (so there was only one from the Program.cpp Structure or Variables.cpp in the folder), and I still had same result.

In addition, there were no compiler errors with any file, and I do not think that I changed any options in the code blocks between the structure of the working program and everything that does not work.

Thanks,

Dalkius

edit: build logs:

 Compiling: Structure of a Programme.cpp Process terminated with status 0 (0 minutes, 0 seconds) 0 errors, 0 warnings Compiling: Variables.cpp Process terminated with status 0 (0 minutes, 0 seconds) 0 errors, 0 warnings 

edit 2: Full Commandline build logs:

 Build started on: 14-12-2011 at 07:57.39 Build ended on: 14-12-2011 at 08:01.03 -------------- Clean: Debug in cplusplus.com Tutorial --------------- Done. mingw32-g++.exe -Wall -g -c "D:\My Documents\0HOME\Programming\C++\Code Blocks\cplusplus.com Tutorial\Structure of a Programme.cpp" -o "obj\Debug\Structure of a Programme.o" Process terminated with status 0 (0 minutes, 1 seconds) 0 errors, 0 warnings mingw32-g++.exe -Wall -g -c "D:\My Documents\0HOME\Programming\C++\Code Blocks\cplusplus.com Tutorial\Variables.cpp" -o obj\Debug\Variables.o Process terminated with status 0 (0 minutes, 0 seconds) 0 errors, 0 warnings 
+4
source share
4 answers

From a glance at your updated build log, it seems that the build phase is not performed to create the final executable. There are a few things you can check out and some ideas you can try:

  • Make sure the linker executable and the correct path are installed, so C :: B can find it. For MinGW, the linker is invoked through a compiler driver named "g ++. Exe". C2WKj.png
  • Verify that the Console Application is selected in the Type field. fZ4wy.png
  • If everything looks fine, but it still doesn't bind trying to create a new empty console project. Add existing files to this project and try to create it.
  • Try creating it manually from the 'cmd' command line to make sure the toolchain itself works. You should find the "mingwvars.bat" script under your mingw installation. Run the script to open the correct command line environment. Do a simple compilation with this command:

cd "D: \ My Documents \ 0HOME \ Programming \ C ++ \ Code Blocks \ cplusplus.com Tutorial"
g ++. exe -Wall -g Variables.cpp -o Variables.exe

Finally, this is what your log should look something like when it is being built correctly: C :: B build log

+4
source

EXE files are mostly built every time you run the code. Try to find the exe file of your program where you installed or copied C ++ program files.

+1
source

I am not very familiar with code blocks, but I will try to help by explaining what the compiler does. These .o files that it creates are called object files. High level compilation works as such:

1) Your source code is compiled by the compiler.

2) The compiler will interpret your code and create an object (or an .o file) for every file you have (anyway).

3) These files are then โ€œlinkedโ€ together in a compilation process known as the โ€œlinkerโ€.

4) Finally, the linker issues your .exe file.

Here, of course, there are more (for example, library files, pre-compiled libraries, preprocessing, etc.), but for your purposes you can think about it as shown above when you are just starting.

My guess is: you may have accidentally modified something using the code block composer, or it is looking for the wrong place to link files - or even the linker throws an error (although most IDEs tell you that). Again, I, unfortunately, are not very familiar with code blocks.

If there is any way in the code blocks to call "clean", you should also try this and try rebuilding. This will delete (clean) the old files that may still be present in the last build.

+1
source

After creating your program in the build log, you can see "Run:" where you can find the path to the .exe file that your program just created.

0
source

Source: https://habr.com/ru/post/1385586/


All Articles