Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Visual-Studio GCC GNU
Hi,
 
I have mostly worked in Windows, and recently I started working in Linux. I have a doubt. I have used Visual Studio as IDE in Windows and used Makefile in Linux.
 
There are two types of libraries in Windows (VC++), static library (.lib) and DLL. It is quite obvious (isn't it?) if I link with lib file I am using static linking else dynamic linking.
 
Now when I use g++ compiler, why I need to explicitly mention -Bstatic/-static or -Bdynamic/-dynamic flags. Because if file is .a file then I must be using static linking and if file is .so I am using dynamic linking.
 
Thanks in advance.
Posted 24-Dec-12 2:08am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You usually don't pass the whole name of the library (that is complete with its extension), for instance when you link with librt you don't pass directly librt.so or librt.a, but use instead the -lrt switch on command line (please note you do the same thing on Windows, for both dynamic or static libraries the input file to the linker is a .lib one).
 
man[^] provides a good explanation of both -BStatic and -Bdynamic.
  Permalink  
Comments
Pranit Kothari at 24-Dec-12 7:58am
   
Thanks CPallini.
CPallini at 24-Dec-12 8:09am
   
You are welcome.
Sergey Alexandrovich Kryukov at 24-Dec-12 13:28pm
   
Nice, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100