Click here to Skip to main content
13,409,451 members (37,897 online)
Rate this:
Please Sign up or sign in to vote.

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
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 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.
Pranit Kothari 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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180212.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2018
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