LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Freshly compiled c prgram has problems loading shared objects (https://www.linuxquestions.org/questions/programming-9/freshly-compiled-c-prgram-has-problems-loading-shared-objects-627454/)

raven 03-12-2008 04:17 AM

Freshly compiled c prgram has problems loading shared objects
 
Hello

I have a user account on a large computer at my university. There I am supposed to test some code, I developed at home.

I successfully ported what needed to be ported, successfully compiled and linked my code.

I defined on the command line

Code:

gcc -o whatever whatever.c something.c -L. -llibrary1 -llibrary2 ...
This works fine, but when I try to execute

./whatever

I get the message:
Code:

error while loading shared libraries: liblibrary1.so: cannot open shared object file: No such file or directory
The file exists only in the same path as my program does, and I don't have permission to copy it to some place like /usr/lib, I don't even know where I'd copy it if I could.

So my question: how can I tell the program to load the .so from the same path the program is? Do I need to export some env_var? If so, which env_var should be exported?

Thanks for your help.

raven

raven 03-12-2008 04:21 AM

Try first, then ask stupid questions...
 
Resolved:

export LD_LIBRARY_PATH to include ./

Then ist works.

bye

raven

ta0kira 03-12-2008 05:37 AM

It's better to use the ./ at link-time, i.e. ./liblibrary1.so instead of -llibrary1. That will hard-code the path into the binary so you don't have to export the additional path if you start a new shell session later on. You should only use -l for installed libraries. All others should be explicitly-named with at least a path fragment and the full library name.
ta0kira


All times are GMT -5. The time now is 07:17 AM.