Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-11-2003, 01:45 PM   #1
LQ Newbie
Registered: Oct 2003
Distribution: CentOS5
Posts: 20

Rep: Reputation: 0
Unhappy Linking a platform independent shared library

I'm trying to create a shared library that my application will be loading at run time to determine its branding specific information. I am linking my application statically so that it is able to be run on different Linux platforms that do not have the same libraries as the one I build on. However, the shared library also needs this capability, but I can not figure out how to remove it's dependencies. Any ideas on how this would work?

Somehow, the shared library needs to use the statically linked application for its unresolved dependencies. I am using the -rdynamic flag when I link the application and I have tried using the -static flag when linking the shared library.

If it helps, my application is being linked with these flags:
g++ -static -rdynamic ...

The shared library is being linked like this, so far:
g++ -fPIC -shared -Wl,-static -lpthread -ldl -Wl,-call_shared ...

Some options I have tried using, but not successfully or perhaps not correctly are:
-nodefaultlibs -nostartfiles -nostdlibs -Wl,-nostdlib


Last edited by rozeboom; 11-13-2003 at 11:01 AM.
Old 11-15-2003, 02:47 PM   #2
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Could you be more spesific with the problem in question (with test-cases would be cool).
Also have you read the Program Library HOWTO. Most issues seems to be handled there.
Old 11-17-2003, 09:41 AM   #3
LQ Newbie
Registered: Oct 2003
Distribution: CentOS5
Posts: 20

Original Poster
Rep: Reputation: 0
Actually, I've been doing research and I've found that specifying the -Wl,-static flag before linking any libraries should be the correct thing to do.
However, it appears there is a bug in versions of GCC above 3.1.1 (from what I've read, still exploring that) which causes libstdc++.a to have an undefined versioned symbol name std::time_put_w@@CLIBCPP_3.2 when linked in this manner. That means that it is not possible to create a shared library with supporting libraries statically linked in. Here's an example:

// Hello.cpp
#include <iostream>

using namespace std;

class Hello {
Hello( const char* msg ) { cout << msg << endl; )

int main(void) {
Hello world("Hello World!");

g++ -fPIC -shared -static-libgcc -o hello.cpp -Wl,-static
/usr/bin/ld: undefined versioned symbol name std::time_put_w@@GLIBCPP3.2

Note: there are other ways to get this example to work without the -Wl,-static flag, but this is just a simple illustration of the problem.
Old 11-18-2003, 02:10 PM   #4
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Hmm.. I have not done any indepth research to be certain that that is the right way to do it, but the commands seems to work with gcc-2.95 and gcc-3.0, but not any newer official version. IIRC, there has been some major restructuring in the object format in the gcc3.2.

The problem seems to be fixed in the newest(two days old) gcc (version 3.4 20031116 (experimental)) brought from the gcc-snapshot debian package.


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
Platform-independent "/dev/null" stream redirection? wapcaplet Programming 1 08-12-2005 10:11 PM
Commandline legth problem linking a shared library DavePrince Linux - Software 0 07-20-2005 08:19 AM
any links on linking, loading shared libraries, shared objects. etc? ananthbv Programming 0 02-03-2005 07:47 AM
Installing platform independent tar.gz lin00b Linux - Newbie 6 09-23-2004 03:51 AM
proper design for a platform independent applicaiton jwstric2 Programming 1 05-31-2004 06:32 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:11 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
Open Source Consulting | Domain Registration