GCC errors - please help!

Started by
11 comments, last by Fruny 18 years, 7 months ago
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!
Advertisement
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.
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.
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?
Although this isn't related to your errors, for your program to be legal you need to include <string> if you use std::string.
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).
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?"
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!!
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.
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

This topic is closed to new replies.

Advertisement