LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-22-2004, 10:52 PM   #1
jon_k
Member
 
Registered: Jul 2003
Location: Fort Worth, Texas
Distribution: Mepis Linux 2004
Posts: 547

Rep: Reputation: 30
Upgrading GCC properly.


Hello, I was wondering if it'd be advisable to upgrade GCC?

A developer and close friend of mine is having trouble with the pow() function in C programming, he suggested possibly if I upgrade gcc it will fix this.

I figured it couldn't hurt upgrading a systems package such as GCC, if anything it could only help so I've decided to look in to doing it.

However, I'm worried since your C compiler is such an important tool in linux, what the correct way to upgrade GCC on redhat 9 would be?

Is there a tutorial or step-by-step documentation anywhere on the internet documenting the steps someone has taken to upgrade gcc?

I don't want to walk in on this in the dark and fubar my system.

I've also heard that after installing gcc, when compiling it still won't compile with the new gcc, you have to change something to get it to start compiling with the new version of gcc rather than the old.

Regards =)

Last edited by jon_k; 08-23-2004 at 12:01 AM.
 
Old 08-22-2004, 11:35 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
i'm really no expert on this !
generally it is not advisable to upgrade gcc (certainly not by itself)
gcc is often NOT reverse compatable with binaries compiled with earlier versions of gcc
if you do you must i think also upgrade glibc to one compiled with the new
gcc

however if you have a descent package manager installed on there like apt-get
you should be able to do it and nearly the entire core system will be upgraded

should be a way to use rpm's simply by getting all the packages that claim dependancy and doing it all at once but without a tested outcome like apt-get could controll you might have minor troubles with some other apps that need rebuilding.

i don't know that much about redhat accept my initial impression of rpm was it was of questionable value.
i think i would redo everything to a more modern system

though i can't imagine this would change the behaviour of something so simple as pow() math function...
if someone is giving you binaries compiled with a more modern compiler just ask for the source code and
compile it yourself to match your system.

as for the system using another gcc -- default compiler is installed with the ./configure
switch --prefix=/usr
alternate gcc's go in /usr/local by default is generally the way people do it
or some other place like /opt
if you want the system to use a non system compiler temporarily alter the PATH variable

it is of course ok to install from source all kinds of versions of gcc as long as you don't overwrite your system one just do ./configure --prefix=/opt/gcc3.x.x or whatever and keep them seperate
then your freind can try it without it breaking your system

Last edited by foo_bar_foo; 08-22-2004 at 11:39 PM.
 
Old 08-22-2004, 11:58 PM   #3
jon_k
Member
 
Registered: Jul 2003
Location: Fort Worth, Texas
Distribution: Mepis Linux 2004
Posts: 547

Original Poster
Rep: Reputation: 30
Okay, we've coded a simple C program like this using the pow() function to elaborate our problem here:
Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char *argv[])
{
    printf("TEST: %d\n", pow(2, 3));      
    return 0;
}
Seems like the program should work, right?

When we try to compile it, we get
In function `main':
/home/shared/dev/plugin-sdk/test.c:7: undefined reference to `pow'
collect2: ld returned 1 exit status



Now, if we take POW out of our program like this
Code:
int main(int argc, char *argv[])
{
    printf("TEST: %d\n", 0); //pow(2, 3));
    return 0;
}
Compile this above code, and run it we get TEST: 0
In other words, the program works and executes correctly if we take out all traces of the pow() function.


This would suggest that our copy GCC doesn't have support for the function pow();. After all, it does say undefined reference, meaning, "Hey! I dont know what this function is!"

This would indicate that gcc was put on our server without pow() support. In order to get pow() functions going, it appears the only way is going to be to install the newest version of gcc.

We need to have power functions unless we plan to code the functions ourself.

So, I'm getting at is:
1) Will re-installing GCC be too much of a dangerous task to do on the server to try and upgrade?
2) If so, how should we go about getting pow() to work?
3) Am I correct about it being GCC's fault for not compiling the pow function or are we actually using or declaring pow wrong?

Is this going above everyones head or is anyone still with me here? ;-)

If I can't get any responses here I figure I'll give it a try over at the Programmers section of LQ too.

UPDATE:
Problem solved!
We were doing the following which is WRONG:
printf("TEST: %d\n", pow(2, 3));

The correct way would be to use:
printf("TEST: %lf\n", pow(2, 3));

Another thing is you have to pass the -lm option to gcc to make it do the math functions. E.G. gcc -g -O2 -lm test.c -o test


Thanks for the help everyone, I hope when this gets to the 'time based archive' it can help someone else too. ;- )

Last edited by jon_k; 08-23-2004 at 12:35 AM.
 
  


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
Upgrading gcc-3.4.3 from gcc-3.3.5 on Debian v3.1 MKSrivastava Debian 2 11-21-2005 10:09 PM
Upgrading GCC from 2.96 jared78 Linux - Software 6 05-11-2005 06:00 PM
gcc installed but not working properly cylaxzene Linux - General 4 01-30-2005 12:30 PM
upgrading gcc abs Slackware 3 08-25-2004 08:57 PM
Themes not working properly after upgrading to Gnome 2.6 crdiscoverer Linux - Software 1 04-17-2004 05:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:31 AM.

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