By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,666 Members | 1,909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,666 IT Pros & Developers. It's quick & easy.

Problem compiling SHARED libraries

P: 24
Hi everyone!
I've got such a problem, that I'm using Kdevelop 3. Kdevelop offer only cmake for compiling with shared library support. So it uses CMakeLists.txt as config file for that
Expand|Select|Wrap|Line Numbers
  1. #add definitions, compiler switches, etc.
  2. ADD_DEFINITIONS(-Wall -O2 -L)
  3.  
  4. #build a shared library
  5. ADD_LIBRARY(test2 SHARED test2.cpp)
  6.  
  7. #for testing the shared library you probably need some test app too
  8. ADD_EXECUTABLE(test2test test2test.cpp)
  9.  
  10. #need to link to some other libraries ? just add them here
  11. TARGET_LINK_LIBRARIES(test2test test2)
Thats an example. It works. But, I cannot move the program. It always looks for that shared library ONLY where it was created. How this problem could be solved? Help please, someone!
Aug 11 '08 #1
Share this Question
Share on Google+
8 Replies


gpraghuram
Expert 100+
P: 1,275
I can understand the issue fully.
Are you saying that the .so is not being looked up properly or you want that to look for the .so in a different directory?

Raghu
Aug 12 '08 #2

P: 24
Actually I need to "unlock" it. I don't want it looking for ablosute adress based dependecies. I need something like that: ./libs or something like that. It will be a Web based programm. So for users it will be impossible to install libraries to exact place. It would be good, if it was possible to make executable to look for libraries in the same folder, where executable is run.

And yes, programm must depend on *.so files by idea. I don't want there to be all in one executable. Shared libraries are required.

PS. I'm soory for my broken English.
Aug 12 '08 #3

gpraghuram
Expert 100+
P: 1,275
Actually I need to "unlock" it. I don't want it looking for ablosute adress based dependecies. I need something like that: ./libs or something like that. It will be a Web based programm. So for users it will be impossible to install libraries to exact place. It would be good, if it was possible to make executable to look for libraries in the same folder, where executable is run.

And yes, programm must depend on *.so files by idea. I don't want there to be all in one executable. Shared libraries are required.

PS. I'm soory for my broken English.

If you want to have a single executable accessible via web then go for a static library in which the library gets bundled with the executable.

Raghu
Aug 13 '08 #4

P: 24
I guess, that I have explained something wrog... Look... Executable and *.so files are written by me and all together only they work as a programm. I need a help with CMake directives. It has to compile libraries(actually it compiles secondary *.cpp as SHARED (*.so)). But the problem is, that after compiling it makes executable to search for libraries in the static adress(for exaple my project's files are in folder /Arhiv/Devel/someproject/). And if I move executable and libraries(*.so files) to (for example) /Programm/ it crashes with erroe that it can't find *.so files.

So I don't need Only exexutable file, I need executable with shared libraries. I guess so, that there is an error during compilation process.

How to make it work properly?
Aug 13 '08 #5

gpraghuram
Expert 100+
P: 1,275
I guess, that I have explained something wrog... Look... Executable and *.so files are written by me and all together only they work as a programm. I need a help with CMake directives. It has to compile libraries(actually it compiles secondary *.cpp as SHARED (*.so)). But the problem is, that after compiling it makes executable to search for libraries in the static adress(for exaple my project's files are in folder /Arhiv/Devel/someproject/). And if I move executable and libraries(*.so files) to (for example) /Programm/ it crashes with erroe that it can't find *.so files.

So I don't need Only exexutable file, I need executable with shared libraries. I guess so, that there is an error during compilation process.

How to make it work properly?

Then you have to set the LD_LIBRARY_PATH properly for this.
Usually when the executable loads it looks for the .so in the paths given in LD_LIBRARY_PATH...

Raghu
Aug 14 '08 #6

P: 24
Yes, that's the thing I really need to do.

Could you give some example? (cmake config file is shown at first post).

Thanx for help.
Aug 14 '08 #7

gpraghuram
Expert 100+
P: 1,275
Yes, that's the thing I really need to do.

Could you give some example? (cmake config file is shown at first post).

Thanx for help.

I think you shuld do it in the variable TARGET_LINK_LIBRARIES.
Add the path of the libraries to LD_LIBRARY_PATH.


raghu
Aug 15 '08 #8

P: 24
So, I've got to read LOTS of manual. Currently started using MonoDevelop for linux(just because it's more comfortable for huge projects). And currently programm works perfectly. The solution is to add custom linker tag
Expand|Select|Wrap|Line Numbers
  1. -Wl,-rpath,'$ORIGIN/.libs'
This command makes executable to search for llibraries in execution directory/.libs .
$ORIGIN = current directory
So it will find libs in "./.libs/"

Huge thanks to everyone!
Answer is written in case if someone has simmilar problem.
PS. For more detailed information see "man ld.so"
Aug 19 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.