LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-14-2008, 10:24 AM   #1
Aidin_36
LQ Newbie
 
Registered: Jun 2005
Location: Iran
Distribution: Debian
Posts: 24

Rep: Reputation: 15
How to NOT use shared libraries (C++)


Hi guys.
How can I compile my C++ program in a way that it dosen't use shared libraries like 'libstdc++'?

Few days ago, I give my program to one of my friends. After a while, he called me and say: "I can't run your program, it says that it want libstdc++6". The problem was he has libstdc++5, not 6.

So ... is there any way to bind this libraries inside of binary file? (like static libraries). I want a binary file which can run in any system, without dependence.

Is anyone have any idea?

(I'm using Debian GNU/Linux, and GCC compiler)
 
Old 08-14-2008, 11:11 AM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
I don't know if you can force normally dynamic libraries to be directly included in your binary. But, you could just give your friend the source code and have him compile it himself. Or, your using debian so you might be able to create a .deb 'installer'? I don't know much about .deb's cause I use suse. Anyone else know?

Last edited by CRC123; 08-14-2008 at 11:12 AM.
 
Old 08-14-2008, 11:29 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Can you not compile with "-static"? Edit: I would assume, though, that this requires that static versions of the library files (possibly .a or .la files, rather than .so, but I'm not certain) need to exist on your system.

Last edited by Nylex; 08-14-2008 at 11:32 AM.
 
Old 08-14-2008, 02:41 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Yes, -static will normally require that libstdc++.a exist, though not all compilers (or versions) use the same name. The C++ RTLs aren't supposed to be "noticed" by the user in the sense of what their names are: the C++ compiler is supposed to handle everything related to its own RTL internally from compilation all the way through linking.

I don't have a problem creating static binaries with g++ in test situations. The main problem is it will greatly increase the size of your binary, usually to at least 1MB. Also, run-time exceptions won't propagate properly, but that only really matters if you're also using exception code.
ta0kira

PS If you use g++, type whereis libstdc++ and see if libstdc++.a shows up.

Last edited by ta0kira; 08-14-2008 at 03:15 PM.
 
Old 08-15-2008, 06:42 AM   #5
Aidin_36
LQ Newbie
 
Registered: Jun 2005
Location: Iran
Distribution: Debian
Posts: 24

Original Poster
Rep: Reputation: 15
Thank you guys!

That information was very useful.
 
  


Reply

Tags
c++, dynamic, gcc, library, libstdc++


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
error while loading shared libraries: libstdc++.so.5: cannot open shared object file: Franziss Linux - Newbie 10 06-28-2010 05:47 AM
Urgent !!! rpm: error while loading shared libraries: libelf.so.1: cannot open shared tinaa Linux - Software 5 12-02-2008 03:19 PM
rtorrent: error while loading shared libraries: libtorrent.so.11: cannot open shared orsty9001 Linux - Software 3 10-29-2008 09:16 PM
error while loading shared libraries: libgvc.so.3: cannot open shared object file coolrock Slackware 6 01-17-2007 05:10 PM
error while loading shared libraries: libdb-4.1.so: cannot open shared object file putquery8581 Linux - Software 1 10-01-2004 07:03 AM


All times are GMT -5. The time now is 11:28 AM.

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