Re: Can't install gcc 3.2 alongside gcc 2.96 on Red Hat 7.3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



lrtaylor@xxxxxxxxxx wrote:

Hi Jonathan,

If you meant this to go to the list, too, it didn't.  Just so you
knew...

Oops, sent now. I knew I was going to do that sooner or later, thanks for pointing that out. Why doesn't the list add a replyto header of gcc-help@xxxxxxxxxxx to the emails it processes?


The -R and -rpath options are not configure options for the compiler.
Rather, they are options for gcc and g++ or for ld (the linker) and are
used when linking a program. -R is supported by GCC on some platforms.
-rpath is supported in Linux, but you have to pass it in in a funny way.
Basically, they both tell the linker to add the given path to the
binary's runtime search path. That path will be searched when the
binary is loaded into memory to find any dependencies that it has (that
is, any shared libraries that it needs).


For example, if your C++ library is in the directory /home/jwatt/lib,
you would use them like this:

-R/home/jwatt/lib

or

-Wl,-rpath,/home/jwatt/lib

Just use one or the other - whichever one works. For example:

g++ -o prog -Wl,-rpath,/home/jwatt/lib prog.cpp

I did eventually find -rpath was an ld option, but I was attempting to use the linker directly after creating an object file. I spent ages trying but for some reason I haven't been able to get that to work. I kept being told that it was failing because my lib directory was a directory. Wierd! Anyway, with your above help I have found that I can compile my small test using


g++ -Wl,-R,/home/jwatt/gcc/lib test.cpp

or

g++ -Wl,-rpath,/home/jwatt/gcc/lib test.cpp

However, -R/home/jwatt/gcc/lib will not work for some reason.

The problem you are seeing compiling your test program is that C++
programs need to be linked using g++ rather than gcc.  gcc is smart
enough to know how to compile C++ source files, but linking C++ programs
requires different options than C programs.  gcc doesn't know about
those, but g++ does.

So, try "g++ test.cpp" instead.

Sure enough that works. Thanks. :) I have always used SCons to compile my source and hadn't really taken on board that it uses g++ not gcc to compile.


Not sure about your other program, though.  I'm not sure that "limits"
is a valid header, though.  Seems to me it should either be "limits.h"
or "climits".  Not sure, though...

Cheers,
Lyle

<limits> is part of the C++ standard library, and it works in my little test program now that the -rpath thing is working. However, in my program proper (the compilation of which is controlled by SCons) it doesn't. My current theory is that for some reason my adjusted PATH variable isn't being exported to SCons properly, so SCons is compiling using gcc 2.96 and its libraries. I'm not sure how to confirm and rectify this yet, but that not a topic for this list so I won't go on. :)


Again, thank you very much. After weeks of trying to find a solution with RPMs and all the rest of it I think the end is finally in sight (until the next problem crops up of course :).

Regards,
Jonathan


-----Original Message-----
From: Jonathan Watt [mailto:jonathan.watt@xxxxxxxxxxxx] Sent: Friday, February 20, 2004 5:44 AM
To: lrtaylor
Subject: Re: Can't install gcc 3.2 alongside gcc 2.96 on Red Hat 7.3


lrtaylor@xxxxxxxxxx wrote:

Jonathan,

GCC supplies its own set of C++ header files along with its own C++
library, which is why the directory is different for those headers.

The


C++ library is fairly tightly coupled with GCC, so you probable

wouldn't


want to try to upgrade that.  An alternative would be to use STLport,
which you might be able to use with the old compiler, but that's

fraught


with difficulties as well, so I'm not sure I would recommend that

path,


except under certain circumstances.

The second comment below that you are concerned about should not

concern


you.  Basically, the C library and headers come with the system.  The
C++ library and headers come with the compiler.  Problems you are

having


compiling C++ code will have little to nothing to do with the C

library


headers and much more to do with the C++ headers and the compiler's
level of C++ compliance.

In short, if it compiles on another system with the version of GCC

that


you are trying to install, it will very likely compile with the one

you


are trying to install.

There are, however, a few caveats that you will need to be aware of.
C++ libraries compiled with the old GCC will not be compatible with
libraries or programs compiled with the new GCC.  This means that if
your programs rely on C++ libraries that are installed with the

system,


you will not be able to use the ones that are installed.  Rather, you
will have to build your own copy of them with the new compiler and

place


them in an appropriate location.  If you're just doing basic C++
programming (that is, not relying on other C++ libraries), you

shouldn't


have any problems.

(C libraries, however, are no problem. They should generally work

fine


regardless of which compiler you built them with.)

In addition, C++ program compiled with your new compiler will be
dependent on the C++ library and other GCC libraries that come with

the


new GCC.  You will need to do one of three things in order for your
programs to run:

1) Embed the path to the libraries into your libraries and programs

that


you build (look at the -R compiler option and -rpath linker option).
2) Place copies of the libraries in one of the directories that your
system looks in by default (or add the directory to your system's
default search path) - not recommended, by the way.
3) Set LD_LIBRARY_PATH to point to the location that GCC's libraries

are


installed in before running your programs.


I can't find the -R comiler and -rpath linker options. I searched the option summary page for gcc 3.2.3:

http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Option-Summary.html

I also searched the same page for gcc 3.3.2 just in case they were new. I did notice the -static-libgcc option though, but I don't think I can use it since I need to be able to handle exceptions thrown by the standard C++ (and another) library.


I would recommend either 1 or 3, and prefer 1.  And, if you plan on
installing the programs built with the new compiler onto the system,
you'll want to put a copy of the libraries that come with GCC into a
directory other than your home directory.

If you don't do one of those things, your program will compile fine,

but


probably won't run, because it will complain that it can't find
libstdc++.so.5 or something like that.

Basically, you can easily install and use another compiler than the
system default, but it will take a little bit of work - or at least
forethought - to get it to work well, depending on how you intend to

use


it and the programs or libraries that you build with it.

Make sense?

Cheers,
Lyle



Thanks for taking the time to write all the above, that has cleared up some of the mystery of how things work. :)

I installed gcc 3.2.3 into my home directory /home/jwatt and tried to build my program. Unfortunately certain things are causing problems. First of all including <ostream> and <limits> doesn't seem to work despite files by these names existing in /home/jwatt/gcc/include/c++/3.2.3 and gcc -v says that, that directory is the first directory searched. Another issue is that I am being told that std::left is not declared whereas compiling with gcc 3.2 on my other machine it was fine.

To test that gcc would be able to find its libraries I created a small C++ test file called test.cpp with the following content.

#include <iostream>

int main()
{
   char buf[255];
   std::cout << "enter a value: ";
   std::cin >> buf;  // I know, just build testing
   std::cout << "you entered: " << buf << std::endl;
   return 0;
}

using 'gcc test.cpp' causes errors at the linking stage, the first being

"undefined reference to 'std::cout'".

Has anyone any ideas as to what might be causing these problems?

Thanks again Lyle,

Jonathan



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux