Archived

This topic is now archived and is closed to further replies.

stefu

extra include and lib directories

Recommended Posts

Hi, How can I add include and lib directories where compiler/linker should search for headers/libraries? I know how to do it in Visual C in Windows but how to do it within Linux? Is there a file where I can add my directories? Thanks.

Share this post


Link to post
Share on other sites
which C/C++ compiler are you using? try checking the command-line switches. usually by running " /?" (i.e. "gcc /?"). usually the switch is something like "-I" or "/I".

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
gcc itself has the option -I to add a directory to the list of directories it searches for headers. If your library is not in one of ''the usual places'' as well, you can tell gcc to tell it''s linker to add a directory to it''s library search path with -Wl, specifically, -Wl,-rpath -Wl,/some/path.

Quick example:
liboffbeat.so''s header files are in: /usr/local/someoffbeatdir/include; the library itself is in /usr/local/someoffbeatdir/lib. The gcc commandline would look something like "gcc -I/usr/local/someoffbeatdir/include -Wl,-rpath -Wl,/usr/local/someoffbeatdir/lib -loffbeat mysource.c -o mysource".

I, uh, think.

Share this post


Link to post
Share on other sites
You could try to add your directory to the /etc/ld.so.conf, run a ldconfig -v afterwards. But this will only work for your lib files. You may want to copy your include files to the "/usr/include" dir. so they will be found on default.

Or make an symbolic link to your real dir, with the "ln -s /usr/include/X /your/dir"

Hope this helps,

Bel''ni

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don''t copy header files. Some of them have path to other headers hard coded in them (often done by configure). Better to link them to /usr/include if required (ln -s /path/to/headers/* /usr/include).

However, there is no reason you should ever need to have all your header files accessible directly. Today''s programs are quite friendly (configure scripts do all the hard work) and will usually find the header files or ask you to provide the path to them (usually a --with-foo=/usr/local/foo/include flag).

For more ''standard'' directories like /usr/local/include that aren''t checked by GCC, you can edit /usr/lib/gcc-lib/{linux_version}/{gcc_version}/specs and add it to the C preprocessor directives (*cpp). On my computers, it looks like this (taken from a Linux, but they''re all alike):

*cpp:
%(cpp_cpu) -I/usr/local/include %{fPIC:-D__PIC__ -D__pic} etc

The -I/usr/local/include was added manually so that it''s added to the the C preprocessor include path.

You could also add something like: export LD_LIBRARY_PATH=/path/to/lib and export C_INCLUDE_PATH=/path/to/headers to your $HOME/.{shell}rc and or .profile, but that''s also dangerous (it could be set by a system wide script, so you''ll want to make sure you don''t overwrite it). These variables differ slightly on some Unices. I believe AIX uses LIBPATH and HP-UX SHLIB_PATH in place of LD_LIBRARY_PATH, so you will want to double check if you need to use these on another system like AIX or HP-UX.

Share this post


Link to post
Share on other sites