Click here to Skip to main content
Sign Up to vote bad
good
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 - 1:08


1 solution

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 - 24 Dec '12 - 7:58
Thanks CPallini.
CPallini - 24 Dec '12 - 8:09
You are welcome.
Sergey Alexandrovich Kryukov - 24 Dec '12 - 13:28
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
Your Filters
Interested
Ignored
     
0 Arun Vasu 339
1 OriginalGriff 320
2 Sergey Alexandrovich Kryukov 315
3 Tadit Dash 221
4 CPallini 178
0 Sergey Alexandrovich Kryukov 9,955
1 OriginalGriff 7,589
2 CPallini 4,028
3 Rohan Leuva 3,422
4 Maciej Los 2,949


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid