next up previous contents
Next: Using the gdb Debugger Up: Computational Programming in C/C++ Previous: Example Linking Zoo Program   Contents

Running

Running is where the fun really starts! Mostly this is down to the irritating habit computers have of doing what you ask them to do instead of what you want them to do. That's when you have to start looking for bugs. However, with a program built with shareable libraries you may not even get the program to run if you move either the program or the libraries it is based on. To demonstrate, I can build and move a static program:-

g++ -g -o Zoo_static.exe  Zoo.cc libZoo.so
cp  Zoo_static.exe ./tmp
cd ./tmp
./Zoo_static.exe
dog says woof woof!
...

but try that with a dynamic program:-

g++ -g -o Zoo_dynamic.exe Zoo.cc libZoo.so
cp  Zoo_dynamic*.exe ./tmp
cd ./tmp
./Zoo_share.exe
./Zoo_share.exe: error while loading shared libraries:
      libZoo.so: cannot open shared object file: No such file or directory

In general it's not a problem; you build the executables and libraries where you want them. If you do want to move things then you can use the environmental variable LD_LIBRARY_PATH to tell the loader where to find the libraries. So to fix up my problem:-

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/home/west/demo/libs
./Zoo_share.exe
dog says woof woof!
...

Use the syntax as shown above so the extra path is appended to the end of the existing colon separated list that LD_LIBRARY_PATH holds; completely redefining LD_LIBRARY_PATH might cause other things might break!


next up previous contents
Next: Using the gdb Debugger Up: Computational Programming in C/C++ Previous: Example Linking Zoo Program   Contents
P.D. Gronbech (IT Staff) 2015-10-02