Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Rodney on April 01, 2003, 01:25:10 PM
-
I've recently installed GCC and all seemed to be working fine until now.
I get very strange, unreadable (to me) error messages when i try to create a vector.
I am kinda still learning this vector stuff, and in doing so i m creating this little program to aswere one of my questions about vectors. But now i have a more important question. What do these errors mean?
Here is the code:
#include
#include
using namespace std;
int main ()
{
vector v;
/* int a = 3;
int b = 2;
v.push_back(a);
v.push_back(b);
v[0] = 10;
v[1] = 10;
printf ("%d %d",a ,b);
*/
}
As you can see, i've commented out most of the code so that im pretty sure the top line of function main() is causing the problemos.
Incase you cant tell from the program, im trying to find out if when adding an element to a vector, does the vector simply copy the element past into push_back() and put it in the vector, or does it obtain the objects address and add the reference in the vector?
However, thats not really the guestion i want answered anymore (although if you know it, that'd be good) The main question is, am i doing something wrong with this code, or is this a problem of my gcc? And has this been reported before? if so, is there a fix etc?
Heres the errors the above code is producing!
Projects:test> gcc -o vex vex.cpp
/t/cc8816321.o: Undefined symbol ___nw__FUlPv referenced from text segment
/t/cc8816321.o: Undefined symbol endl(ostream &) referenced from text segment
/t/cc8816321.o: Undefined symbol _cerr referenced from text segment
/t/cc8816321.o: Undefined symbol ___ls__7ostreamPCc referenced from text segment
/t/cc8816321.o: Undefined symbol ___ls__7ostreamPFR7ostream_R7ostream referenced from text segment
-
Youre getting a lot of C++ iostream references. The STL uses IO streams for IO in preference to the C IO style methods. My guess is that you're getting problems caused by unreferenced calls to IO stream code.
Try adding
#include
Also, you commented out everything that uses your vector - it may get optimised away...
Hope this helps.
-
Rodney wrote:
Incase you cant tell from the program, im trying to find out if when adding an element to a vector, does the vector simply copy the element past into push_back() and put it in the vector, or does it obtain the objects address and add the reference in the vector?
Well, that depends on what you create a vector of. A template uses whatever T is given to it, be it a class, integer, float, int* you name it.
Internally, most vector implementations use something like a conventional array (the kind you get with operator new[]).
Getting back to our template stuff, a vector is a vector of ints.
Similarly,
class Dummy {
  int a, b, c;
  float x, y, z;
...
}
vector is a vector of Dummy objects.
Assignment etc. would be done via a user-defined copy constructor if defined, or the default copy constructor if it isnt. For ints and other elemental types, copying is of the straightforward a = b; assignment type.
Beware of default copy construction in classes that have dynamically allocated data inside! You really need to take charge on how these things are copied yourself by providing a copy constructor.
Also, if you make the your copy constructor for your Dummy class private or protected you probably wouldn't be able to make a vector of it.
Moving on, if you want a vector of references, you need to do it something like this
vector
Or alternatively create a class which is a wrapper for a Dummy* and use a vector of that.
Anyhoo, hope this answers a your question a bit.
-
Good suggestion with the however it didnt work. Infact, it cant even find the file. So i tried and well, got the errors.
After some buggering around i tried copying iostream.h in gnu/lib/g++include/ to iostream and then included got the same errors again.
I tried
#define iostream iostream.h
#include
So that hopfuly the #define would filter down into the vector include files, however, got an error at the '.' in the #define, but thats not a problem... Cause it was just a stab in the dark.
I've got version 2.7.0 of gcc i believe. Is this good enough by peoples experiance?
-
Hmm,
Well the whole headername / headername.h thing is fairly recent in C++. According to the current standards, the .h part of the name is redundant (the compiler knows you're talking about a header). However, the .h should still work fine. Personally when I write my headers I stick to .hpp ;-)
As for your woes, I guess there may be a problem at the linker stage. After I posted the iostream thing I realised that it wouldn't really matter - the STL components that use IO stream would include it themselves. Since your main file isn't using any iostream stuff, things should be ok even though you didn't include it there.
My guess is that somehow your installation is broken - some .lib files may be missing or the compiler is somehow looking in the wron place for them.
Unfortunatley, I recently had to flatten my developer partition :-( so I need to go the the whole install/build hassle again...
-
Well thanx for you help anyway. Ill have another look at it tomorrow, and possibly reinstall or upgrade (if thats possible, this was the only installation of gcc i could find on aminet).
For now, im off to bed!
-
in my opinion you should install a newer version of GCC you are not even using egcs which means it's oooolllddd.
second thing (this aplies to anyone doing C++ with GCC) is to install stlport instead standard gnu stl implementation, stlport can be found at http://www.stlport.org
-
trgse wrote:
in my opinion you should install a newer version of GCC you are not even using egcs which means it's oooolllddd.
Yer, this makes sence. A search on aminet returned some Warp UP stuff but nothing that would suggest it is a native C++ compiler for 68k AmigaOS.
it also returned egcs-src.lha . Which im guessing is the source of the compiler. Do you know where i can get the binaries from?
second thing (this aplies to anyone doing C++ with GCC) is to install stlport instead standard gnu stl implementation, stlport can be found at http://www.stlport.org
Whats the advantages of STLport and why would you recommended over the standard gnu implementation?
-
I haven't used g++ for quite a while now, but IIRC something you needed to do was, if you're using gcc to do the linking for you (eg gcc -omybin myobj1.o myobj2.o myobj3.o) is that you have to use the g++ command to do this, as gcc is the C compiler and g++, being the C++ compiler, does a bit more. If you're using ld to link the final binary, you'd have to add "-lstdc++" or "-lstdcxx" to your command line (that's part of that extra stuff g++ does). That library has all the stream code in it.
So, according to your example, you should be doing this:
Projects:test> g++ -o vex vex.cpp
(if g++ is not recognized as a command, try gxx)
-
trgse wrote:
in my opinion you should install a newer version of GCC you are not even using egcs which means it's oooolllddd.
Yup :) good point. Problem. There seems to be now egcs on aminet except for some Warp Up stuff. There was a page which some guy had m68k hosted and targeted binaries there, and all the warpup stuff too, but non of the links work.
And then the ftp site of back2roots had 2 version of 68020 binaries for egcs... i think one was alpha 1.0.3 and the other one looked like a stable 1.1.2...
Is this the stuff i want? Or is there a more up to date version? (http://ftp.back2roots.org/geekgadgets/amiga/m68k/alpha/egcs/)
second thing (this aplies to anyone doing C++ with GCC) is to install stlport instead standard gnu stl implementation, stlport can be found at http://www.stlport.org
And this sounds a little weird. If i develop useing these libraries, will i still be able to port my stuff to other platforms and use the gnu STL's?
What advantages does this give me? I think at their site i saw something about optomisations. Do you have any other reasons for why their good to use?
Do i need to get an Amiga specific version of it?
-
CodeSmith wrote:
I haven't used g++ for quite a while now, but IIRC something you needed to do was, if you're using gcc to do the linking for you (eg gcc -omybin myobj1.o myobj2.o myobj3.o) is that you have to use the g++ command to do this, as gcc is the C compiler and g++, being the C++ compiler, does a bit more. If you're using ld to link the final binary, you'd have to add "-lstdc++" or "-lstdcxx" to your command line (that's part of that extra stuff g++ does). That library has all the stream code in it.
So, according to your example, you should be doing this:
Projects:test> g++ -o vex vex.cpp
(if g++ is not recognized as a command, try gxx)
i dont know, but maybe what your talking about is Amiga specific. But on Unix, gcc does everything. infact, gcc is just a unified interface for g++ and the linker etc... gcc calls c++ if the code is in C++
eg, i was writing c++ in a file with the extension .c. gcc had errors... i changed the named to cpp and then it worked :). Gcc also supports the file extension .c++ for C++ code.
Anyway, thats what i thought! :)
-
Rodney wrote:
i dont know, but maybe what your talking about is Amiga specific. But on Unix, gcc does everything. infact, gcc is just a unified interface for g++ and the linker etc... gcc calls c++ if the code is in C++
eg, i was writing c++ in a file with the extension .c. gcc had errors... i changed the named to cpp and then it worked :). Gcc also supports the file extension .c++ for C++ code.
Anyway, thats what i thought! :)
Gcc will guess the language from the file extension, so you would have had errors with a cpp file called #?.c
I'm pretty sure the g++ thing is not an Amiga-only thing, because I first found out about it when I was doing some MS-DOS coding :-D
If you don't have g++ on your platform, just add the "-lstdc++" switch to the last time you run gcc, or to the time you call ld, in your makefile.
-
The code compiles for me. The output is 3 2. So the values stored in the vector are not stored by reference. As for your compilation errors... try installing a new version.
-
@Rodney
ftp://ftp.geekgadgets.org/pub/geekgadgets/amiga/m68k/alpha/gcc/
2.95.3
...there seems to be braind new 3.2.2 there too, but you'd better stick with 2.95.3 for now...
-
nyteschayde wrote:
The code compiles for me. The output is 3 2. So the values stored in the vector are not stored by reference. As for your compilation errors... try installing a new version.
Thanx heaps :) but thats not what i wanted to hear :) That is, i was hopeing that'd be passed by reference. Not to worry.
-
Piru wrote:
@Rodney
ftp://ftp.geekgadgets.org/pub/geekgadgets/amiga/m68k/alpha/gcc/
2.95.3
Thank you very much, just what i wanted :)
...there seems to be braind new 3.2.2 there too, but you'd better stick with 2.95.3 for now...
Think i'll go the 3.2.2 :) the newer the better :). Unless 3.2.2 is in alpha or beta then i might go the 2.95.3 :}
-
@Anybody
What's the current gcc WarpOS build ?
Cheers
-
Think i'll go the 3.2.2 :) the newer the better :). Unless 3.2.2 is in alpha or beta then i might go the 2.95.3 :}
Don't. It is definetely very much alpha. Don't use it. Stick with 2.95.3, this saves you a LOT of headaches.
-
Piru wrote:
Don't. It is definetely very much alpha. Don't use it. Stick with 2.95.3, this saves you a LOT of headaches.
Hey i almost forgot, i was told to upgrade to egcs, which to me makes sence, because egcs is now the official gnu compiler i believe.
That is, i thought egcs, was gcc ... infact i forget when gcc developement stoped and egcs started. somewhere in the 2.x's.
Ummmm so i guess im confused over the two different directories now :) theres the
alpha/gcc and
alpha/egcs
So, which one is better? I would have though egcs was uptodate, but ithough gcc 3 was egcs :}
-
Hey i almost forgot, i was told to upgrade to egcs, which to me makes sence, because egcs is now the official gnu compiler i believe.
Wrong. EGCS (as package) is dead. It merged back to gcc. There is just gcc. Use gcc.
The history of egcs is that some developers decided to take their own way with the direction of the development and branched egcs out of gcc. Later on the disagreement was solved and egcs and gcc merged back together [or rather FSF halted the original gcc 2.x and appointed egcs team to be resposnsible for it... iirc].
Found this link about it (http://gcc.gnu.org/faq.html#gcc).
EGCS as itself is dead. Don't use it. It's ancient. It's just GCC now.
That is, i thought egcs, was gcc ... infact i forget when gcc developement stoped and egcs started. somewhere in the 2.x's.
Wrong. egcs stopped, gcc goes on. Though egcs-team is now responsible for gcc. I think this is the root of your confusion...
Ummmm so i guess im confused over the two different directories now :) theres the
alpha/gcc and
alpha/egcs
Yes, you're definetely confused.
So, which one is better? I would have though egcs was uptodate, but ithough gcc 3 was egcs :)
gcc gcc gcc gcc.
Forget egcs altogether.
Whoever told you to use it need to be educated about this issue aswell.
-
in my opinion you should install a newer version of GCC you are not even using egcs which means it's oooolllddd.
I think what he was saying is that the version of gcc i had, hadnt even split to egcs yet.
But where i got my information for egcs was i think the BSD sources. I was trying to find the latest compiler for OpenBSD and i could only find egcs. In the read me it said something like, gcc dev stoped, and egcs took over and because the official compiler for either, bsd or gnu... not sure...