Is possible to link with a DEF file?
Is possible to link with a DEF file?
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.
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.
Re: Is possible to link with a DEF file?
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.
Re: Is possible to link with a DEF file?
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.
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.
Re: Is possible to link with a DEF file?
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).
Re: Is possible to link with a DEF file?
Hi Julcar,
The FreeBASIC installation provides the The DLL Import Library Tool. It can create import libraries from module definition files :
For example, creating a decorated import library for kernel32.dll :
The module definition file :
About symbol decoration \ name mangling :
https://en.wikipedia.org/wiki/Name_mangling
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
Code: Select all
\FreeBASIC\bin\win32\dlltool.exe --dllname kernel32.dll --def kernel32.def --output-lib libkernel32.dll.a -k
Code: Select all
LIBRARY kernel32
EXPORTS
AcquireSRWLockExclusive@4
AcquireSRWLockShared@4
ActivateActCtx@8
AddAtomA@4
AddAtomW@4
AddConsoleAliasA@12
AddConsoleAliasW@12
.
.
https://en.wikipedia.org/wiki/Name_mangling
Re: Is possible to link with a DEF file?
(It did in the past, when I started with Open Source on Windows in late nineties, it iirc did)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.
Re: Is possible to link with a DEF file?
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 :
Building the executables :
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
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
Re: Is possible to link with a DEF file?
Okay sure. Not sure what your question is.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.
This is obviously incorrect.Julcar wrote:AFAIK, the binutils LD only accepts .a files, but maybe I'm wrong.
I don't believe you can.If not the case, how could I generate a .a file from the DEF file generated by TCC?[/quote
Re: Is possible to link with a DEF file?
I started this thread without knowing a lot of things now I got to know, many thanks to everyone
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Is possible to link with a DEF file?
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
The tiny c compiler TCC used simple *.def files instead !
Joshy