Does OpenJDK statically link the C++ runtime?
Volker Simonis
volker.simonis at gmail.com
Wed Jan 4 10:09:30 UTC 2012
Regarding your first question: yes, at least the HotSpot (i.e.
libjvm.so) still statically links libstdc++.
You can verify this by looking at make/linux/makefiles/vm.make:
ifeq ($(SHARK_BUILD), true)
STATIC_CXX = false
else
ifeq ($(ZERO_LIBARCH), ppc64)
STATIC_CXX = false
else
STATIC_CXX = true
endif
endif
...
# JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
# get around library dependency and compatibility issues. Must use gcc not
# g++ to link.
ifeq ($(STATIC_CXX), true)
LFLAGS_VM += $(STATIC_LIBGCC)
LIBS_VM += $(STATIC_STDCXX)
else
LIBS_VM += -lstdc++
endif
So for any build except SHARK build and ZERO builds on ppc64,
libstdc++ is statically linked.
STATIC_STDCXX is defined in make/linux/makefiles/gcc.make as:
# statically link libstdc++.so, work with gcc but ignored by g++
STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
Regards,
Volker
On Wed, Jan 4, 2012 at 7:16 AM, John Von Seggern <vonseg at gmail.com> wrote:
> Way back in a bug report for Java 1.4, I found this note:
>
> "We statically link the C++ runtime in JDK and enabled linker script
> to hide symbols from libstdc++ and other internal symbols."
> --http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4694590
>
> Does OpenJDK continue to take this approach?
>
> I'm asking because I would like to use the Java Native Interface to
> call functions in a C++ library (that statically links the C++
> runtime). When I distribute my application, do I need to worry about
> C++ ABI compatibility issues?
>
> In case it's useful to anyone, I also asked this question on StackOverflow:
> http://stackoverflow.com/questions/8722320/is-the-java-native-interface-jni-affected-by-c-abi-compatibility-issues
>
> (I figured I'd also try asking here, too. I apologize if this is the
> wrong place.)
>
> Thanks,
> -John
More information about the build-dev
mailing list