digitalmars.D.learn - Linking g++ compiled object files
- Rubikoid (15/15) Nov 23 2016 For example, i have test.cpp:
- Basile B. (16/31) Nov 24 2016 * Under linux:
- Rubikoid (3/11) Nov 24 2016 My mistake, already understood;)
- Mike Parker (8/9) Nov 24 2016 DMD can work with COFF objects when given -m32mscoff when
For example, i have test.cpp: #include <stdio.h> void test() { printf("test\n"); } And test.d: import std.stdio; extern (C++) void test(); void main() { test(); readln(); } How i should compile test.cpp using g++ to link it normally?
Nov 23 2016
On Wednesday, 23 November 2016 at 19:49:35 UTC, Rubikoid wrote:For example, i have test.cpp: #include <stdio.h> void test() { printf("test\n"); } And test.d: import std.stdio; extern (C++) void test(); void main() { test(); readln(); } How i should compile test.cpp using g++ to link it normally?* Under linux: - create the object g++ -c test.cpp - link: dmd test.d test.o * Under windows 32 bit: - create the object: Use digital mars C/C++ (dmc) to create an OMF object (GCC would produce COFF) then - link: dmd test.d test.obj Note that in both cases it can be better not to use the same name for the cpp object. With more C++ objects you could create an archive (aka static library) but for just one source this is useless.
Nov 24 2016
On Thursday, 24 November 2016 at 17:37:51 UTC, Basile B. wrote:* Under windows 32 bit: - create the object: Use digital mars C/C++ (dmc) to create an OMF object (GCC would produce COFF) then - link: dmd test.d test.objSo, is there any way to use gcc/g++ under windows?Note that in both cases it can be better not to use the same name for the cpp object.My mistake, already understood;)
Nov 24 2016
On Thursday, 24 November 2016 at 20:09:29 UTC, Rubikoid wrote:So, is there any way to use gcc/g++ under windows?DMD can work with COFF objects when given -m32mscoff when compiling 32-bit and -m64 for 64-bit. In both cases, yoi will need the Microsoft linker and SDK intalled. However, when linking with GCC-compiled objects from MinGW or Cygwin, any use of the C standard library in those objects is bound to cause linker errors. With C++, there's also the issue of name mangling. I don't know if GCC's and Microsoft's are compatible.
Nov 24 2016