Following a C++ tutorial, the user (using CodeBlocks) has me to add a class through the File Menu: File -> New -> Class
So now I have main.cpp, bottles.cpp and bottles.h. But, unlike his that works, mine throws an error when I try to run it:
-------------- Build: Debug in tut-002 (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -std=c++11 -I -c /home/slyde/Desktop/CB/Tutorials/tut-002/bottles.cpp -o obj/Debug/bottles.o
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
main.cpp has a main in it.
#include <iostream>
#include "bottles.h"
//using namespace std;
int main()
{
bottles bo;
return 0;
}
bottles.cpp:
#include "bottles.h"
#include <iostream>
bottles::bottles()
{
std::cout << "Am I a glass bottle? Or am I made of plastic?" << std::endl;
}
bottles.h:
#ifndef BOTTLES_H
#define BOTTLES_H
class bottles
{
public:
bottles();
//protected:
//private:
};
#endif // BOTTLES_H
And the guy in the video...he never references any necessary setting(s) to run this. Will someone tell me what do I have to do to "fix" this? T tried adding a linker option: $(LINK) -nostartfiles -g ... that I got from here (https://stackoverflow.com/questions/11116399/crt1-o-in-function-start-undefined-reference-to-main-in-linux). But that didn't work.
Thanks.
You have to use a project....
... to compile both your cpp-files to link both together to the final application.
Quote from: BlueHazzard on February 21, 2018, 10:10:39 PM
You have to use a project....
I appreciate you.
**UPDATE**I wiped out the previous files and started a new Project. I get the same error. And I'm certain this is a Project. View here: https://imgur.com/a/9VpIZ.
Any other ideas?
https://imgur.com/C09EOyg <<== shows it is Project
https://imgur.com/OHSypuy <<== runs deleted code in main
I fixed it. But I have no idea how or why it worked out this way.
I closed the Project/Workspace and was prompted that the Project had changed - would I like to save the changes. I did. Then, just out of curiosity, I reopened it. F9 and it compiled and ran as it shld've all along.
Why did it take me closing it for it to save the changes and "fix" itself?
How did you added the files?
(@devs and only for the devs: this would not have happened if we save the project before building by default ;) because without fixed (saved) project a build is not possible, like the source files also have to be saved before build... )
1) File -> New -> Project (game me main.cpp
2) File -> New-> Class (game me bottles.h and bottles.cpp)
And at the popup about selecting target you enabled the tick on both?
I did.
i see from your signature that you are using a 5 year old release of codeblocks. Can you try the latest release? Can you reproduce this problem?
Three of the Debian files won't install. Dependencies aren't satisfied. Ever. I wish Mint wld update their damn depository!
Have you passed all dep packages in a single command? Are you using the correct packages?
No. I haven't tried to knock them all out in a single cmd. Here's what I tried to use:
Quote from: BlueHazzard on February 22, 2018, 11:38:00 PM
Can you reproduce this problem?
Ten times out of ten. I can reproduce this issue with my eyes closed.
you can also try this ppa https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks
this are basically nightly builds so will get the latest version. I don't know if your linux mint is there.
Or you compile it by yourself. It is pretty easy. I tried to write a little instruction:
https://github.com/bluehazzard/codeblocks_sf/wiki/build_linux_mint_18
it is not complete but the make install way worked for me and was pretty easy.
Lightning flashed, ripping apart the heavens as Landslyde's PC filled with the latest build of CodeBlocks. And, for better or for worse, the world as we know it is surely about to change! ;D
The error's gone, btw. Thanks for your help, BlueHazzard.