Skip to main content
gamedev.net
🔒 Locked

GCC errors - please help!

Started by Crypter 11 replies 2.2k views
Original Post
Crypter
Crypter
Hey everyone, I just downloaded a GBA emulater and compiler. The compiler includes the GCC compiler. I never used this compiler before. I ran this simple program..

#include <iostream>

class CLogStream;

class cLogStream //: std::ostream
{
	std::string m_strData;    //errors??

public:
    cLogStream () {}
	~cLogStream () {}
};

int main()
{
return 0;
}

This code is from my original logging system, which works great in MSVC++. Anyways, GCC is giving me errors..

gcc -o zengine.elf main.cpp -lm
ccdgJ7pr.o: In function `__static_initialization_and_destruction_0(int, int)':
ccdgJ7pr.o(.text+0x54): undefined reference to `std::ios_base::Init::Init()'
ccdgJ7pr.o(.text+0x7c): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status
What could be the cause for this? My code works with MSVC++ 6. (Okay..The pluses aren showing..Its _cplusplus.) Thanks!
Peregrin
Peregrin
Try using g++ instead of gcc:
g++ -o zengine.elf main.cpp -lm

EDIT: Note that g++ is the same GNU compiler as gcc, but gcc does not use the C++ libraries by default while g++ does.

[Edited by - Peregrin on September 11, 2005 10:27:56 PM]
Jooleem. Get addicted.
kdogg
kdogg
What Peregrin said. It says in the man pages that gcc will know to use the c++ compiler if the file extension is a c++ type (.cxx .cc .cpp etc.), but in practice i've found that not to be the case.
MaulingMonkey
MaulingMonkey
Quote:
Original post by kdogg
What Peregrin said. It says in the man pages that gcc will know to use the c++ compiler if the file extension is a c++ type (.cxx .cc .cpp etc.), but in practice i've found that not to be the case.


The errors displayed are linker errors. Considering it's not whining about "class" being undefined, I'd say it's compiling the C++ code just fine (and hence using the correct compiler for that). It's just not linking all the necessary libraries.

Depending on your system layout, you may be able to simply add -lstdc++ to GCC's options - but why not just use the g++ commandline?
me22
me22
Although this isn't related to your errors, for your program to be legal you need to include <string> if you use std::string.
d000hg
d000hg
Yuck, command lines. I'd avoid them if possible. I used to use GCC for 32bit DOS programming a few years back - it IS a good compiler, if a little peculiar compared to VS (which may be VS's fault).
Crypter
Crypter
Thanks for replying!

I tried using g++, but I get the same exact errors.

@me22:
D'uh! I forgot about that! Anyways, after adding
#include <string> and running g , I get one error..
g++ -o zengine.elf ..\zengine\main.cpp -lm../lib/gcc-lib/arm-agb-elf/3.0.2/../../../../arm-agb-elf/lib/libstdc  .a(pure.o): In function`__cxa_pure_virtual':../../../../gcc-3.0.2/libstdc  -v3/libsupc  /pure.cc:49:undefined reference to`write'collect2: ld returned 1 exit status

What could cause this? Please help!

btw, Why doesnt my pluses appear in the "Show Preview?"
Crypter
Crypter
Okay, Im stuck. It is definitaly a linker prob..
but I have no idea whats causing the stupid error.

Ill post everything I can, and hope someone here
can help.

Code:
#include <iostream>int main(){return 0;}

The makefile that I use (make.bat):
PATH=c:\devkitadv\bin;%PATH%g++ -o zengine.elf main.cpp -lmobjcopy -O binary zengine.elf zengine.binpause

The error..
C:\DevKitAdv>g++ -o zengine.elf main.cpp -lm/cygdrive/c/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../../arm-agb-elf/lib/libstdc++.a(pure.o):  In function `__cxa_pure_virtual':    ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/pure.cc:49:       undefined reference to `write'collect2: ld returned 1 exit status

Ive never used this compiler before..Please help!!
ender7771
ender7771
Dont quote me on this, but I dont think that gcc for the gba has a <iostream>.

You cant use it ecause it doesnt exist.

And by the way, have you tried using HAM? Its my favorite IDE and it works awesome.
Fruny
Fruny
Your code compiles and links without a hitch with my copy of GCC. Where did you get yours?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
MaulingMonkey
MaulingMonkey
Quote:
Original post by Crypter
@ender7771: iostream is part of the C++ standard, so
almost all compilers should support it.


Yes, but for certain targets (where storage of the library would be hard/impossible - e.g. embedded platforms - e.g. possibly the GBA) certain parts of the SC++L (including iostreams? not sure...) can be excluded while still being considered complaint with the C++ spec.

It sucks, but it's possible... even assuming a perfect world where everyone implements the latest version of the C++ spec to the line :-). (I think, anyways, iostreams might be on the required list... I don't have a copy of the standard handy)
Fruny
Fruny
In a freestanding environment, a conforming C++ compiler implementation is only required to provide <cstddef>, <limits>, <cstdlib>, <new>, <typeinfo>, <exception>, <cstdarg>.

<cstdlib> needs to at least contain abort(), atexit() and exit().
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.