I've just started learning C++, and to display the outputs of code I found this method. This worked when I first compiled Structure of a Programme.cpp:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
It gave me a .exe, which I opened, ran, and got a lovely 'Hello World!' appearing, but when I tried compiling a second one, Variables.cpp:
#include <iostream>
using namespace std;
int main ()
{
int a, b;
int result;
a=5;
b=2;
a=a+1;
result=a-b;
cout << result;
return 0;
}
I didn't get a .exe at all, so couldn't work out how to open it. I tried re-compiling Structure of a Programme.cpp (after deleting all the associated files), but now that won't create a .exe anymore, either. The only files created are Structure of a Programme.o and Variables.o (in a sub-directory obj\Debug).
The only question I could find that seemed similar was this, but the problem seems to be slightly different, and I tried deleting one of the files (so there was only one of Structure of a Programme.cpp or Variables.cpp in the folder) and I still had the same result.
Also, there were no compiler errors with either file, and I don't think I changed any options in Code Blocks between Structure of a Programme working and everything not working.
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
From looking at your updated build log, it appears the linking step isn't being performed to generate the final executable. There are a couple of things you can check and some ideas to try out:
cd "D:\My Documents\0HOME\Programming\C++\Code Blocks\cplusplus.com Tutorial"
g++.exe -Wall -g Variables.cpp -o Variables.exe
Lastly, this is what your log should approximately look like when it's building correctly:
EXE files are mostly build each time when you run the code. Try finding the exe file of your program where you have installed or copied the C++ program files.
I'm not too familiar with codeblocks, but I'll try to help by explaining what the compiler is doing. Those .o files it's creating are called Object Files. Compilation at a high level works as such:
1) Your source code get's compiled by a compiler.
2) The compiler will interpret your code and create an object (or .o file) for each file you have (in general anyways).
3) These files are then "linked" together in part of the compilation process known as "the linker".
4) Finally, the linker puts out your .exe file.
There's of course more to this (such as library files, pre-compiled dlls, pre-processing, etc.) but for your purposes you can think of it like above as you're just starting out.
My guess would be you may have accidentally modified something with codeblocks linker, or it is looking in the wrong place to link the files - or even the linker is throwing an error (though most IDEs inform you of this). Again, I'm unfortunately not too familiar with codeblocks.
If there is any way in codeblocks to trigger a "clean" you should also try that and try rebuilding. This will remove (clean) up any old files that may still be there from last build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With