Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a number of legacy codes that need to be compiled with specific (and often conflicting) libraries. To be specific I have a program which can only be compiled with g77 and another program which can only be compiled with gfortran.

Let's call the first program makee and the second program UVES_popler.

When compiling (and running) they both need to be linked to the version of pgplot that is compiled with the respective compiler. So, compiling makee with g77 needs to run with pgplot that has been compiled by g77 as well. And the same, respectively for UVES_popler and gfortran.

Let's assume that I can compile pgplot with both g77 and gfortran -- what is the best practice for organizing my bashrc? Should I create a bash function for each program and have the proper links and LD_LIBRARY_PATHs? Something like:

runmakee() {
  export LD_LIBRARY_PATH=/path/to/g77-pgplot/
  makee
}

And (probably relatedly) is there a way of setting flags in Makefiles so that the proper libraries are called when compiling these programs respectively?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Your bash functions should work, but the "usual" way of doing that is to write a wrapper script for each executable, and set anything that needs to be set in there. (You can change the executable name to foo.bin for instance, and call the wrapper script foo to make it easy to call.)

For ELF targets (not sure about other object formats), you can also set the -rpath linker option to hard-code a runtime library search path in your executables directly. With gcc (for C code), for the final link stage, it would look like:

gcc ... -Wl,-rpath,/your/hardcoded/path ...

I assume the Fortran compilers have similar options, or that you can change the linker options directly yourself (in which case the option is -rpath /your/path).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.