digitalmars.D.learn - Linking C++ standard library works with GDC... but not DMD. (Linux)
- TheGag96 (11/11) Apr 16 2015 Hi, I've got this project that requires me to link into a C++
- FreeSlave (3/15) Apr 16 2015 Can't get to linux machine now, but you can try place -L-lstdc++
- John Colvin (6/18) Apr 16 2015 I don't know why that's happening, but you can explicitly link
- TheGag96 (9/33) Apr 16 2015 I had wanted to try this too, but I wasn't sure if the linker
- Dicebot (6/18) Apr 16 2015 Simple issue but unpleasant fix. You always must use C++ library
- Jacob Carlborg (4/9) Apr 16 2015 The title says (Linux), where DMD uses GCC and not DMC.
- Dicebot (3/14) Apr 17 2015 Does DMD also use GCC conventions on Linux when compiling
- Jacob Carlborg (8/10) Apr 17 2015 Not exactly sure that you mean by "conventions" but "extern(C++)" and
- Steven Schveighoffer (7/17) Apr 16 2015 Try dmd -v to tell you exactly what command it is running for link. Then...
- TheGag96 (6/16) Apr 16 2015 Got it!! This is what helped me the most. I compiled a regular
Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get errors involving the standard library not being added like: /usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.) What do I need to do to make this work? Thanks.
Apr 16 2015
On Thursday, 16 April 2015 at 08:51:15 UTC, TheGag96 wrote:Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get errors involving the standard library not being added like: /usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.) What do I need to do to make this work? Thanks.Can't get to linux machine now, but you can try place -L-lstdc++ after source files.
Apr 16 2015
On Thursday, 16 April 2015 at 08:51:15 UTC, TheGag96 wrote:Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get errors involving the standard library not being added like: /usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.) What do I need to do to make this work? Thanks.I don't know why that's happening, but you can explicitly link using gcc (or ld/gold directly) if you need to. E.g. dmd -c myFile.d gcc myFile.o -lphobos2 or whatever is necessary on your project/system.
Apr 16 2015
On Thursday, 16 April 2015 at 09:46:40 UTC, John Colvin wrote:On Thursday, 16 April 2015 at 08:51:15 UTC, TheGag96 wrote:I had wanted to try this too, but I wasn't sure if the linker knew where phobos2 was on my system. I just tried this now for funsies: dmd -c *.d g++ main.o [client files] -lphobos2 With or without that -lphobos2 flag, I get errors like these: main.d(.text._Dmain+0x18e): undefined reference to `D3std5stdio16__T7writeln(TAyaZ7writeFAyaZv'Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get errors involving the standard library not being added like: /usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.) What do I need to do to make this work? Thanks.I don't know why that's happening, but you can explicitly link using gcc (or ld/gold directly) if you need to. E.g. dmd -c myFile.d gcc myFile.o -lphobos2 or whatever is necessary on your project/system.
Apr 16 2015
On Thursday, 16 April 2015 at 08:51:15 UTC, TheGag96 wrote:Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get errors involving the standard library not being added like: /usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.) What do I need to do to make this work? Thanks.Simple issue but unpleasant fix. You always must use C++ library that matches base C++ compiler. For GDC it is GCC (which is used by default). For DMD it is DMC (Digital Mars C compiler). For LDC it is whatever Clang standard library is called. All those are incompatible because rely on different compiler built-ins.
Apr 16 2015
On 2015-04-16 11:56, Dicebot wrote:Simple issue but unpleasant fix. You always must use C++ library that matches base C++ compiler. For GDC it is GCC (which is used by default). For DMD it is DMC (Digital Mars C compiler). For LDC it is whatever Clang standard library is called. All those are incompatible because rely on different compiler built-ins.The title says (Linux), where DMD uses GCC and not DMC. -- /Jacob Carlborg
Apr 16 2015
On Thursday, 16 April 2015 at 12:39:07 UTC, Jacob Carlborg wrote:On 2015-04-16 11:56, Dicebot wrote:Does DMD also use GCC conventions on Linux when compiling extern(C++) code? I didn't know that.Simple issue but unpleasant fix. You always must use C++ library that matches base C++ compiler. For GDC it is GCC (which is used by default). For DMD it is DMC (Digital Mars C compiler). For LDC it is whatever Clang standard library is called. All those are incompatible because rely on different compiler built-ins.The title says (Linux), where DMD uses GCC and not DMC.
Apr 17 2015
On 2015-04-17 10:16, Dicebot wrote:Does DMD also use GCC conventions on Linux when compiling extern(C++) code? I didn't know that.Not exactly sure that you mean by "conventions" but "extern(C++)" and "extern(C)" follows the ABI of the system compiler. On Linux that is GCC, on OS X it's Clang/GCC, on Windows it's either DMC or VS depending on what object format is used, I guess. DMC is not even available for any other platform than Windows. -- /Jacob Carlborg
Apr 17 2015
On 4/16/15 4:51 AM, TheGag96 wrote:Hi, I've got this project that requires me to link into a C++ backend. It works just fine when using GDC: gdc *.d [client libraries] However, this command using DMD does not work: dmd -L-lstdc++ *.d [client libraries] I still get errors involving the standard library not being added like: /usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.)Try dmd -v to tell you exactly what command it is running for link. Then play around with the link line to see if you can figure out a way to link it correctly. We can work on fixing the situation from there. Maybe there's a way to link using dmd, maybe we have to fix dmd so it allows the correct link call. -Steve
Apr 16 2015
On Thursday, 16 April 2015 at 12:57:12 UTC, Steven Schveighoffer wrote:Got it!! This is what helped me the most. I compiled a regular C++ program with the -v flag, found where my libstdc++.a was, added it to the command and bam. I really should have thought of this one earlier... Thanks for the quick support, everyone!/usr/include/c++/4.8/iostream:74: undefine reference to `std::ios_base::Init::Init()' (etc.)Try dmd -v to tell you exactly what command it is running for link. Then play around with the link line to see if you can figure out a way to link it correctly. We can work on fixing the situation from there. Maybe there's a way to link using dmd, maybe we have to fix dmd so it allows the correct link call. -Steve
Apr 16 2015