Problem compiling SHARED libraries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wingleader
    New Member
    • May 2007
    • 24

    Problem compiling SHARED libraries

    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
    Code:
    #add definitions, compiler switches, etc.
    ADD_DEFINITIONS(-Wall -O2 -L)
    
    #build a shared library
    ADD_LIBRARY(test2 SHARED test2.cpp)
    
    #for testing the shared library you probably need some test app too
    ADD_EXECUTABLE(test2test test2test.cpp)
    
    #need to link to some other libraries ? just add them here
    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!
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    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

    Comment

    • wingleader
      New Member
      • May 2007
      • 24

      #3
      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.

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by wingleader
        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

        Comment

        • wingleader
          New Member
          • May 2007
          • 24

          #5
          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(actua lly 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?

          Comment

          • gpraghuram
            Recognized Expert Top Contributor
            • Mar 2007
            • 1275

            #6
            Originally posted by wingleader
            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(actua lly 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

            Comment

            • wingleader
              New Member
              • May 2007
              • 24

              #7
              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.

              Comment

              • gpraghuram
                Recognized Expert Top Contributor
                • Mar 2007
                • 1275

                #8
                Originally posted by wingleader
                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_LIB RARIES.
                Add the path of the libraries to LD_LIBRARY_PATH .


                raghu

                Comment

                • wingleader
                  New Member
                  • May 2007
                  • 24

                  #9
                  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
                  Code:
                  -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"

                  Comment

                  Working...