How can I change the following static linked program into dynamic linked program?

198 views Asked by At

I have already figure out how to staticly link v8 with my own GLIBC/STDC++.

$(GCC_ROOT)/bin/g++ samples/bench.cpp -o bench -isystem$(GLIBC_ROOT)/include/ -I. -Iinclude -isystem$(GLIBC) -nodefaultlibs  -DV8_COMPRESS_POINTERS -static $(V8_OBJ)/libv8_monolith.a -Wl,--start-group $(GCC_ROOT)/lib64/libstdc++.a  $(GLIBC_ROOT)/lib/libpthread.a $(GLIBC_ROOT)/lib/libdl.a $(GLIBC_ROOT)/lib/libm.a $(GLIBC_ROOT)/lib/librt.a $(GCC_GCC)/libgcc.a $(GCC_GCC)/libgcc_eh.a $(GCC_GCC)/libcommon.a $(GLIBC_ROOT)/lib/libc.a -Wl,--end-group 

However, I find it not good to link all stuff staticly, and I want to GLIBC/STDC++ dynamicly, and my strategy is:

  1. For all .a which is staticly linked, I use -Wl,-rpath= to specify its path.
  2. For those .a which has no corresponding .so, such as libgcc.a, I still link them staticly.

So I write the following command

$(GCC_ROOT)/bin/g++ samples/bench.cpp -isystem$(GLIBC_ROOT)/include/ -I. -Iinclude -isystem$(GLIBC_ROOT)/ -o bench_dyn -nodefaultlibs  -DV8_COMPRESS_POINTERS -Wl,--start-group $(V8_OBJ)/libv8_monolith.a  -Wl,-rpath=$(GCC_ROOT)/lib64/ $(GCC_GCC)/libgcc.a $(GCC_GCC)/libgcc_eh.a $(GCC_GCC)/libcommon.a -Wl,-rpath=$(GLIBC_ROOT)/lib -Wl,--end-group 

However, this strategy won't work, because lots of symbols are not found, such as

  1. pthread_mutex_*
  2. std::ostream::operator<<(int)

I think these are all GLIBC/STDC++ symbols, and I linked them dynamicly, so they should not remain undefined?

What's wrong here?

0

There are 0 answers