Click here to Skip to main content
15,886,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.
 
Share this answer
 
Comments
[no name] 24-Dec-12 7:58am    
Thanks CPallini.
CPallini 24-Dec-12 8:09am    
You are welcome.
Sergey Alexandrovich Kryukov 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900