Code Help Needed


BenScar

What does this do again?
Joined
Jan 4, 2006
Messages
435
Age
47
Location
UK, Near London, somewhere...
Website
Visit site
Hello all,

After much help from MadDog and Slygamer, I've managed to get my Visual Studio set up to complie for the GP2x. Going though the "Lazy Foo' Productions" SDL tutorial and I've hit a problem on the first example! I feel like a total newbie (which isn't to far off...)

With this piece of code I get some errors on complie:
Code:
#include "SDL/SDL.h"
#include <string>

SDL_Surface *load_image( std::string filename ) 
{
That's not all of it, it's just the parts causing me the (current) errors.

To start with it's telling me
Error 1 error: string: No such file or directory
The error log tells me this is the "<string>" one that it can't find. If I change this to <string.h> it'll find the include file, sadly this doesn't rid me of any other of the errors. I thought this was happening as it's not the "usual" complier doing the work but the ARM one. So I copied the includes to a specific place and named it as one of the "Additional Include Paths". This had no effect.

I believe this is causing the next two errors:
Error 2 error: syntax error before ':' token
Error 3 error: 'filename' undeclared (first use in this function)
The "std::string filename" part won't work anyway I try it, remove the "std::" and it gives me simply "syntax error before 'filename'"
As the "filename" variable isn't being worked out properly I assume this then gives the next error about the variable being "undeclared", which seems fair.

So, can anyone point out what I'm doing wrong? I've played with it, teased it, mis-spelt things on purprose to try and trick the complier/linker all to no avail. Been though my "Dummies Guide to C++" and can't see why it's not finding the <sting> include file...

Starting to think someone out there doesn't want me making a noughts and crosses program for my 2x!
 
Sounds like it doesn't understand your C++ code, so...

Ensure the filename is of the format <filename>.cpp

Or try and use g++ instead of gcc to compile it.
 
Hello all,

After much help from MadDog and Slygamer, I've managed to get my Visual Studio set up to complie for the GP2x. Going though the "Lazy Foo' Productions" SDL tutorial and I've hit a problem on the first example! I feel like a total newbie (which isn't to far off...)

With this piece of code I get some errors on complie:
Code:
#include "SDL/SDL.h"
#include <string>

SDL_Surface *load_image( std::string filename ) 
{
That's not all of it, it's just the parts causing me the (current) errors.

To start with it's telling me
Error 1 error: string: No such file or directory
The error log tells me this is the "<string>" one that it can't find. If I change this to <string.h> it'll find the include file, sadly this doesn't rid me of any other of the errors. I thought this was happening as it's not the "usual" complier doing the work but the ARM one. So I copied the includes to a specific place and named it as one of the "Additional Include Paths". This had no effect.


Maybe a wierdness with the windows compiler? Have you tried
Code:
#include "SDL/SDL.h"
#include <string>

using namespace std;   // Explicitly specify namespace

SDL_Surface *load_image( std::string filename ) 
{

Just a stab. I'm better at C than C++ (and far better at perl and PHP than C) But it might help.

If that's not it, I dunno. Unless you're using VC++ 6.0. ;)
 
Last edited by a moderator:
How strange, are you trying to compile for Windows or for the GP2X? It looks like you mau not have the C++ Standard Library.

To check/verify, try
#include <vector>
#include <iostream>

If you get the same error (file not found) then by the looks of things you are missing the STL and/or the Standard Library.

You may need to download another 'pack' from Microsoft if you are usng the Express Edition.
 
Sounds like it doesn't understand your C++ code, so...
Ensure the filename is of the format <filename>.cpp
Thank you, that seems to have worked some magic. It now sees the <string> thing, although it's a little confused about this line "loadedImage = SDL_LoadBMP( filename.c_str() );"

It's now giving this slew of messages, looks like it might be something to do with that <string> include file although it's not complaining about it at all...
Code:
main.cpp
Linking GP2xTesting.gpe...
Debug\main.o: In function `load_image(std::string)':
main.cpp:(.text+0x28): undefined reference to `std::string::c_str() const'
Debug\main.o: In function `main':
main.cpp:(.text+0x1f0): undefined reference to `std::allocator<char>::allocator()'
main.cpp:(.text+0x210): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.cpp:(.text+0x240): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x260): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x278): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x284): undefined reference to `std::allocator<char>::allocator()'
main.cpp:(.text+0x2a4): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.cpp:(.text+0x2bc): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x304): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x35c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x374): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x3dc): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x470): undefined reference to `__gxx_personality_sj0'

I feel like I'm missing something else very simple (filename was bad enough :) )

PS this is being complied for the 2x, not Windows.
 
Last edited by a moderator:
add stdc++ to your library list.

/me bows down before the God like Squidge.

Yay..... It complied, no errors. Copied it to the 2x and it only went and worked.
Thank you so much, at last I have an env that allows me to do SOMETHING :)

SDL here I come, cross compling and lots more things to play with now...

Thanks everyone that's helped out.
 
Last edited by a moderator:
I am NOT starting another thread as this is pretty much the same issue (me being a C++ newbie!)

Got to the next step of the Lazy Foo' tutorial, started to use the "IMG_Load" function, so added the "SDL_image" to the "additional dependancies" (as stated).
Now I'm getting another spew of error messages when linking!

Code:
Linking GP2xTesting.gpe...
C:\devkitGP2X\lib\libsdl_image.a(IMG.o): In function `IMG_Load':
IMG.c:(.text+0x5c): undefined reference to `SDL_RWFromFile'
C:\devkitGP2X\lib\libsdl_image.a(IMG_bmp.o): In function `LoadBMP_RW':
IMG_bmp.c:(.text+0x650): undefined reference to `SDL_ReadLE32'
IMG_bmp.c:(.text+0x660): undefined reference to `SDL_ReadLE16'
IMG_bmp.c:(.text+0x670): undefined reference to `SDL_ReadLE16'
IMG_bmp.c:(.text+0x680): undefined reference to `SDL_ReadLE32'
IMG_bmp.c:(.text+0x690): undefined reference to `SDL_ReadLE32'
IMG_bmp.c:(.text+0x6ac): undefined reference to `SDL_ReadLE16'
IMG_bmp.c:(.text+0x6bc): undefined reference to `SDL_ReadLE16'
IMG_bmp.c:(.text+0x6cc): undefined reference to `SDL_ReadLE16'
IMG_bmp.c:(.text+0x6dc): undefined reference to `SDL_ReadLE16'
IMG_bmp.c:(.text+0x720): undefined reference to `SDL_ReadLE32'

There is more but I have the feeling they're all linked to one core issues (aside from me being clueless).
Added in the include for "SDL/SDL_image.h" and even looked up the "SDL_RWFromFile'" that it says is undefined but I can't understand why it's not finding the function.
From what I understand there is a relationship to the order of the libraries on the command line, with that in mind I've moved them about and tried different things but so far this order gives me the least ammount of errors:
SDL;SDLmain;SDL_image;pthread;stdc++
Which gives this command line:
arm-linux-gcc.exe Debug\*.o -o "d:\profiles\ScarboroB\My Documents\Visual Studio 2005\Projects\GP2xTesting\Debug\GP2xTesting.gpe" -L"C:\devkitGP2X\lib" -lSDL -lSDLmain -lSDL_image -lpthread -lstdc++ -static 2>&1 | sed -e s/(.[a-zA-Z]\+):([0-9]\+):/\1(\2):/

The output path does work (even with all the spaces) as if I move back to using "SDL_LoadBMP" instead of "IMG_Load" it complies and runs fine.

What simple include/library am I missing this time?
(and where's the nearest wall to beat my head against.... Not giving up, I will get the hang of this! :) )
 
Last edited by a moderator:
If you're doing lesson 3, try this:

arm-linux-gcc -Ic:\devkitGP2X\include lesson03.cpp -Lc:\devkitGP2X\lib -lstdc++ -lSDL_image -lSDL -lpng -lz -ljpeg -lpthread -lm -static

It built for me using the libs in that order.
 
Thank you luteijn, got what I needed from that thread.
Started off with:
stdc++;SDL_mixer;SDL_ttf;SDL_image;mikmod;vorbisidec;freetype;jpeg;png12;z;m;SDL;pthread

Which is pretty much everything, then started to take things out until the errors came back. Managed to get rid of the following before I got any errors:
;SDL_mixer;SDL_ttf
;mikmod;vorbisidec;freetype

Just in case anyone else needs to know :)

Thanks again.
Ben
---
 
Thank you luteijn, got what I needed from that thread.
Started off with:
-lstdc++ -lSDL_mixer -lSDL_ttf -lSDL_image -lmikmod -lvorbisidec -lfreetype -ljpeg -lpng12 -lz -lm -lSDL -lpthread

Which is pretty much everything, then started to take things out until the errors came back.
Managed to get rid of the following before I got any errors:
SDL_mixer
SDL_ttf
mikmod
vorbisidec
freetype

Just in case anyone else needs to know :)

Thanks again.
Ben
---
 
Back
Top