Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-22-2012, 09:54 AM   #1
LQ Newbie
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Is it possible to add a shared library to a static library ?

I have created a new shared library "" . There is a existing static library "libstatic.a" . I need to refer the new code of .so into the .a files.

The libstatic.a compiles fine after I add -I<> in its Makefile.

Now this static.a is referenced in a exe . To avoid any linker issues I added -L<> -lshared in the Makefile of the exe . But when I try to compile it I get linker issue , of undefined reference to the libstatic.a for the methods of .so .

Even the nm for libstatic.a gives "U" for the methods of .so

Now my question is :

1) Is it valid to have a shared library call in a static library?
2) How to get rid of this undefined reference error ?

Please help me solve this issue.


Last edited by rupa_123; 03-23-2012 at 03:14 AM.
Old 03-23-2012, 09:22 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. You can add anything you want to a library ... including your grocery list, if you wanted.

2. You can mix'n'match shared and static references in your program: some symbols can be static, others can be dynamic.

3. By the same token, Yes: it's absolutely legal for a subroutine in a shared library to call a static reference (in which case the static reference will be included in your actual .so file). It's also legal for a subroutine in a static library to call a shared reference.
Old 03-24-2012, 11:25 AM   #3
LQ Newbie
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for confirming. So can you pls elaborate on how to get rid of the linking issue when building the exe ?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SDL static library, shared library icecubeflower Programming 6 04-09-2009 04:10 PM
Making a static library from a given shared library vro Programming 1 07-27-2007 05:07 PM
LINUX - linking archive (static library) with shared (dynamic) library gurkama Programming 5 03-05-2007 12:11 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 05:20 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration