5
votes

I'm completely stumped on how to get FreeType 2.4.8 compiled as a static lib and usable from within my D application in Windows. I've tried running it over with objconv, coff2omf, and trying extern(C)/extern(System), etc. but nothing seems to work. I'm getting symbol not found errors, access violations and just a bunch of unhelpful errors.

How can I work around this? Am I correct in using pragma lib to link to my static libraries, and how do I reliably convert COFF static libs to OMF which DMD/Optlink can use?

EDIT: Some examples of what I've tried doing:

  1. Compiling the FreeType source with VS 2010 as a static lib, linking in my D code with pragma lib. (Returned a "library format unknown" type error)
  2. Same as above, but converting to OMF format using objconv and then trying to link with pragma lib. (Linked successfully, but still not able to call functions.)
  3. Compiled a DLL of the FreeType source, ran it through implib to create an import library, tried linking with pragma lib. (Linked successfully, but unable to to call any functions due to "attempt to privileged function" or "access violation" errors)
  4. I've tried defining function prototypes as all of: extern(System), extern(C), and extern(Windows). The first and third mangle the functions names of the extern-ed functions such that they don't match the static libraries, and the second compiles, but I get access violations during runtime when I actually try and call the functions.

I'm able to get it working via dynamic libraries and symbol loading, but I'd much prefer to not require a bunch of external dependencies when deploying my project.

2
Can you show us a minimal example of what you've tried? e.g. one function prototype declared with example program demonstrating the errors you are getting. Also, if you show us what you have tried with the static lib (attempts to convert it from COFF to OMF) then that would help too. - Peter Alexander
Certainly, let me whip some examples up. - Mark LeMoine
Static libs on Windows can be a PITA. Easiest approach is to always use dynamic libraries + implib. Does the created dll work if you use it from C++? If yes, can you show your C++ and D code? Note that extern(System) means extern(Windows) on Windows and extern(C) on Linux. - Trass3r
If you build a static FreeType library, you simply just add it to the list of your SOURCE files. Example: dmd file1.d file2.d C:/dev/proj/freetype.lib - DejanLekic
@DejanLekic: Good luck with that. The GDC binary requires "libcloog-0.dll", which is nowhere to be found in the 4.5.2 TDM bundle installer. Not to mention that half the links to individual packages on the TDM page are dead. - Andrej Mitrović

2 Answers

1
votes

I'm pretty sure Derelict2 has FreeType bindings: http://www.dsource.org/projects/derelict (See DerelictFT).

-1
votes

Yes, you will need extern(System) in your .d files with FT function declarations. Static library a collection of object files. So no need for any kind of conversion (omf2coff, etc). DMD accepts a static libraries as arguments, so simple dmd file1.d file2.d C:/path/to/freetype.lib should work.

Edit:

I was wrong. Apparently I needed to read some documentation about the COFF2OMF. Quote: The Microsoft COFF format apparently changed with Visual C++ 6.0. To use coff2omf on a .lib file with the newer format, use Microsoft's linker to convert the file to the earlier COFF format:

link /lib /convert freetype.lib

So, judging by the statement above you need to perform 2 steps.

  1. First use the Microsoft's linker to convert static library you made with the VisualStudio (in COFF format) to the old COFF format as described above.

  2. Now execute coff2omf freetype.lib to convert the static library into the OMF format.

  3. It should now be ready to be used with the DMD the way described originally in my post.