i just installed gcc 4.9 using the link here and it is a very good link. But I have only one problem which i dont want to try not to mess up --> linking the libraries and path variables.
we have a cluster in our college and i installed this in my home directory (without root). Now my home/ directory contains this folder where all the gcc folders are :
bin
include
lib
lib64
libexec
share
What all do i have to do to point to the g++/gcc binary in bin folder with additional linking ? For example, set ld_library_path, set binary paths (export PATH = /home/asdf/gcc4.9/bin:$PATH) . etc..
Can anyone provide details on what all needs to be done to use gcc/g++ 4.9 (installed by me) by bypassing the older version of gcc installed by root.
Do i have to add lib and lib64 to the ld_library_paths as well ? Will i have to use " " instead of < > to include files (e.g. # inlcude "set" or #include and it includes from gcc4.9 and not the old one ) Or explicitly provide the include path using -I
Any suggestions/discussions/comments are welcome. I am aware this may marked as duplicate, but it will really be useful to all the people out there who want to try the new gcc-4.9 with c++11 without messing up the environment variables.
PS: I am not asking how to export or set an environment variable. I am asking what all environment variables are required to use my non-root version of gcc and not the root's older version and not mess up the ld paths and so paths during runtime.
thanks !!
If you build your compiler with --prefix=/home/myname/gcc4.9 (adjust to match your system, obviously), then the compiler should "know" that the include paths etc.
All you need beyond that is to make sure your path has /home/myname/gcc4.9/bin before /usr/bin or wherever your other gcc is installed, and everything should work just like normal. On my machine, I have gcc 4.8.2 installed from my own build and gcc 4.6.3 from the linux installer for gcc (because it's a fairly old distro). And as long as I have the paths set in the right order, it works "automagically".
You will need to set LD_LIBRARY_PATH, but include-paths and static libraries should be handled by gcc itself.
Related
Hi recently I upgraded gcc to 9.1,but I installed in custom path. All the other dependency libraries i use is also installed in that path. I had set PATH and LIBRARY_PATH to this folder. Whatever previous versions i was using it is still there in system path. Now when I compile my program first it is searching include files in the system path then later my custom path. How can i make so first include search priority to be given to the custom path.
And also i am using eclipse on Ubuntu for development, it is not referring g++ to the new path. Still considering old path. How can i rectify this? Invoking g++, gcc, gdb points to the new path
Where multiple possible versions of a library exist, is there a way of ensuring cmake picks the "right" one?
For example: centOS7 comes with gcc 4.5.2, and includes /usr/lib64/libgfortran.so.1. I have compiled gcc 6.2.0 in /usr/local, and this includes /usr/local/gcc-6.2/libgfortran.so.3
However,
find_package(Gfortran REQUIRED)
Always finds the system gfortran. My "FindGfortran.cmake" file contains:
find_library(Gfortran_LIBRARY
NAMES gfortran
PATHS /usr/local/gcc-6.2/lib64
)
And I've set tried running cmake with:
LD_RUN_PATH='/usr/local/gcc-6.2/lib64' LDFLAGS='-L/usr/local/gcc-6.2/lib64' CXXFLAGS='-L/usr/local/gcc-6.2/lib64' cmake ..
But whatever I do, cmake picks up the /usr/lib64/libgfortran.so.1 version (and then my code fails because it links, correctly, against a different library which is in turn linked against libgfortran.so.3).
I have a "workaround" in that I can edit my CMakeLists.txt file to include the line:
set (Gfortran_LIBRARIES /usr/local/gcc-6.2/lib64/libgfortran.so.3)
But this is rather rubbish, and means that I need to maintain different CMakeLists.txt files on different machines (so I can't commit the file to SVN) which seems to defy the point of using cmake.
There must be something stupid I'm doing wrong - can anyone advise?
I think this is my problem with installing GCC. I keep getting
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of mpc.h... yes
checking for the correct version of the gmp/mpfr/mpc libraries... no
when I type
/Users/[username]/Documents/gcc-4.8.3/configure --with-gmp=/usr/local
--with-mpc=/usr/local --with-mpfr=/usr/local
with [username] being my actual username.
I installed GMP, MPC, and MPFR, but the files for the three are spread among different folders in /usr/local. All the header files are in /usr/local/include, but the library files are in /usr/local/lib.
You should be able to figure it out from this:
$ ~/src/gcc/gcc/configure --help | fgrep gmp
--with-gmp-dir=PATH this option has been REMOVED
--with-gmp=PATH specify prefix directory for the installed GMP
--with-gmp-include=PATH/include plus
--with-gmp-lib=PATH/lib
--with-gmp-include=PATH specify directory for installed GMP include files
--with-gmp-lib=PATH specify directory for the installed GMP library
Also, https://gcc.gnu.org/install/prerequisites.html says
Alternatively, if GMP is already installed but it is not in your library search path, you will have to configure with the --with-gmp configure option. See also --with-gmp-lib and --with-gmp-include.
And of course, https://gcc.gnu.org/install/configure.html says
--with-gmp=pathname
--with-gmp-include=pathname
--with-gmp-lib=pathname
--with-mpfr=pathname
--with-mpfr-include=pathname
--with-mpfr-lib=pathname
--with-mpc=pathname
--with-mpc-include=pathname
--with-mpc-lib=pathname
If you want to build GCC but do not have the GMP library, the MPFR library and/or the MPC library installed in a standard location and do not have their sources present in the GCC source tree then you can explicitly specify the directory where they are installed (‘--with-gmp=gmpinstalldir’, ‘--with-mpfr=mpfrinstalldir’, ‘--with-mpc=mpcinstalldir’). The --with-gmp=gmpinstalldir option is shorthand for --with-gmp-lib=gmpinstalldir/lib and --with-gmp-include=gmpinstalldir/include. Likewise the --with-mpfr=mpfrinstalldir option is shorthand for --with-mpfr-lib=mpfrinstalldir/lib and --with-mpfr-include=mpfrinstalldir/include, also the --with-mpc=mpcinstalldir option is shorthand for --with-mpc-lib=mpcinstalldir/lib and --with-mpc-include=mpcinstalldir/include. If these shorthand assumptions are not correct, you can use the explicit include and lib options directly. You might also need to ensure the shared libraries can be found by the dynamic linker when building and using GCC, for example by setting the runtime shared library path variable (LD_LIBRARY_PATH on GNU/Linux and Solaris systems).
That should make it pretty obvious that it's completely normal, even expected, that the files will not all be in one directory. Almost all UNIX software installs header files and libraries in separate directories.
It's usually easier to build those libs in-tree and link GCC to them statically, as described at http://gcc.gnu.org/wiki/InstallingGCC
I am using clang on a Mac but I think this question will have the same answer for gcc (and any other unix system -- hopefully).
Right now, I can't link against libboost because it lives in /usr/local/lib. Sure, I can get it to do it with the -L/usr/local/lib and setting LD_LIBRARY_PATH to include /usr/local/lib, but I want my system to search for libraries and includes in /usr/local without the need to specify it in the command line.
Is there a way to do this?
To let your system do this automaticly, you can specify the enviroment variable LIBRARY_PATH (Enviroment Variables) to you library directory (/usr/local/lib).
To make this permanent, just declare this variable in your .bashrc, or similar.
Another way is to change the specs of gcc.
Indeed, this a summary from this question: How to add a default include path for gcc in linux?
I would like to add some extra include/lib directories besides the default ones for MinGW to search upon compilation. The reason for this is because the hard drive I currently have MinGW installed into is nearly full and so I had to install Qt into my second one instead. Thus, how can I have MinGW include the Qt files by default?
You can set environment variables CPLUS_INCLUDE_PATH for include directories and LIBRARY_PATH for library directories. More information can be found in Environment Variables Affecting GCC
Use -Idirective for extra includes and -Ldirective for extra library paths such as:
g++ [...] -I C:\qt\include -L C:\qt\lib
You can use multiple -Iand -Loptions.