Set include path linux

How to add include and lib paths to configure/make cycle?

I need a place to install libraries in a linux box I have no su access to. I’m using ~/local[/bin,/lib,/include], but I don’t know how can I tell ./configure to look for libraries there (particularly, I’m trying to compile emacs, which needs libgif, which doesn’t come in my distro). I tried adding

export PATH=$PATH:~/local/bin export LD_LIBRARY_PATH=~/local/lib export C_INCLUDE_PATH=~/local/include export CPLUS_INCLUDE_PATH=~/local/include 

Note that excepted for the PATH, you overwrite your system default ones. If you make something like export C_INCLUDE_PATH=~/local/include:$C_INCLUDE_PATH , your compiler will search firstly in ~/local/include , and in $C_INCLUDE_PATH only if it didn’t found the include in the first directory.

6 Answers 6

You want a config.site file. Try:

$ mkdir -p ~/local/share $ cat ~/local/share/config.site CPPFLAGS=-I$HOME/local/include LDFLAGS=-L$HOME/local/lib . EOF

Whenever you invoke an autoconf generated configure script with —prefix=$HOME/local, the config.site will be read and all the assignments will be made for you. CPPFLAGS and LDFLAGS should be all you need, but you can make any other desired assignments as well (hence the . in the sample above). Note that -I flags belong in CPPFLAGS and not in CFLAGS, as -I is intended for the pre-processor and not the compiler.

William; A thanks, that was bang on advice about CPPFLAGS for building on a shared host. Saved much thrashing about with failed ./configure runs today, because of your note.

Set LDFLAGS and CFLAGS when you run make:

$ LDFLAGS="-L/home/me/local/lib" CFLAGS="-I/home/me/local/include" make 

If you don’t want to do that a gazillion times, export these in your .bashrc (or your shell equivalent). Also set LD_LIBRARY_PATH to include /home/me/local/lib:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/me/local/lib 

when I add LDFLAGS and CFLAGS to .bashrc ./configure fails with a configure: error: C compiler cannot create executables.

They are probably overriding the configure test code compiler parameters. Just use the make env prefetching. Also try and see if configure doesn’t already have an option for overriding libgif. If the autotools scripts are properly made it will alow you to spec a path where libgif is installed (e.g. override the default library location). That would be the cleaner solution.

same difference.. tneme@ws16lab07:~/Descargas/emacs-23.3$ LDFLAGS=»-L/home/tneme/local/lib» CFLAGS=»-l/home/tneme/local/include» ./configure —prefix=»/home/tneme/local» checking build system type. i686-pc-linux-gnu checking host system type. i686-pc-linux-gnu checking for gcc. gcc checking whether the C compiler works. no configure: error: in /home/tneme/Descargas/emacs-23.3′: configure: error: C compiler cannot create executables See config.log’ for more details t

just tried configuring emacs 23 with these and I didn’t get that problem: LDFLAGS=»-L/home/me/local/lib» CFLAGS=»-I/home/me/local/include» ./configure checking build system type. x86_64-unknown-linux-gnu checking host system type. x86_64-unknown-linux-gnu checking for gcc. gcc checking for C compiler default output file name. a.out checking whether the C compiler works. yes checking whether we are cross compiling. no checking for suffix of executables. checking for suffix of object files. o checking whether we are using the GNU C compiler. yes

Читайте также:  Linux run python environment

This took a while to get right. I had this issue when cross-compiling in Ubuntu for an ARM target. I solved it with:

PATH=$PATH:/ccpath/bin CC=ccname-gcc AR=ccname-ar LD=ccname-ld CPPFLAGS="-nostdinc -I/ccrootfs/usr/include . " LDFLAGS=-L/ccrootfs/usr/lib ./autogen.sh --build=`config.guess` --host=armv5tejl-unknown-linux-gnueabihf 

Notice CFLAGS is not used with autogen.sh/configure, using it gave me the error: «configure: error: C compiler cannot create executables». In the build environment I was using an autogen.sh script was provided, if you don’t have an autogen.sh script substitute ./autogen.sh with ./configure in the command above. I ran config.guess on the target system to get the —host parameter.

After successfully running autogen.sh/configure, compile with:

PATH=$PATH:/ccpath/bin CC=ccname-gcc AR=ccname-ar LD=ccname-ld CPPFLAGS="-nostdinc -I/ccrootfs/usr/include . " LDFLAGS=-L/ccrootfs/usr/lib CFLAGS="-march=. -mcpu=. etc." make 

The CFLAGS I chose to use were: «-march=armv5te -fno-tree-vectorize -mthumb-interwork -mcpu=arm926ej-s». It will take a while to get all of the include directories set up correctly: you might want some includes pointing to your cross-compiler and some pointing to your root file system includes, and there will likely be some conflicts.

I’m sure this is not the perfect answer. And I am still seeing some include directories pointing to / and not /ccrootfs in the Makefiles. Would love to know how to correct this. Hope this helps someone.

Источник

How to add a default include path for gcc in linux?

Linux: how to add a default include path for GCC in Linux?

There are several ways to add a default include path for GCC in Linux. Here, we will discuss two methods:

Method 1: Using command line options

  • Step 1 — Open the terminal on your Linux machine
  • Step 2 — Compile your code using the -I option followed by the path to your include directory

For example, if you want to add the directory /usr/local/include as an include path, you would use the following command:

gcc -I/usr/local/include -o myprogram myprogram.c

This tells GCC to look for include files in the /usr/local/include directory in addition to the default include paths.

  • Step 3 — Once you have compiled your program using the -I option, you can run it by typing the following command:

Method 2: Using environment variables

  • Step 1 — Open the terminal on your Linux machine
  • Step 2 — Check the current value of the environment variable C_INCLUDE_PATH by typing the following command:

This will show you the current include paths that are set for GCC.

  • Step 3 — To add a new include path, you can set the C_INCLUDE_PATH environment variable to the new path

For example, if you want to add the directory /usr/local/include as an include path, you would use the following command:

export C_INCLUDE_PATH token punctuation">:$C_INCLUDE_PATH"

This tells GCC to look for include files in the /usr/local/include directory in addition to the default include paths.

  • Step 4 — Once you have set the environment variable, you can compile your code as usual and it will use the new include path
gcc -o myprogram myprogram.c
  • Step 5 — Once you have compiled your program using the environment variable, you can run it by typing the following command:
  • The above methods are for temporary settings and the include path will be lost after you close the terminal. To make the include path permanent, you can add the export command to your .bashrc file.
  • Instead of C_INCLUDE_PATH, you can also use CPLUS_INCLUDE_PATH for c++ programs, and the same command with different environment variable name.
Читайте также:  Перенести линукс другой диск

You can also use the -L flag to add a default library path for GCC in Linux.

Method 1: Using command line options

  • Step 1 — Open the terminal on your Linux machine
  • Step 2 — Compile your code using the -L option followed by the path to your library directory

For example, if you want to add the directory /usr/local/lib as a library path, you would use the following command:

gcc -L/usr/local/lib -o myprogram myprogram.c

This tells GCC to look for libraries in the /usr/local/lib directory in addition to the default library paths.

  • Step 3 — Once you have compiled your program using the -L option, you can run it by typing the following command:

Method 2: Using environment variables

  • Step 1 — Open the terminal on your Linux machine
  • Step 2 — Check the current value of the environment variable LD_LIBRARY_PATH by typing the following command:

This will show you the current library paths that are set for GCC.

  • Step 3 — To add a new library path, you can set the LD_LIBRARY_PATH environment variable to the new path

For example, if you want to add the directory /usr/local/lib as a library path, you would use the following command:

export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"

This tells GCC to look for libraries in the /usr/local/lib directory in addition to the default library paths.

  • Step 4 — Once you have set the environment variable, you can compile your code as usual and it will use the new library path
gcc -o myprogram myprogram.c
  • Step 5 — Once you have compiled your program using the environment variable, you can run it by typing the following command:
  • The above methods are for temporary settings and the library path will be lost after you close the terminal. To make the library path permanent, you can add the export command to your .bashrc file.
  • Instead of LD_LIBRARY_PATH, you can also use LIBRARY_PATH for some systems, and the same command with different environment variable name.

It’s important to note that, while the -I flag is used to specify additional directories for the preprocessor to search for header files and the -L flag is used to specify additional directories for the linker to search for libraries, the environment variables C_INCLUDE_PATH and LD_LIBRARY_PATH, respectively, have the same effect as the command line options.

Conclusion

In conclusion, there are several ways to add a default include and library path for GCC in Linux. The two most common methods are using command line options and using environment variables. To add an include path, you can use the -I option followed by the path to your include directory when compiling your code, or set the C_INCLUDE_PATH environment variable to the new path. To add a library path, you can use the -L option followed by the path to your library directory when compiling your code, or set the LD_LIBRARY_PATH environment variable to the new path. It’s important to note that these settings are temporary and will be lost after closing the terminal, but you can make them permanent by adding the export command to your .bashrc file.

Читайте также:  Линукс чем качать файлы

Источник

Where are include files stored — Ubuntu Linux, GCC

the compiler, GCC in my case, knows where that stdio.h (and even the object file) are located on my hard drive. It just utilizes the files with no interaction from me. I think that on my Ubuntu Linux machine the files are stored at /usr/include/ . How does the compiler know where to look for these files? Is this configurable or is this just the expected default? Where would I look for this configuration? Since I’m asking a question on these include files, what are the source of the files? I know this might be fuzzy in the Linux community but who manages these? Who would provide and manage the same files for a Windows compiler. I was always under the impression that they come with the compiler but that was an assumption.

4 Answers 4

When the include file is in brackets the preprocessor first searches in paths specified via the -I flag. Then it searches the standard include paths (see the above link, and use the -v flag to test on your system).

When the include file is in quotes the preprocessor first searches in the current directory, then paths specified by -iquote, then -I paths, then the standard paths.

-nostdinc can be used to prevent the preprocessor from searching the standard paths at all.

Environment variables can also be used to add search paths.

When compiling if you use the -v flag you can see the search paths used.

gcc is a rich and complex «orchestrating» program that calls many other programs to perform its duties. For the specific purpose of seeing where #include «goo» and #include will search on your system, I recommend:

$ touch a.c $ gcc -v -E a.c . #include ". " search starts here: #include search starts here: /usr/local/include /usr/lib/gcc/i686-apple-darwin9/4.0.1/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. # 1 "a.c" 

This is one way to see the search lists for included files, including (if any) directories into which #include «. » will look but #include <. >won’t. This specific list I’m showing is actually on Mac OS X (aka Darwin) but the commands I recommend will show you the search lists (as well as interesting configuration details that I’ve replaced with . here;-) on any system on which gcc runs properly.

Источник

Оцените статью
Adblock
detector