User Library Path

Adjust the OS environment for the adm user by adding the following into the PATH and LIBPATH / LDLIBRARYPATH variables for the adm user: /usr/sap//hdbclient So what I understand I have to add this path against the environment variable. You can set pad and psm library path using Setup - User Preferences - Path Library - padpath for pads. Setup - User Preferences - Path Library - psmpath for footprint. You can also specify more that one path for libraries. Allegro will search for PADS / Footprint in the order of the paths where libraries are specified.

There are two steps to build a program with gcc: compilation and linking.

gcc is mostly responsible for the compilation, while when linking, it uses a linker program (e.g., ld) with some additional flags.

In compilation, gcc only requires header files ( .h files)to ensure that external function calls have correct parameters matched with the definition.
After that, in the linking stage, the linker connects/links all compiled objects and libraries to an executable file.

There are two types of libraries: static library ( .a) and dynamic library ( .so, .dynlib, dll). The static libraries are copied and embedded directly to the executable file. In opposite, the dynamic libraries are not. The dynamic libraries are supposed to exist in the system where the executable file is executed.

So, where does gcc look for the header files, and the dynamic libraries?

Mac User Library Path

Check the configuration

In compilation

For c: echo | gcc -x c -E -Wp,-v - >/dev/null
For cpp: echo | gcc -x c++ -E -Wp,-v - >/dev/null

These are the outputs in my PC.

For C

Path

For cpp

In linking

  • ld's search directories:

The output from my PC.

  • gcc wraps some flags when calling ld. Therefore, the directories list is different.

The output from my PC.

  • My gcc's build information with gcc --verbose.

Note: gcc looks for the libraries' names from left to right and stop finding when it matches the first library with the searching term.

  • You also can show the library search directories list by adding the verbose flag -v when linking.
    For example: gcc -v foo.o bar.o -o foo
  • To figure out which libraries are linked with a program and the libraries' full path, use ldd. For example, ldd foo. Example output from my PC.

How to add a directory as a library search directory

Customized library paths, which are added to the compilation/linking, by the following method have higher priority than the default library search directories. In other words, if a library is found in a customized directory, it will be selected rather than the library in system default.

Compilation

Method 1: use CPATH (c or c++), C_INCLUDE_PATH (c only), CPLUS_INCLUDE_PATH (c++ only). For example: CPATH=/home/transang/my_libs_headers gcc -c foo.c -o foo.o.

Method 2: use -I<dir_path> to gcc when compiling. For example: gcc -I/home/transang/my_libs_headers -c foo.c -o foo.o.

Linking

Method 1: To add a directory to the library linking search directories list, use LD_LIBRARY_PATH environment variable. For example: LD_LIBRARY_PATH=/home/transang/my_libs gcc foo.o bar.o -o foo

Method 2: add the flag -L<dir_path> to gcc when linking. For example: gcc -L/home/transang/my_libs foo.o bar.o -o foo.

Note 1: LD_LIBRARY_PATH environment variable's value does not affect the results of ld --verbose and gcc -print-search-dirs commands.
Note 2: LD_LIBRARY_PATH 's value affects the result of ldd command. Thus, ldd command is the more reliable way to figure out library path.
Note 3: You also have to provide the LD_LIBRARY_PATH value when running the executable file. For e.g. LD_LIBRARY_PATH=/home/transang/my_libs ./foo.

How to add dynamic library when linking

So far, I have introduced a way to figure out the current configuration and modify it to add more directories for library searching.

To link a library, add -l<lib_name> flag to the gcc command when linking. If the lib_name does not start with :, gcc will look for a library named lib<lib_name>.so. Otherwise, the file name lib_name will be searched.

For example: with -lfoo, gcc looks for libfoo.so file. With -l:foo.so, gcc looks for foo.so file.

Clear environment

User Library Path Definition

In some cases, you may want a clean build that isolates from the running machine. You can use the following command:

Moreover, the system library header searching path is configured in /etc/ld.so.conf.

User Library Path Chart

By default, /etc/ld.so.conf refers to the content of all files in the directory /etc/ld.so.conf.d. You can look into the directory to control the configuration.