RFC: Why are -lsupc++ -lstdc++ needed when linking java programs?

David Daney ddaney@avtrex.com
Wed Oct 1 17:22:00 GMT 2003


I am playing around with mipsel-linux-gcj (GCC) 3.4 20030930 
(experimental).  Mainline cvs configured for mipsel-linux target.


My "test" program is PR218.java from the libgcj testsuite.

When compiled in the "standard" manner:

$ mipsel-linux-gcj -static -o PR218 -O3 --main=PR218 PR218.java

/home/testcvs/lib/gcc/mipsisa32el-linux/3.4/../../../../mipsisa32el-linux/lib/libgcj.a(prims.o)(.text+0xb3c): 
In function `parse_heap_size':
/home/testcvs/mipsisa32el-linux/sys-include/stdlib.h:307: undefined 
reference to `__cxa_call_unexpected'
/home/testcvs/lib/gcc/mipsisa32el-linux/3.4/../../../../mipsisa32el-linux/lib/libgcj.a(prims.o)(.text+0xb44):/home/testcvs/mipsisa32el-linux/sys-include/stdlib.h:307: 
undefined reference to `__cxa_call_unexpected'
/home/testcvs/lib/gcc/mipsisa32el-linux/3.4/../../../../mipsisa32el-linux/lib/libgcj.a(natFile.o)(.text+0x764):/home/testcvs/mipsisa32el-linux/sys-include/sys/stat.h:345: 
undefined reference to `__cxa_call_unexpected'
/home/testcvs/lib/gcc/mipsisa32el-linux/3.4/../../../../mipsisa32el-linux/lib/libgcj.a(natFile.o)(.text+0x76c):/home/testcvs/mipsisa32el-linux/sys-include/sys/stat.h:345: 
undefined reference to `__cxa_call_unexpected'
/home/testcvs/lib/gcc/mipsisa32el-linux/3.4/../../../../mipsisa32el-linux/lib/libgcj.a(natFile.o)(.text+0x8bc):/home/testcvs/mipsisa32el-linux/sys-include/sys/stat.h:345: 
undefined reference to `__cxa_call_unexpected'
/home/testcvs/lib/gcc/mipsisa32el-linux/3.4/../../../../mipsisa32el-linux/lib/libgcj.a(natFile.o)(.text+0x8c4):/home/testcvs/mipsisa32el-linux/sys-include/sys/stat.h:345: 
more undefined references to `__cxa_call_unexpected' follow
collect2: ld returned 1 exit status


The problem seems to be that some of the 'C++' files in libgcj require 
the C++ runtime (at least for the mipsel-linux target), but it is not 
being linked by the gcj driver.

If I compile and link like this:

$ mipsel-linux-gcj -static -o PR218 -O3 --main=PR218 PR218.java -u 
__cxa_call_unexpected -lsupc++ -lstdc++

Then I am successful, and the program runs as expected.

Q: Do we need to add -lsupc++ -lstdc++ to gcj?



Thanks in advance for any insight.

David Daney



More information about the Java mailing list