1

I found very needed for my binding to lib named GDAL. https://github.com/craig-dillabaugh/gdal

The problem that there is no examples of it's usage. Before I have never used any bindings.

dub.json include next string: "libs" : ["gdal"]

So it seems that it need lib file with this name.

In the old commits I found example of compilation without dub: dmd test_gdal_d.d gdal.d -L-ldgal

Original gdal distrib do not include lib with such name. There is only gdal111.dll lib. So I converted it with implib to gdal111.lib. With command implib /s gdal111.lib gdal111.dll

From 11MB lib become 1MB of size.

With Dependency Walker I looked it table of symbols. It's have symbols like GDALGetRasterXSize I am trying to build all with next command:

dmd D:\code\binding\gdal-master\gdal-master\source\App.d D:\code\binding\gdal-master\gdal-master\source\gdal.d -L -Igdal111.lib

but I am getting next error:

D:\code\binding\gdal-master\gdal-master>dmd D:\code\binding\gdal-master\gdal-master\source\App.d D:\code\binding\gdal-master\gdal-master\source\gdal.d -L -Igdal111.lib OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html App.obj(App) Error 42: Symbol Undefined _GDALClose App.obj(App) Error 42: Symbol Undefined _GDALGetRasterCount App.obj(App) Error 42: Symbol Undefined _GDALGetRasterXSize App.obj(App) Error 42: Symbol Undefined _GDALGetRasterYSize App.obj(App) Error 42: Symbol Undefined _GDALOpen App.obj(App) Error 42: Symbol Undefined _GDALAllRegister App.obj(App) Error 42: Symbol Undefined _GDALIdentifyDriver App.obj(App) Error 42: Symbol Undefined _GDALCreate --- errorlevel 8

I put archive with all stuff here http://dlang.ru/gdal-d-binding.zip

UPD: I got GDAL run!!!

I gist add string: pragma( lib, "libgdal.lib" ); at example, and it's run. Soon I hope to push some code to github.

Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
  • Try to generate the __*.di__ interface with [*implib*](http://www.digitalmars.com/ctg/implib.html). It's also possible that the example was made for the static library file (__*.lib__). – Abstract type Apr 09 '15 at 15:15
  • implib will make the .lib, not the .di. But these errors are about a missing .lib so it is what you should try. implib can be downloaded here http://ftp.digitalmars.com/bup.zip and you just run it on the dll. probably `implib /s ldgal.lib ldgal.dll` – Adam D. Ruppe Apr 09 '15 at 15:18
  • I tried. But without result... – Dmitry Bubnenkov Apr 09 '15 at 18:14
  • Nothing happened or did you still get the same error? Be sure you pass the generated .lib file to the compiler too when building. – Adam D. Ruppe Apr 10 '15 at 03:42
  • I am trying to compile it with next command: ``dmd D:\code\binding\gdal-master\gdal-master\source\App.d D:\code\binding\gdal-master\gdal-master\source\gdal.d -L -Ilibgdal.lib`` The error is same. But I am not sure that command is correct. Lib name is libgdal. And I linking with it with -L -Ilibgdal.lib – Dmitry Bubnenkov Apr 10 '15 at 06:42
  • The -I is wrong. Just add the `libgdal.lib` to the end of the command with no esxtra stuff around it. Like: `dmd path\to\App.d path\to\gdal.d libgdal.lib` – Adam D. Ruppe Apr 10 '15 at 13:06

1 Answers1

2

writing up the solution we got together from the comments here:

First, you need to make the lib file. implib can be downloaded here ftp.digitalmars.com/bup.zip and you just run it on the dll, implib /s ldgal.lib ldgal.dll to generate the import library.

Once that is made, you need to add it to the build. There's two ways to do that: add ldgal.lib to the end of the command line to dmd (without any other switches, just add the file, dmd will see that it is a .lib and do the right thing) or add pragma(lib, "ldgal"); to your main source file.

Adam D. Ruppe
  • 25,382
  • 4
  • 41
  • 60