2

I am trying to call a c++ function from a D module. I have followed the guide on this page http://dlang.org/spec/cpp_interface.html but I am unable to get it to work.

I have created a solution in visual studio 2015 with two projects in it, one is the D project and the other is C++ project. I build the C++ project and generate a .lib file. Then in the D project I have set the path to the lib file in Configuration Properties -> Linker -> General -> Library Files but when I run the solution I get Error43: Not a Valid Library File.

Thanks in advance

1 Answers1

2

Problem is that your library contains COFF object files, but DMD expects them to be in the OMF format. (Take a look at "Can I link in C object files created with another compiler?" @ https://dlang.org/faq.html)

What you have to do is to convert the library to OMF for use with DMD using, say, coff2omf tool. This tool is part of the DigitalMars extension package (check the freecompiler download section) Or, if you can, use some C++ compiler, like DigitalMars C/C++ compiler, to generate an OMF library.

Also, take a look at: Converting COFF lib file to OMF format

Community
  • 1
  • 1
DejanLekic
  • 18,787
  • 4
  • 46
  • 77
  • do you have a link to the tool? i cant seem to find a way to download it anywhere – Govardhan Gosavi Jan 20 '16 at 12:51
  • dmd for win32 can output coff since several monthes now (switch __-ms32coff__), which you can do instead of converting. Another option is to make a dynamic library in c++. – Abstract type Jan 21 '16 at 16:47