LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to fix this library problem because of newer GCC build (https://www.linuxquestions.org/questions/programming-9/how-to-fix-this-library-problem-because-of-newer-gcc-build-817958/)

knobby67 07-04-2010 08:57 AM

how to fix this library problem because of newer GCC build
 
Hi all,
I've just been been compiling some code on a new Debian install, however due to it having a newer build of GCC I get a lot of

invalid conversion from ‘const char*’ to ‘char*’

I've spent an hour converting all my code to run correctly. However I've found a library file I use is now causing a problem as this uses char * in it's prototype. The lib is Devil a texture loader.

In my code I had

void ParticleGiveBith(PARENT_PARTICLE *parent, char *texture ....

and this calls the Devil function with

parent->texture_id=ilutGLLoadImage(texture);

However I had to change my fuction to use const char so it says

void ParticleGiveBith(PARENT_PARTICLE *parent,const char *texture...

This now gives
error: invalid conversion from ‘const char*’ to ‘char*’
error: initializing argument 1 of ‘GLuint ilutGLLoadImage(char*)’

as the devil function uses char*, is there anyway to fix this? I can't change Devil as I apt-get it, I could search for source and compile but this may cause even more problems messing around with a lib function, can anyone advise a way round this? Thanks :)

knudfl 07-04-2010 09:09 AM

If you can't fix the code, then more compilers can be installed.

apt-get install g++-4.3 ( etc. etc.)
Or get a Debian Lenny gcc / g++ : more choice than Squeeze.

Using, examples : g++-4.1 <code>
make CC=gcc-4.1 CXX=g++-4.1

You can have all the "deb compat compilers"
installed at the same time.
They are built not to conflict with each other.
..

zirias 07-04-2010 10:10 AM

Quote:

Originally Posted by knobby67 (Post 4023487)
parent->texture_id=ilutGLLoadImage(texture);

If you are REALLY REALLY sure that this function does NOT change its parameter, use the following in C++:
Code:

parent->texture_id=ilutGLLoadImage(const_cast<char *>(texture));
or in ISO C:
Code:

parent->texture_id=ilutGLLoadImage((char *)texture);
(and for completeness: if you are NOT sure, allocate a buffer with malloc(), copy the string texture with strcpy(), call the function on the (non-const) copy, and free() it afterwards)

knobby67 07-04-2010 03:32 PM

Thanks both, I had already considered using a different GCC, but was leaving that to a last shot. I did try (char *) but it caused errors. Then when I read your post Zirias I realized I was using g++ :s. I don't programme in C++ but use the g++ compiler (for various reasons) and had totally forgotten! Thanks both


All times are GMT -5. The time now is 12:50 PM.