www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - linking C library with D, creating a OpenVG D port

reply "ddos" <oggs gmx.at> writes:
hi!

i'm trying to run OpenVG examples in D. So far i have compiled 
ShivaVG (an implementation of OpenVG standard) in C++ and created 
a shared library. Now i'd like to link my OpenVG.lib with a D 
program.
(the library was compiled with msvc2013x86, i'd like to avoid 
switching compiler)

to link the library i added my C++ lib to my dub file,
"libs": ["OpenVG"],
dmd complains:  Error 43: Not a Valid Library File

after some googling i found out i have to convert/create my lib 
file in the appropriate format to be used with dmd, so i used 
implib to create a new lib from my dll. viewing this lib no 
exports are visible with dumpbin, dumpbin /EXPORTS OpenVG_D.lib 
also reports a warning: OpenVG_D.lib : warning LNK4048: Invalid 
format file; ignored
maybe i have to use another tool here to view the exports? but 
dumpbin can view pe and coff, dmd uses coff i think so this 
should work i guess

if i try to compile my application it now tells me about the 
obviously missing export,  Error 42: Symbol Undefined 
_vgCreateContextS
Apr 03 2015
parent reply "ddos" <oggs gmx.at> writes:
progress ... i think
in some forum posts i've read 64bit dmd uses a differnt linker 
which supports coff
atleast i can now link my app in 64bit mode without errors
dmd -m64 source/app.d OpenVG.lib

also an exported test function prints to stdout, so my problem is 
solved for x64 :)

if anyone could explain how this could be done with 32bit builds 
i'd appreciate it
why does dmd use different linkers for 32 and 64bit anyway?
Apr 03 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 4/04/2015 1:00 a.m., ddos wrote:
 progress ... i think
 in some forum posts i've read 64bit dmd uses a differnt linker which
 supports coff
 atleast i can now link my app in 64bit mode without errors
 dmd -m64 source/app.d OpenVG.lib

 also an exported test function prints to stdout, so my problem is solved
 for x64 :)

 if anyone could explain how this could be done with 32bit builds i'd
 appreciate it
 why does dmd use different linkers for 32 and 64bit anyway?
In the beginning, Symantec had their own c/c++ compiler. That compiler was made by a humble but brilliant developer called Walter Bright. At the time the Microsoft toolchain was horribly incompatible between versions. In fact it was so bad, that a linker was made specifically for it. At the time OMF was the standard binary format for Windows. Not long after PE-COFF was transitioned to for Windows 95. Not long after this, Symantec dropped their toolchain and that clever developer negotiated the rights to it and in the process created a little company. Furthering this, that clever developer didn't enjoy c++ not nearly as much as what others think of it. Instead choose to create a new language using the existing toolchain. Fast forward about 12 years. The compiler still used that old linker but only for 32bit on Windows. But now the need was strong for 64bit support. After successful addition of 64bit support of *nix, Windows was worked on. Now nobody wanted to add 64bit support to that old old linker as it was written in an arcane dialect of assembly. Almost nobody understood it. So the clever people, implemented it using the standard toolchain on the Windows platform. Instead of their own custom one. However it used PE-COFF for binary format. Unfortunately the need was not great to add it also for 32bit. Causing a great divide. That divide has since been resolved and will be forgotten about after one more major release. Disclaimer: not 100% accurate, bunch of stuff I missed out. But more or less accurate timeline.
Apr 03 2015
parent "ddos" <oggs gmx.at> writes:
thanks Rikki!

also if anyone is interested in OpenVG i have now a running demo 
in D based on ShivaVG and derelict GLFW3, it's not beautiful but 
it works :D

http://imgur.com/ZH0kD0q

i'm pretty impressed how painless the compiling and interfacing 
to C was actually :) +1 for D
Apr 03 2015