Welcome, Guest. Please login or register.

Author Topic: G++ problems  (Read 3933 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline alxTopic starter

G++ problems
« on: November 26, 2003, 10:51:24 AM »
I'm just starting to learn C++, and I've downloaded GCC from Aminet.  I've installed everything as it says and if I do a standard "Hello World" program in C and go:

Work:>GCC -o helloc hello.c

Work:>helloc

It runs nicely.  Now if i write a C++ program:

Quote

#include

int main ()
{
  std::cout << "Hello C++!\n";
  return 0;
}


And go:

Work:>G++ -o hellocpp hello.cpp

Work:>hellocpp

It cannot find "hellocpp" - the compiler hasn't actually written an executable.  If I change the sourcecode a bit:

Quote

#include

int main ()
{
  std::cout << "Hello C++!\n";
  return 0;
}


The compiler compains that it cannot find the header, so I guess it's doing something.  If i do something like this though:

Quote

#include

inain ()

  stdanythjng::cut << "Hello C++!\n" let's not use semicolons
   gerbil
}}}}}


It doesn't actually give any errors, so I suspect the C++ compiler (not the preprocessor) is at fault.  Any ideas?  I'm a C/C++ newbie, and it's running under WinUAE (AIAB)

Offline Eniodis

  • Newbie
  • *
  • Join Date: Feb 2003
  • Posts: 17
    • Show only replies by Eniodis
Re: G++ problems
« Reply #1 on: November 26, 2003, 11:07:58 AM »
Try your first C++ program but...

#include // without .h !

Does it work ?
 

Offline alxTopic starter

Re: G++ problems
« Reply #2 on: November 26, 2003, 12:05:07 PM »
Quote
Try your first C++ program but...

#include // without .h !

Does it work ?


No - it complains it cannot find the header files (they all end in .h - even for C++)

---edit---

I'm not in front of my computer now BTW so I cannot check for certain, but that's what I remember...

Offline Ratto

  • Newbie
  • *
  • Join Date: Oct 2002
  • Posts: 16
    • Show only replies by Ratto
Re: G++ problems
« Reply #3 on: November 26, 2003, 12:27:27 PM »
I've used g++ under amigaos, whitout problem, try this:

#include

using namespace std;

int main(){

cout << " hello" << endl;

return 0;
}

Then save whit the name: hello.cc

Open a shell and write:

g++ hello.cc -o hello

then run hello

This must work  :-D
Ratto

\\"Nulla è finito di ciò che è fatto\\"
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: G++ problems
« Reply #4 on: November 26, 2003, 12:38:40 PM »
Quote

#include

int main ()
{
std::cout << "Hello C++!\n";
return 0;
}




#include

Using namespace std;

int main ()
              {
           cout << "Hello C++!" << endl;
      return 0;
}


Offline bytecode

  • Newbie
  • *
  • Join Date: Nov 2003
  • Posts: 3
    • Show only replies by bytecode
Re: G++ problems
« Reply #5 on: November 26, 2003, 03:28:27 PM »
Just so that you know, standard C++ headers don't have any .h extension. Those are deprecated, pre-standard headers. There is no guarantee that they'll behave the same way on different implementations, or that they'll be present at all.

So, include , , , etc, and not , , , etc.

The same holds true for C headers. There is no guarantee that a complete C89 environment will be present. So include , , etc, and not , , etc.

Everything inside the aforementioned headers should be in the std namespace. So you can use something like:

std::cout << "hello world!" << std::endl;

or

using namespace std;
cout << "hello world!" << endl;

or

using std::cout;
using std::endl;
cout << "hello world!" << endl;

or even:

namespace s = std;
s::cout << "hello world!" << s::endl;


Remember that even C functions should now be in the std namespace (it's sadly not always implemented that way), so if you want to use say, printf, use std::printf (or one of the options above).


Hope this helps.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: G++ problems
« Reply #6 on: November 26, 2003, 05:28:05 PM »
I think for the majority of beginners, "using namespace std;" is the least hassle. There really isnt much n the standard C library or the C++ STL where you'd ever get indentifier overlaps requiring the selection of a particular member of a given namespace...

That only really tnds to happen in large projects involving many people who always end up inventing the same names for stuff, or in various 3rd party libraries which offer replacement functionality for elements of the standard libraries.
int p; // A
 

Offline alxTopic starter

Re: G++ problems
« Reply #7 on: November 26, 2003, 05:32:00 PM »
@Ratto/bloodline

Thanks, but it still doesn't work :-(   When I run "hello", it cannot find it (Hello: Unknown Command).  I get the distinct impression it isn't actually compiling the code - surely:

Quote
#include
supercalifragilisticecpialidosios


Should give an error?  Could I have made a mistake installing the C++ parts?

@bytecode

In the C++ tutorial book I'm using, it mentions that about the .h, and it compiles fine under G++ in windoze.  But the Amiga version I have doesn't seem to have those versions, unless I'm looking at this the completely wrong way (it complains it cannot find them without the .h extension)

BTW Welcome to A.org :-D

Offline Kronos

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: G++ problems
« Reply #8 on: November 26, 2003, 06:09:31 PM »
Nothing to see here  :-D
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: G++ problems
« Reply #9 on: November 26, 2003, 06:21:54 PM »
@alx

#include is definately erronious :-)

C++ formatted IO streams are cack for console output anyway. Coming from me, Mr. "C++ owns all progrmming languages", thats quite a statement!

I mean theyr'e great for quick and dirty use, but in all honesty, I find the old C printf() a lot more useful, but as with all things C, you have no protection from misusing it...
int p; // A
 

Offline alxTopic starter

Re: G++ problems
« Reply #10 on: November 26, 2003, 06:30:36 PM »
Quote
#include is definately erronious


Whoops :-D

What I meant is that, as long as I get the #include bits right, i can write anything into the code and it won't complain - wierd... :-?

---edit---

BTW I remember hearing a while ago that geek gadgets was easier to setup than the individual files from Aminet, but the links on GG seem to be broken, I'd had problems with it before, and I can make GCC compile C progs ATM - just not C++ :-(

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: G++ problems
« Reply #11 on: November 26, 2003, 06:36:48 PM »
I just downloaded that big fat 85Mb GoldEd trial. It comes with gcc 2.95.3 and 3.3 (plus vbcc and other goodies).

I haven't installed it yet, but I hear it does most of the set up for you (the main reason I downloaded the bugger - 85Mb over 56k....)

I always find manual installation of gcc a total nightmare. Guess I am simply not a l33t haXX0r.

Still, on the bright side, I am not a l33t haXX0r, thus implying I have real friends, good lady and a life away from my unix box :lol:
int p; // A
 

Offline alxTopic starter

Re: G++ problems
« Reply #12 on: November 26, 2003, 06:40:24 PM »
@Karlos

That sounds worth it, if it comes with an IDE.  Will the trial let me compile without restrictions, or does it time out or something?

Offline Kronos

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: G++ problems
« Reply #13 on: November 26, 2003, 06:48:36 PM »
Probraly restricted to 1000 lines in the editor (per file), but fully working
on the compiler.
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: G++ problems
« Reply #14 on: November 26, 2003, 07:15:29 PM »
@alx

Yeah, Kronos is right - it has a restriction on the source file length, but the compilers are complete.

Personally I don't mind StormEd for source editing - I got pretty used to it so any restriction in GoldEd's editor doesnt really matter to me.
int p; // A