Ben Stott
Ben Stott

Reputation: 2218

GCC/G++ equivalent of ldconfig -n

When I create my own non-standard path for library files (say, ~/lib) I can run ldconfig -n ~/lib and this directory is added to the list of locations ld uses to search for non-standard libraries.

Is there a similar switch for GCC/G++ (or an appropriate gcc/++ config manager) related to include directories, and if so, what? I'm aware the -I flag will include non-standard directories, butI'd rather not have to go through all my projects and have to add all forms of magic to the makefiles to make them work -- and then find that these changes are (of course) non-portable to any other system this code is built on (with collaborators, etc), so editing the makefile isn't really an option....

Edit: Note that my ignorance assumes this solution is gcc/++ only. I'm happy for any solution, however, so if there's a method that abuses some property of ldconfig or whatever, I'm not adverse to it!

Upvotes: 2

Views: 1391

Answers (2)

Drakosha
Drakosha

Reputation: 12165

Generally, just do man gcc. You'll need -L <path> flag if you are willing to change the Makefiles. There's also a solution similar to ldconfig - to use LIBRARY_PATH env. variable.

Similarly, there's CPLUS_INCLUDE_PATH and C_INCLUDE_PATH and CPATH which are declaring a list of directories to search for header files.

Upvotes: 2

Daniele Santi
Daniele Santi

Reputation: 771

I don't think you can do this with include files, apart from modifying the gcc/g++ source code and recompile it.

The best alternative is adding an alias to your enviroment (if using bash) like:

alias gcc="gcc -Idir1 -Idir2 -Idir3"
alias g++="g++ -Idir1 -Idir2 -Idir3"

or creating an ad-hoc script.

Upvotes: 0

Related Questions