Add extra include/lib paths to MinGW - c++

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.

Related

CMake and MinGW-w64 include paths

I have a C++ project that needs to be built with CMake and MinGW-W64.
Some libraries (such as zlib, libpng) are in: C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32\
So I use : -DCMAKE_PREFIX_PATH="C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32"
But, I get a compilation error because the following header is outdated and miss important symbols:
C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32\include\float.h
If I add a compiler flag to search into the proper include directory for float.h:
-DCMAKE_CXX_FLAGS="-isystem C:/Dev/mingw64-5.3.0/lib/gcc/x86_64-w64-mingw32/5.3.0/include"
Then, this does not work, since CMake will add this folder after its generated includes_CXX.rsp
How can I handle this issue? Is there a way to enforce header search path priority?
You could also add the include location(s) to environment variable C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
To locate the libraries you can do the same for the lib with the LIBRARY_PATH environment variable.
For DLL and EXE files you may even need to add the bin path to PATH.

Make /usr/local/lib a default library search path for ld on mac os x?

I have XCode installed, but for some reason, /usr/local/lib is not amongst the default library search paths:
gcc -Xlinker -v
gives me:
#(#)PROGRAM:ld PROJECT:ld64-224.1
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 armv6m armv7m armv7em
Library search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/
This is unfortunate since /usr/local/lib is a fairly canonical location for installed libraries and and there is no /etc/ld.so.conf+ldconfig on mac os x to modify the default library search paths. So without using -L/usr/local/lib this results in a linker error. Is there any other, non-runtime option than setting the environment variable DYLD_LIBRARY_PATH?
EDIT: Setting the DYLD_LIBRARY_PATH env variable did nothing for me. I had to set the LIBRARY_PATH env variable instead to be able to link libraries installed under /usr/local/lib with gcc.
Was there an option about this when installing XCode? (it's a work computer, haven't installed it myself)
To add a temporary library to my project using Xcode I did the following:
To add a temporary include path to my XCode library search paths I had to do the following:
If you want to add default include and search paths you need to use:
For include paths:
CPATH
C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
OBJC_INCLUDE_PATH
And for library paths:
LIBRARY_PATH
In order for Xcode and other GUI applications in OS X (tested on 10.10) to be able to access these environment variables, you need to set variables using:
/bin/launchctl setenv LIBRARY_PATH /usr/local/lib
/bin/launchctl setenv CPATH /usr/local/include
But these are not permanent. In order to have these variables across restarts, you need to create a startup script. See this page for an example.
Environment variables starting with DYLD_ like DYLD_LIBRARY_PATH are specific to Apple's dynamic link editor called dyld. The manual pages state:
DYLD_LIBRARY_PATH
This is a colon separated list of directories that contain libraries. The dynamic linker
searches these directories before it searches the default locations for libraries. It allows
you to test new versions of existing libraries.
For each library that a program uses, the dynamic linker looks for it in each directory in
DYLD_LIBRARY_PATH in turn. If it still can't find the library, it then searches DYLD_FALL-
BACK_FRAMEWORK_PATH and DYLD_FALLBACK_LIBRARY_PATH in turn. Use the -L option to otool(1). to discover the frameworks and shared libraries that the exe-
cutable is linked against.
Please note that the DYLD_FALLBACK_LIBRARY_PATH already contains a reference to standard /usr/local/lib by default.
DYLD_FALLBACK_LIBRARY_PATH
This is a colon separated list of directories that contain libraries. It is used as the
default location for libraries not found in their install path. By default, it is set to
$(HOME)/lib:/usr/local/lib:/lib:/usr/lib.
Xcode has Project-wide or Target-specific Build Settings such as "Library Search Paths" where you would define paths to non-standard locations that you need to let the linker know about.
Apart from copying and adding *.dylib files to your Xcode project you need to "make install" those to one of these known library locations. Otherwise the O/S loader (launchd process) cannot use them during actual launch or run-time of your app image.
See: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/UsingDynamicLibraries.html
Please note that C++ as well as Object-C have their challenges regarding Dynamic Libraries.

installing GCC-4.9 without root - adding paths and binaries and extra

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.

Add only specific subdirectory of an include path to includes

I have a project which is built using cmake.
This project is uses avr-gcc to compile the binaries and I use boost mpl for some parts of it.
As avr-gcc does not have /usr/include as a default include path but boost is installed there, I need to add it as an include path such that boost is found.
Unfortunately, adding -I/usr/include to the command line pulls in all other files and directories in /usr/include which seems to introduce collisions with the avr includes and thereby compiler errors.
My initial solution involved a softlink to /usr/include/boost in one of my user defined include directories to resolve the
#include <boost/mpl/*>
However, I thought this to be not very platform independent and decided for cmake to add the include path for boost. This again led to "-I/usr/include" being present on the compiler command.
How do I solve this in a platform agnostic manner?
A solution would be to let cmake create the link for me to get the right include directory.
However, I consider the whole symbolic link solution ugly.
Is there something better that I can do?
For example: Is there some option that adds an include path under an alias like:
-I/usr/include/boost:boost
Which would add only the boost subfolder under the name boost to be includable by the #include <boost/...> directive?
I see at least two options for you:
Where does avr-gcc include files from by default? Let's say it is /opt/avr-gcc/include for concreteness. Then what may work for you is -I/opt/avr-gcc/include -I/usr/include.
Another option is to install Boost in a different directory and use that instead of the Boost in /usr/include. For example, you might create /opt/boost and then use -I/opt/boost (or a sub-directory under that) on the command line.

How do I make the c++ compiler search for libraries in /usr/local/lib?

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?