Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:53:29+00:00 2026-06-02T05:53:29+00:00

I’ve made a program that uses two shared libraries (which I compiled) and are

  • 0

I’ve made a program that uses two shared libraries (which I compiled) and are placed like this:

/home_directory_where_I_compile_and_run_everything
-->/lib/libjson_linux-gcc-4.4.6_libmt.so
-->/lib/libre2.so.0

When I compile my program I pass the relative location of those libraries to the linker, like this:

g++ ...... stuff ........ my_program.cc lib/libjson_linux-gcc-4.4.6_libmt.so lib/libre2.so.0

And it compiles fine, however when running the program it fails to find libre2.so, and if I inspect it with ldd, here’s what happens:

....
lib/libjson_linux-gcc-4.4.6_libmt.so (0x00007f62906bc000)
libre2.so.0 => not found
....

Apparently, it does acknowledge that the path on libjson is relative, but it doesn’t do that on libre2.so.0 (it trims all the path and just leaves libre2.so.0)

Can someone tell me why this happens?

Also, is there a way to modify this via a g++ argument?

Best.

* UPDATE * Whoa check this out!
I’ve changed the name of libre2.so.0 to stuff.so, and then tried to compile essentially the same like this:

g++ ...... stuff ........ my_program.cc lib/libjson_linux-gcc-4.4.6_libmt.so lib/stuff.so

And it fails anyways; not only it does fail, it fails because it can’t find “libre2.so.0”.

Whyyy?

* UPDATE # 2 *

Output for readelf -d the_program.o

0x0000000000000001 (NEEDED)             Shared library: [lib/libjson_linux-gcc-4.4.6_libmt.so]
0x0000000000000001 (NEEDED)             Shared library: [libre2.so.0]

Now, if I could just make that [libre2.so.0] to be [lib/libre2.so.0] instead it would be fine.

* UPDATE # 3 *

As @troubadour found out:

When an executable is linked with a shared object which has a DT_SONAME field, then when the executable is run the dynamic linker will attempt to load the shared object specified by the DT_SONAME field rather than the using the file name given to the linker.

That’s why it works with libjson…..so and not with libre2.so.0. (libjson…..so does not have an entry for SONAME).

And I finally found the exact question for what I’m looking for:

Is there any way to tell the gcc linker to ignore the SONAME entries on a shared library file and link instead to the specific file path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:53:31+00:00Added an answer on June 2, 2026 at 5:53 am

    I’ll answer the second part of your question first i.e. why renaming libre2.so.0 didn’t do what you expected.

    The file name that you pass to the linker is irrelevant when you run the executable (unless you fail to supply -soname when building the library – see second edit below). The dependency is taken from what is called the “soname”. If you run the readelf command on your library you can determine its soname eg.

    readelf -d libre2.so.0 | grep SONAME
    

    It doesn’t matter if you rename the file. The result of the above command will still give you the same soname, hence the reason the program still failed to find “libre2.so.0”.

    As to the original part of your question it all hinges on whether the libraries have an RPATH or RUNPATH built in to them and/or what the content of your LD_LIBRARY_PATH environment variable is. These are the things the run-time linker (ld.so) will use to find the shared libraries. Try

    man ld.so
    

    for more information.

    Since you built the libraries yourself you will know whether or not they used the -rpath or -runpath options at the final linking stage. Alternatively, use readelf again eg.

    readelf -d libre2.so.0 | grep RPATH
    readelf -d libre2.so.0 | grep RUNPATH
    

    I suspect the above two commands will return nothing.

    My guess was going to be that you have the current directory in your LD_LIBRARY_PATH which would allow the run-time linker to find lib/libjson_linux-gcc-4.4.6_libmt.so but not libre2.so.0. I notice that you’ve replied to my comment on your question to say that your LD_LIBRARY_PATH is empty. That’s odd.

    Perhaps you’ve somehow got the prefix “lib/” on the soname for libjson? i.e. did the readelf command for the SONAME return

    lib/libjson_linux-gcc-4.4.6_libmt.so
    

    rather than just

    libjson_linux-gcc-4.4.6_libmt.so
    

    Also, check what the program needs in terms of soname by running

    readelf -d my_progam | grep NEEDED
    

    Perhaps the “lib/” prefix is in there because of the way you passed it to gcc. If so then if you use the gcc command given by @enobayram then it will level the playing field i.e. it will fail to find libjson too.

    The first thing to establish is not why it is not finding libre2.so.0 but how it is managing to find libjson. If you try running your executable from a different directory does it still work or does it now fail for libjson too? Alternatively, if you copy libre2.so.0 to be beside your executable does that change anything?

    Edit

    A posting on the Fedora Forum suggest that the Fedora version of ld.so has the current directory as a built-in search path. I haven’t been able to verify this though but it would explain why you are picking up any libraries at all given that all the other things ld.so uses are absent on your case.

    Edit 2

    From the ld man page on my system

    -soname=name

    When creating an ELF shared object, set the internal DT_SONAME field
    to the specified name. When an executable is linked with a shared
    object which has a DT_SONAME field, then when the executable is run
    the dynamic linker will attempt to load the shared object specified by
    the DT_SONAME field rather than the using the file name given to the
    linker.

    Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
    Software Foundation, Inc.

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3 or
    any later version published by the Free Software Foundation; with no
    Invariant Sections, with no Front-Cover Texts, and with no Back- Cover
    Texts. A copy of the license is included in the section entitled “GNU
    Free Documentation License”.

    So, the theory in your comment is correct. If no -soname is explicitly specified when the library is built then no SONAME exists in the shared object and the NEEDED field in the executable simply has the file name given to the linker which, in your case, contained the leading “lib/”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.