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 7556767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:56:48+00:00 2026-05-30T11:56:48+00:00

I have built a shared library (i.e libabc.so ) and an executable (i.e myapp

  • 0

I have built a shared library (i.e libabc.so) and an executable (i.e myapp) which uses my shared library. I have placed both the shared library and my executable in my filesystem but when I run my executable it gives me the following error

error while loading shared libraries: <target_lib_path>/<mylib>.so cannot open shared object file: No such file or directory.

Now my dev environment is I have a different target filesystem which is placed at ~/targetfs after building my shared library I am installing it in ~/targetfs/usr/local/abc/lib. During linking my application I give it

LDFLAGS += -L~/targetfs/usr/local/abc/lib 

My application builds fine. But when I run my application in an environment where ~/targetfs is my filesystem, then my application complains
error while loading shared libraries:

/home/user/targetfs/usr/local/abc/lib/libabc.so: can not open shared object file. No such file or directory exist.

Now, of course the path my application is searching for the shared library that does not exist, but I want my application to be independent of this path, rather it should look for my shared library in /lib, /usr/lib, /usr/local/lib or LD_LIBRARY_PATH location.

How can I make my application to link libraries independent of its location?

Makefiles for my shared library & application is given below.

————– Shared library makefile. (Omitting un-necessary info)

CC              = $(CROSS_COMPILE)gcc
CFLAGS          = -Wall -shared -fpic
LDFLAGS         = -Xlinker --gc-sections --allow-shlib-undefined
LIBRARY         = libabc.so
OBJ_DIR         = obj
SRC_DIR         = src
CHK_DIR_EXISTS  = test -d
MKDIR           = mkdir -p

# Project Source Files
C_SOURCES += $(SRC_DIR)/abc.c
OBJECTS   += $(OBJ_DIR)/abc.o
INCLUDES  += -Iinc                               
$(LIBRARY): $(OBJECTS)
    @echo ""
    @echo "Linking..." $(LIBRARY)
    @$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $(OBJ_DIR)/$(LIBRARY) 

———- Application Makefile (Omitting un-necessary info)

LDFLAGS += $(TARGETFS)/usr/local/abc/lib/libabc.so           \
       -lpthread -lrt

Any thoughts what’s missing in my Makefiles.

  • 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-05-30T11:56:49+00:00Added an answer on May 30, 2026 at 11:56 am

    You can ask the linker to put multiple search paths into the binary. You introduce those search paths with the -Wl,rpath=… option.

    gcc -o abc abc.c 
    -L~/targetfs/usr/local/abc/lib 
    -labc 
    -Wl,-rpath=/usr/local/abc/lib 
    -Wl,-rpath=...
    -Wl,-rpath=...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3. Edited for clarity. I have a shared library in which
I have a shared library project that is built from 4 static libraries (
I have a core project which I'm building as a shared library. In one
I have a simple project that uses a single library in order to run.
I have built a web page which contains a Crystal Report built using the
I have built a number of asp.net servercontrols into a class library, & I
I built a (very simple) library, which I can call just fine from another
I have successfully built and installed gcc 4.6.1 on my OS X box, but
I have an executable that was built in Qt. When I try to use
I have a static library, liborc-0.4.a with no shared library. I have another library,

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.