Is possible to link with a DEF file?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Julcar
Posts: 98
Joined: Oct 19, 2010 18:52
Contact:

Is possible to link with a DEF file?

Postby Julcar » May 16, 2021 3:23

Hello,

I've just compiled mBedTLS using TCC compiler, and it generated a DEF file with the library definitions.

Ok, I am in the work of translate the C prototypes of mBedTLS functions into FB's syntax, but I wonder if when compiling, I would be able to use that DEF file with the linker. AFAIK, the binutils LD only accepts .a files, but maybe I'm wrong.

If not the case, how could I generate a .a file from the DEF file generated by TCC?

Thanks.
caseih
Posts: 1705
Joined: Feb 26, 2007 5:32

Re: Is possible to link with a DEF file?

Postby caseih » May 16, 2021 3:52

Usually a .DEF file is just a file that described to the linker how to link with a DLL. It does not contain the library itself. I'm not sure the GCC linker system that FB actually uses DEF files. Usually you link against the .dll directly.
Julcar
Posts: 98
Joined: Oct 19, 2010 18:52
Contact:

Re: Is possible to link with a DEF file?

Postby Julcar » May 16, 2021 4:19

Of course, the ld links against the dll file, but even for winapi dlls in FB's lib folder there are a lot of .dll.a files, but according to https://sourceware.org/binutils/docs/ld/WIN32.html ld.exe looks for the library files in the following order:

libxxx.dll.a
xxx.dll.a
libxxx.a
xxx.lib
libxxx.lib
cygxxx.dll (*)
libxxx.dll
xxx.dll

so, theorically I would match the last case.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Is possible to link with a DEF file?

Postby Cretin Ho » May 16, 2021 7:34

You could create a .a import library (not to be confused with static library, also .a extension) directly from the dll itself or from .def file. I don't remember the details as I left Windows too long but MinGW does have the tools needed to do so. Normally, you should link with the .a import library if the dll is not compiled by MinGW (e.g: it's compiled by MSVC).
Vortex
Posts: 48
Joined: Sep 19, 2005 9:50

Re: Is possible to link with a DEF file?

Postby Vortex » May 16, 2021 8:27

Hi Julcar,

The FreeBASIC installation provides the The DLL Import Library Tool. It can create import libraries from module definition files :

Code: Select all

dlltool --dllname foo.dll --def foo.def --output-lib libfoo.a


For example, creating a decorated import library for kernel32.dll :

Code: Select all

\FreeBASIC\bin\win32\dlltool.exe --dllname kernel32.dll --def kernel32.def --output-lib libkernel32.dll.a -k


The module definition file :

Code: Select all

LIBRARY kernel32
EXPORTS
AcquireSRWLockExclusive@4
AcquireSRWLockShared@4
ActivateActCtx@8
AddAtomA@4
AddAtomW@4
AddConsoleAliasA@12
AddConsoleAliasW@12
.
.


About symbol decoration \ name mangling :

https://en.wikipedia.org/wiki/Name_mangling
marcov
Posts: 3143
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Is possible to link with a DEF file?

Postby marcov » May 16, 2021 8:36

caseih wrote:Usually a .DEF file is just a file that described to the linker how to link with a DLL. It does not contain the library itself. I'm not sure the GCC linker system that FB actually uses DEF files. Usually you link against the .dll directly.


(It did in the past, when I started with Open Source on Windows in late nineties, it iirc did)
Vortex
Posts: 48
Joined: Sep 19, 2005 9:50

Re: Is possible to link with a DEF file?

Postby Vortex » May 16, 2021 15:42

GoLink, the linker of Go Tools can process object files without the need of module definition files and import libraries. The problem is that there is no option to specify static libraries so FreeBASIC's run-time library cannot be supported by GoLink.

Go Tools :

http://www.godevtool.com/

A simple FreeBASIC example :

Code: Select all

#include "windows.bi"
#include "crt.bi"

#ifdef __FB_64BIT__

    #define CallConvention

#else

    #define CallConvention Cdecl

#endif


Sub wmain CallConvention Alias "wmain" ()

Dim As Integer i

For i=1 To 3

   printf !"This is a test.\n"

Next i

   ExitProcess(0)

End Sub


Building the executables :

Code: Select all

\FreeBASIC\fbc -nodeflibs -c Sample.bas -o Sample.obj

\FreeBASIC\fbc -arch 64 -nodeflibs -c Sample.bas -o Sample64.obj

GoLink /entry:_wmain /console /mix Sample.obj kernel32.dll msvcrt.dll

GoLink /entry:wmain /console Sample64.obj kernel32.dll msvcrt.dll
caseih
Posts: 1705
Joined: Feb 26, 2007 5:32

Re: Is possible to link with a DEF file?

Postby caseih » May 16, 2021 16:50

Julcar wrote:Of course, the ld links against the dll file, but even for winapi dlls in FB's lib folder there are a lot of .dll.a files, but according to https://sourceware.org/binutils/docs/ld/WIN32.html ld.exe looks for the library files in the following order:

libxxx.dll.a
xxx.dll.a
libxxx.a
xxx.lib
libxxx.lib
cygxxx.dll (*)
libxxx.dll
xxx.dll

so, theorically I would match the last case.

Okay sure. Not sure what your question is.
Julcar wrote:AFAIK, the binutils LD only accepts .a files, but maybe I'm wrong.

This is obviously incorrect.
If not the case, how could I generate a .a file from the DEF file generated by TCC?[/quote

I don't believe you can.
Julcar
Posts: 98
Joined: Oct 19, 2010 18:52
Contact:

Re: Is possible to link with a DEF file?

Postby Julcar » May 16, 2021 18:05

I started this thread without knowing a lot of things now I got to know, many thanks to everyone
D.J.Peters
Posts: 8298
Joined: May 28, 2005 3:28
Contact:

Re: Is possible to link with a DEF file?

Postby D.J.Peters » May 16, 2021 21:29

FreeBASIC can use "optional" import libs "libXXX.dll.a" to link an exe with a dynamic library "xxx.dll"
The tiny c compiler TCC used simple *.def files instead !

Joshy

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 5 guests