demo_lib.h void fun();
demo_lib.cpp
#include<iostream>
void fun(){
std::cout << "I am in demo_lib::fun()" << std::endl;
}
compiled a static library
g++ -c demo_lib.cpp -o demo_lib.o
ar rcs libdemo_lib.a demo_lib.a
main.c
#include "demo_lib.h"
int main(){
fun();
return 0;
}
compiled static
g++ -static main.cpp -L. -ldemo_lib
size of a.out is 1702697 => static linked by linker
compiled without static
g++ main.cpp -L. -ldemo_lib
size of a.out is 9247 => is demo_lib linked dynamically ??
why the difference in size here ??
i think the cpp library is linked static when we used -static compiler option
And when we don't cpp library is linked dynamically except the demo_lib.
In both case's demo_lib is linked static and only the cpp library diff
can we link static compiled library as dynamic ??
does this mean the default linkage of standard library is shared ??