If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
I've finally managed to compile my library into a static library for the Dreamcast, however when I try to use it I get undefined references from all the C++ functions. I've tried to manually link stdc++ but it doesn't seem to make any difference, here's the link line (generated by CMake):
You should definitely be linking with sh-elf-g++ or kos-c++. KOS' built-in "linker" flags, assume that. That, and it's rather annoying to even try to get sh-elf-ld to do the right thing with libstdc++ anyway.
As for your problem, you're sure whatever functions that are coming up as undefined are actually available in the version of libstdc++ in use?
compatibility.o:
00000000 n _ZNSt11char_traitsIcE11eq_int_typeERKiS2_
00000000 n _ZNSt11char_traitsIcE3eofEv
00000000 n _ZNSt11char_traitsIwE11eq_int_typeERKjS2_
00000000 n _ZNSt11char_traitsIwE3eofEv
00000000 n _ZSt3minIiERKT_S2_S2_
00000000 n _ZStoRRSt12_Ios_IostateS_
00000000 n _ZStorSt12_Ios_IostateS_
U __Unwind_Resume
00000000 t __ZL20__gthread_key_deletei
U __ZNKSi6sentrycvbEv
U __ZNKSt13basic_istreamIwSt11char_traitsIwEE6sentrycvbEv
U __ZNKSt15basic_streambufIcSt11char_traitsIcEE4gptrEv
U __ZNKSt15basic_streambufIcSt11char_traitsIcEE5egptrEv
U __ZNKSt15basic_streambufIwSt11char_traitsIwEE4gptrEv
U __ZNKSt15basic_streambufIwSt11char_traitsIwEE5egptrEv
U __ZNKSt9basic_iosIcSt11char_traitsIcEE5rdbufEv
U __ZNKSt9basic_iosIwSt11char_traitsIwEE5rdbufEv
00000000 T __ZNSi6ignoreEi
U __ZNSi6ignoreEv
U __ZNSi6sentryC1ERSib
00000000 W __ZNSt11char_traitsIcE11eq_int_typeERKiS2_
00000000 W __ZNSt11char_traitsIcE3eofEv
00000000 W __ZNSt11char_traitsIwE11eq_int_typeERKjS2_
00000000 W __ZNSt11char_traitsIwE3eofEv
00000000 T __ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEi
U __ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEv
U __ZNSt13basic_istreamIwSt11char_traitsIwEE6sentryC1ERS2_b
U __ZNSt15basic_streambufIcSt11char_traitsIcEE12__safe_gbumpEi
U __ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetcEv
U __ZNSt15basic_streambufIcSt11char_traitsIcEE6snextcEv
U __ZNSt15basic_streambufIwSt11char_traitsIwEE12__safe_gbumpEi
U __ZNSt15basic_streambufIwSt11char_traitsIwEE5sgetcEv
U __ZNSt15basic_streambufIwSt11char_traitsIwEE6snextcEv
U __ZNSt9basic_iosIcSt11char_traitsIcEE11_M_setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIwSt11char_traitsIwEE11_M_setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIwSt11char_traitsIwEE8setstateESt12_Ios_Iostate
00000000 W __ZSt3minIiERKT_S2_S2_
00000000 W __ZStoRRSt12_Ios_IostateS_
00000000 W __ZStorSt12_Ios_IostateS_
U __ZTIN10__cxxabiv115__forced_unwindE
U ___cxa_begin_catch
U ___cxa_end_catch
U ___cxa_rethrow
U ___gxx_personality_v0
U _kthread_key_delete
compatibility-debug_list.o:
00000000 n _ZSt4swapIPNSt6__norm15_List_node_baseEEvRT_S4_
00000000 T __ZNSt6__norm15_List_node_base4hookEPS0_
00000000 T __ZNSt6__norm15_List_node_base4swapERS0_S1_
00000000 T __ZNSt6__norm15_List_node_base6unhookEv
00000000 T __ZNSt6__norm15_List_node_base7reverseEv
00000000 T __ZNSt6__norm15_List_node_base8transferEPS0_S1_
00000000 W __ZSt4swapIPNSt6__norm15_List_node_baseEEvRT_S4_
compatibility-debug_list-2.o:
compatibility-list.o:
00000000 n _ZSt4swapIPSt15_List_node_baseEvRT_S3_
00000000 T __ZNSt15_List_node_base4hookEPS_
00000000 T __ZNSt15_List_node_base4swapERS_S0_
00000000 T __ZNSt15_List_node_base6unhookEv
00000000 T __ZNSt15_List_node_base7reverseEv
00000000 T __ZNSt15_List_node_base8transferEPS_S0_
00000000 W __ZSt4swapIPSt15_List_node_baseEvRT_S3_
compatibility-list-2.o:
compatibility-c++0x.o:
00000000 t __ZL20__gthread_key_deletei
00000000 r __ZStL19piecewise_construct
U _kthread_key_delete
compatibility-atomic-c++0x.o:
00000000 t __ZL20__gthread_key_deletei
00000000 r __ZStL10adopt_lock
00000000 r __ZStL10defer_lock
00000000 r __ZStL11try_to_lock
00000000 r __ZStL13allocator_arg
00000000 r __ZStL19piecewise_construct
00000000 r __ZStL6ignore
U _kthread_key_delete
compatibility-thread-c++0x.o:
00000000 t __ZL20__gthread_key_deletei
00000000 r __ZN9__gnu_cxxL21__default_lock_policyE
00000000 r __ZStL10adopt_lock
00000000 r __ZStL10defer_lock
00000000 r __ZStL11try_to_lock
00000000 r __ZStL13allocator_arg
00000000 r __ZStL19piecewise_construct
00000000 r __ZStL6ignore
U _kthread_key_delete
That's all it outputs... surely there should be more than that? Did I do something wrong when compiling the toolchain?
compatibility.o:
U __Unwind_Resume
00000000 T __ZNSi6ignoreEi
U __ZNSi6ignoreEv
U __ZNSi6sentryC1ERSib
00000000 T __ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEi
U __ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEv
U __ZNSt13basic_istreamIwSt11char_traitsIwEE6sentryC1ERS2_b
00000000 t __ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetcEv.part.1
00000000 t __ZNSt15basic_streambufIwSt11char_traitsIwEE5sgetcEv.part.4
U __ZNSt9basic_iosIcSt11char_traitsIcEE11_M_setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
U __ZNSt9basic_iosIwSt11char_traitsIwEE11_M_setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIwSt11char_traitsIwEE5clearESt12_Ios_Iostate
U __ZTIN10__cxxabiv115__forced_unwindE
U ___cxa_begin_catch
U ___cxa_end_catch
U ___cxa_rethrow
U ___gxx_personality_v0
compatibility-debug_list.o:
00000000 T __ZNSt6__norm15_List_node_base4hookEPS0_
00000000 T __ZNSt6__norm15_List_node_base4swapERS0_S1_
00000000 T __ZNSt6__norm15_List_node_base6unhookEv
00000000 T __ZNSt6__norm15_List_node_base7reverseEv
00000000 T __ZNSt6__norm15_List_node_base8transferEPS0_S1_
compatibility-debug_list-2.o:
compatibility-list.o:
00000000 T __ZNSt15_List_node_base4hookEPS_
00000000 T __ZNSt15_List_node_base4swapERS_S0_
00000000 T __ZNSt15_List_node_base6unhookEv
00000000 T __ZNSt15_List_node_base7reverseEv
00000000 T __ZNSt15_List_node_base8transferEPS_S0_
compatibility-list-2.o:
compatibility-c++0x.o:
compatibility-atomic-c++0x.o:
compatibility-thread-c++0x.o:
I'm not sure what I could've done wrong... everything is based on the template set up. In fact, this was built as a docker image so I can show exactly the steps I took to build the toolchain:
# Dockerfile for generating a Fedora image with the full KallistiOS SDK installed so you can compiled
# Dreamcast applications
FROM fedora
MAINTAINER kazade <kazade@gmail.com>
# RUN dnf -y update && dnf clean all
RUN dnf -y install git bzip2 patch gcc texinfo libjpeg-turbo-devel libpng-devel python && dnf clean all
RUN mkdir -p /opt/toolchains/dc
RUN git clone git://git.code.sf.net/p/cadcdev/kallistios /opt/toolchains/dc/kos
RUN git clone --recursive git://git.code.sf.net/p/cadcdev/kos-ports /opt/toolchains/dc/kos-ports
RUN cd /opt/toolchains/dc/kos/utils/dc-chain && sh ./download.sh && sh ./unpack.sh && make
RUN cp /opt/toolchains/dc/kos/doc/environ.sh.sample /opt/toolchains/dc/kos/environ.sh
RUN echo -e "\nsource /opt/toolchains/dc/kos/environ.sh" >> /etc/bash.bashrc
RUN source /etc/bash.bashrc; echo ${KOS_BASE}
RUN source /etc/bash.bashrc; cd /opt/toolchains/dc/kos && make
RUN source /etc/bash.bashrc; cd /opt/toolchains/dc/kos-ports/libGL && make install clean
RUN source /etc/bash.bashrc; cd /opt/toolchains/dc/kos-ports/libjpeg && make install clean
RUN source /etc/bash.bashrc; cd /opt/toolchains/dc/kos-ports/libpng && make install clean
RUN dnf -y install cmake
RUN sed -i 's/-fno-rtti//' /opt/toolchains/dc/kos/environ_base.sh
RUN sed -i 's/-fno-exceptions//' /opt/toolchains/dc/kos/environ_base.sh
RUN sed -i 's/-fno-operator-names//' /opt/toolchains/dc/kos/environ_base.sh
Nothing there stands out as being wrong in any way that would cause that. I mean, you don't need --recursive on the kos-ports git clone, but that's not actually going to cause problems (and certainly not of that kind).
Once when I experienced similar issues using a successfully compiled tool chain, it turned out to be related to the binutils used during compilation. There just seemed to be a discrepancy between what gcc and binutils wanted as far as directory structure goes.
I don't know if this is the issue you have, but it might help to check the preferred version of binutils, even if you might want a newer one. My last tool chain build used binutils-2.23.2.
I also used to compile gcc once for a while without issue but went back to the normal two-stage compile after kos integrated its libc and libstdc++ with gcc. Are you working in this area? I.e. Patching gcc?
No, I'm just building the standard toolchain - but I have come up with a theory! I'm wondering if latest GCC (shipped with latest Fedora) doesn't build the old GCC + stdlib correctly. I tested bumping GCC to 4.8.2 and compilation failed because the newest host GCC doesn't like it (I found a bug report for this but it's only fixed in GCC 5.x not 4.x).
So I've changed the Docker image to source from Fedora 23 rather than latest, and I'm re-compiling 4.7.3 now, and already the output is much cleaner (before there were a *lot* of warnings)
I'll update the thread when I've tested the output.
compatibility.o:
U __Unwind_Resume
00000000 T __ZNSi6ignoreEi
U __ZNSi6ignoreEv
U __ZNSi6sentryC1ERSib
00000000 T __ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEi
U __ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEv
U __ZNSt13basic_istreamIwSt11char_traitsIwEE6sentryC1ERS2_b
00000000 t __ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetcEv.part.1
00000000 t __ZNSt15basic_streambufIwSt11char_traitsIwEE5sgetcEv.part.4
U __ZNSt9basic_iosIcSt11char_traitsIcEE11_M_setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
U __ZNSt9basic_iosIwSt11char_traitsIwEE11_M_setstateESt12_Ios_Iostate
U __ZNSt9basic_iosIwSt11char_traitsIwEE5clearESt12_Ios_Iostate
U __ZTIN10__cxxabiv115__forced_unwindE
U ___cxa_begin_catch
U ___cxa_end_catch
U ___cxa_rethrow
U ___gxx_personality_v0
compatibility-debug_list.o:
00000000 T __ZNSt6__norm15_List_node_base4hookEPS0_
00000000 T __ZNSt6__norm15_List_node_base4swapERS0_S1_
00000000 T __ZNSt6__norm15_List_node_base6unhookEv
00000000 T __ZNSt6__norm15_List_node_base7reverseEv
00000000 T __ZNSt6__norm15_List_node_base8transferEPS0_S1_
compatibility-debug_list-2.o:
compatibility-list.o:
00000000 T __ZNSt15_List_node_base4hookEPS_
00000000 T __ZNSt15_List_node_base4swapERS_S0_
00000000 T __ZNSt15_List_node_base6unhookEv
00000000 T __ZNSt15_List_node_base7reverseEv
00000000 T __ZNSt15_List_node_base8transferEPS_S0_
compatibility-list-2.o:
compatibility-c++0x.o:
compatibility-atomic-c++0x.o:
compatibility-thread-c++0x.o:
Does anyone have any other ideas? I'm running out of options...
It seems you are using CMake instead of the standard make for your project and rewriting the compile flags... Does it matter for your project that you don't have the -nodefaultlibs -nostdlib -nostartfiles flags?
I also just noticed that in the environ_base.sh kos is set to compile (itself?) with -std=gnu++98. Would this be an issue for how you are working?
It's also weird that one of the errors you got mention unknown emulation -4-single-only. Maybe it could help to describe how you are compiling your library?
e.g.
- have a working copy of gcc (kos-patched) from the toolchain that your are modifying
- running dc-chain script using modified gcc
I'm using CMake for my library and application - but that obviously shouldn't affect the build of libstdc++
I don't suppose someone can attach their version of libstdc++.a so I can compare the files? Presumably as they are built with the same toolchain they should be the same (right?).
As a last resort I rolled back the Docker image to Fedora 21 (which ships with GCC 4.9.x) previously I'd tried latest (GCC 6.x) and Fedora 23 (GCC 5.x) It appears there is a bug somewhere when compiling with newer GCC.
I still have a few undefined references but those are my fault or due to incomplete C++11 in 4.7.3 (std::to_string isn't implemented)
I only know that GCC 6 worked for me for C, didn't test C++.
Just a shot in the dark, but perhaps you can disable some newer C++ library features with command line flags? I'd read the changelog