LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2010, 08:57 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
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
 
Old 07-04-2010, 09:09 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,513

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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.
..
 
Old 07-04-2010, 10:10 AM   #3
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Quote:
Originally Posted by knobby67 View Post
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)

Last edited by zirias; 07-04-2010 at 10:14 AM.
 
Old 07-04-2010, 03:32 PM   #4
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Build gcc 4.3.2 problem zvivered Linux - Embedded & Single-board computer 1 01-07-2009 10:52 AM
library linking problem in gcc surya1006 Linux - Newbie 2 09-05-2008 03:43 PM
How do I fix this assignment problem C++ compiler error in GCC? Erik_the_Red Programming 4 07-12-2005 09:36 AM
Can't build from sources - gcc problem jaybee Linux - Software 1 06-19-2004 10:26 AM
How can I use gcc to build a static library? vtluu Red Hat 1 04-12-2004 10:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration