ld cannot find shared library





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.



Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.



The problem:



I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.



Here's what I've already managed to do:




  1. Compiled all .cpp files with -fPIC explicitly stated


  2. Created the library with



    g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
    libcustom_program_options.so.1.0.1 *.o




  3. Ran ldconfig to update the loader cache like this:



    sudo ldconfig -n /usr/local/lib




And when I try to link the library against my test program:



g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options


Here's what happens:




/usr/bin/ld: cannot find -llibcustom_program_options



collect2: error: ld returned 1 exit status






Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.










share|improve this question























  • Did you try -lcustom_program_options? the l is usually expanded to lib (so for example -lm links libm.so and so on)

    – steeldriver
    Mar 23 at 20:43













  • Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.

    – TuRtoise
    Mar 25 at 10:45




















0















Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.



Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.



The problem:



I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.



Here's what I've already managed to do:




  1. Compiled all .cpp files with -fPIC explicitly stated


  2. Created the library with



    g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
    libcustom_program_options.so.1.0.1 *.o




  3. Ran ldconfig to update the loader cache like this:



    sudo ldconfig -n /usr/local/lib




And when I try to link the library against my test program:



g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options


Here's what happens:




/usr/bin/ld: cannot find -llibcustom_program_options



collect2: error: ld returned 1 exit status






Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.










share|improve this question























  • Did you try -lcustom_program_options? the l is usually expanded to lib (so for example -lm links libm.so and so on)

    – steeldriver
    Mar 23 at 20:43













  • Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.

    – TuRtoise
    Mar 25 at 10:45
















0












0








0








Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.



Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.



The problem:



I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.



Here's what I've already managed to do:




  1. Compiled all .cpp files with -fPIC explicitly stated


  2. Created the library with



    g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
    libcustom_program_options.so.1.0.1 *.o




  3. Ran ldconfig to update the loader cache like this:



    sudo ldconfig -n /usr/local/lib




And when I try to link the library against my test program:



g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options


Here's what happens:




/usr/bin/ld: cannot find -llibcustom_program_options



collect2: error: ld returned 1 exit status






Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.










share|improve this question














Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.



Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.



The problem:



I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.



Here's what I've already managed to do:




  1. Compiled all .cpp files with -fPIC explicitly stated


  2. Created the library with



    g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
    libcustom_program_options.so.1.0.1 *.o




  3. Ran ldconfig to update the loader cache like this:



    sudo ldconfig -n /usr/local/lib




And when I try to link the library against my test program:



g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options


Here's what happens:




/usr/bin/ld: cannot find -llibcustom_program_options



collect2: error: ld returned 1 exit status






Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.







shared-library g++ ld






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 18:40









TuRtoiseTuRtoise

11




11













  • Did you try -lcustom_program_options? the l is usually expanded to lib (so for example -lm links libm.so and so on)

    – steeldriver
    Mar 23 at 20:43













  • Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.

    – TuRtoise
    Mar 25 at 10:45





















  • Did you try -lcustom_program_options? the l is usually expanded to lib (so for example -lm links libm.so and so on)

    – steeldriver
    Mar 23 at 20:43













  • Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.

    – TuRtoise
    Mar 25 at 10:45



















Did you try -lcustom_program_options? the l is usually expanded to lib (so for example -lm links libm.so and so on)

– steeldriver
Mar 23 at 20:43







Did you try -lcustom_program_options? the l is usually expanded to lib (so for example -lm links libm.so and so on)

– steeldriver
Mar 23 at 20:43















Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.

– TuRtoise
Mar 25 at 10:45







Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.

– TuRtoise
Mar 25 at 10:45












1 Answer
1






active

oldest

votes


















0














Ok, I finally managed to solve it.



Once I checked what file the linker is actually expecting to find, I knew what to do next.



I did it by calling:



ld -L/usr/local/lib -lcustom_program_options --verbose


Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).



As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).



The file ld was trying to find indeed never existed.



The solution was to create the link manually:



sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so


So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1128112%2fld-cannot-find-shared-library%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Ok, I finally managed to solve it.



    Once I checked what file the linker is actually expecting to find, I knew what to do next.



    I did it by calling:



    ld -L/usr/local/lib -lcustom_program_options --verbose


    Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).



    As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).



    The file ld was trying to find indeed never existed.



    The solution was to create the link manually:



    sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so


    So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.






    share|improve this answer




























      0














      Ok, I finally managed to solve it.



      Once I checked what file the linker is actually expecting to find, I knew what to do next.



      I did it by calling:



      ld -L/usr/local/lib -lcustom_program_options --verbose


      Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).



      As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).



      The file ld was trying to find indeed never existed.



      The solution was to create the link manually:



      sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so


      So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.






      share|improve this answer


























        0












        0








        0







        Ok, I finally managed to solve it.



        Once I checked what file the linker is actually expecting to find, I knew what to do next.



        I did it by calling:



        ld -L/usr/local/lib -lcustom_program_options --verbose


        Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).



        As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).



        The file ld was trying to find indeed never existed.



        The solution was to create the link manually:



        sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so


        So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.






        share|improve this answer













        Ok, I finally managed to solve it.



        Once I checked what file the linker is actually expecting to find, I knew what to do next.



        I did it by calling:



        ld -L/usr/local/lib -lcustom_program_options --verbose


        Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).



        As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).



        The file ld was trying to find indeed never existed.



        The solution was to create the link manually:



        sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so


        So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 13:11









        TuRtoiseTuRtoise

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1128112%2fld-cannot-find-shared-library%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            數位音樂下載

            When can things happen in Etherscan, such as the picture below?

            格利澤436b