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

  • Home
  • SEARCH
  • 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 8197545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:45:52+00:00 2026-06-07T05:45:52+00:00

I was reading Introduction to GCC and it says if a package has both

  • 0

I was reading Introduction to GCC and it says if a package has both .a and .so. gcc prefer the shared library. By default the loader searches for shared libraries only in a predefined set of system directories, such as /usr/local/lib and /usr/lib. If the library is not located in one of these directories it must be added to the load path, or you need to use -static option to force it to use the .a library. However, I tried the following:

vim hello.c:

#include <gmp.h>
#include <stdio.h>

int main() {
        mpz_t x;
        mpz_init(x);
        return 0;
}

gcc hello.c -I/opt/include -L/opt/lib -lgmp  (my gmp library is in opt)
./a.out

And it runs. The book says it should have the following error:

./a.out: error while loading shared libraries:
libgdbm.so.3: cannot open shared object file:
No such file or directory

(well, the book uses GDBM as example but I used GMP, but this won’t matter right?)

However, I did not set LD_LIBRARY_PATH=/opt/lib, and as you can see I did not use -static option either, but a.out still runs.

Can you all tell me why and show me how to get the error described in the book? Yes I want the error so I will understand what I misunderstood.

  • 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-07T05:45:52+00:00Added an answer on June 7, 2026 at 5:45 am

    From your response to my comment:

    linux-gate.so.1 => (0xb7746000)
    libgmp.so.10 => /usr/lib/i386-linux-gnu/libgmp.so.10 (0xb76c5000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7520000)
    /lib/ld-linux.so.2 (0xb7747000) 
    

    So, your program is picking up the lib from /usr/lib.

    What you can try to do is rename the lib in your /opt/lib, and link against the new name.

    mv /opt/lib/libgmp.so /opt/lib/libgmp-test.so
    gcc hello.c -I/opt/include -L/opt/lib -lgmp-test
    

    Then try running the program. Also, compare the result of ldd against the new a.out against what you got before.

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

Sidebar

Related Questions

I am reading Apple's sample codes at: http://developer.apple.com/library/mac/#samplecode/CocoaSlides/Introduction/Intro.html it works on a NSView #import
I am reading Introduction to Arrays for nawk It says: Arrays in awk superficially
I'm reading Introduction to 3D Game Programming with DirectX 10 to learn some DirectX,
I was reading GADT introduction here and it I found the idea of restricting
I'm reading a book called Introduction to algorithms . I think many of you
I'm reading Introduction to Algorithm by CLRS. In chapter 2, the authors mention loop
I'm just reading Dependent Types at Work . In the introduction to parametrised types,
I'm reading through Rob Ashton's excellent blog post on RavenDB: http://codeofrob.com/archive/2010/05/09/ravendb-an-introduction.aspx and I'm working
I was reading today about researchers discovering that NVidia's Phys-X libraries use x87 FP
I'm reading Introduction to Algorithms book, second edition, the chapter about Medians and Order

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.