Thread overview
Problems with static linking of c libraries
Jul 14, 2011
Danny Arends
Jul 14, 2011
Loopback
Jul 14, 2011
Danny Arends
Jul 14, 2011
Loopback
Jul 15, 2011
Mike Parker
Jul 14, 2011
Trass3r
July 14, 2011
Hey all,

I'm trying to build a D application which statically links in the the blas and lapack libraries (from http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html ). When downloading the pre-build libraries from the website I link them in using:

pragma(lib, "blas");
pragma(lib, "lapack");

Compiling isn't a problem but then optlink complains:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
blas.lib
 Error 43: Not a Valid Library File

First I thought this was due to the fact that I was running on windows 2008 (32 bit version) but I also tried on windows XP professional, with the same result...

I decided to build the libraries myself using Cmake and VisualStudio 2010, this however also has the same result:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
blas.lib
 Error 43: Not a Valid Library File

I am able to build the packages using the MinGW toolchain (using GNU C/CPP) however I then end up with
libblas.a and liblapack.a files, which causes the linker to not find the libraries (under windows it searches for
the .lib extension). renaming them leads again to the msg seen above (Not a Valid Library)

Any help on how to statically link these 2 packages in my executable using windows ?

Kind regards,
Danny
July 14, 2011
You need to convert the libraries to OMF format from COFF.
These are some tools which can do this:

Coffimplib: http://www.digitalmars.com/ctg/coffimplib.html
Coff2OMF: http://www.digitalmars.com/ctg/coff2omf.html
ObjConv: http://www.agner.org/optimize/objconv.zip
July 14, 2011
Wow THANX,
Using the COFF2OMF tool at least got me a step further, now it finds and accepts the lib files,
however, it now fails with the following error:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
lapack.lib(lapack)  Offset B24AEH Record Type 009D
 Error 16: Index Range
--- errorlevel 1

Any suggestions, on how to fix this error ?
July 14, 2011
On 2011-07-14 17:06, Danny Arends wrote:
> Wow THANX,
> Using the COFF2OMF tool at least got me a step further, now it finds and accepts the lib files,
> however, it now fails with the following error:
>
> OPTLINK (R) for Win32  Release 8.00.12
> Copyright (C) Digital Mars 1989-2010  All rights reserved.
> http://www.digitalmars.com/ctg/optlink.html
> lapack.lib(lapack)  Offset B24AEH Record Type 009D
>   Error 16: Index Range
> --- errorlevel 1
>
> Any suggestions, on how to fix this error ?

My own success have varied depending on which tool that I have used.
COFF2OMF seems to be the one most appropriate with old libraries (such
as VC++ 6.0 and earlier). Coffimplib only works with a few libraries,
(in my own experience) and I have had least success with this tool,
whilst objconv works in most cases. I would recommended to try them
all and see which one that works best for you. If none of them works,
try to use them on different compiled libraries (the one's on the
website and the one's that you have compiled locally etc..).
July 14, 2011
Am 14.07.2011, 16:36 Uhr, schrieb Danny Arends <Danny.Arends@gmail.com>:

> Hey all,
>
> I'm trying to build a D application which statically links in the the blas and lapack libraries
> (from http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html ). When downloading the
> pre-build libraries from the website I link them in using:

You save yourself a lot of hassle if you just stick with dlls on Windoze.
Converting prebuilt libs has never really worked for me.
And compiling them with dmc is a nightmare.

But creating an import library from a dll with implib worked really well so far no matter how the code was compiled.
July 15, 2011
On 7/15/2011 12:12 AM, Loopback wrote:
> On 2011-07-14 17:06, Danny Arends wrote:
>> Wow THANX,
>> Using the COFF2OMF tool at least got me a step further, now it finds
>> and accepts the lib files,
>> however, it now fails with the following error:
>>
>> OPTLINK (R) for Win32 Release 8.00.12
>> Copyright (C) Digital Mars 1989-2010 All rights reserved.
>> http://www.digitalmars.com/ctg/optlink.html
>> lapack.lib(lapack) Offset B24AEH Record Type 009D
>> Error 16: Index Range
>> --- errorlevel 1
>>
>> Any suggestions, on how to fix this error ?
>
> My own success have varied depending on which tool that I have used.
> COFF2OMF seems to be the one most appropriate with old libraries (such
> as VC++ 6.0 and earlier). Coffimplib only works with a few libraries,
> (in my own experience) and I have had least success with this tool,
> whilst objconv works in most cases. I would recommended to try them
> all and see which one that works best for you. If none of them works,
> try to use them on different compiled libraries (the one's on the
> website and the one's that you have compiled locally etc..).

You could also try to compile the C source with DMC. Then it will be in the right format to use directly with OPTLINK.