www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can a lib file converted to 1 ob file?

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

My understanding is, a lib file is a collection of multiple obj 
files.

 From a delphi app I want to call D coding without using a dll. 
Delphi does not know the concept of lib files but can link obj 
files.

Linking all single obj files of DRuntime, phobos and my library 
might be possible but I wonder whether there is a better way.

Therefore the question, if I have a d lib file which contains all 
the obj files of DRuntime, phobos and my custom code, is it 
possible to convert it to exactly 1 obj file?

Or must 1 obj file correspond to exactly 1 d module?

Kind regards
Andre
Apr 19 2020
parent reply Basile B. <b2.temp gmx.com> writes:
On Sunday, 19 April 2020 at 07:50:13 UTC, Andre Pany wrote:
 Hi,

 My understanding is, a lib file is a collection of multiple obj 
 files.
This is exact.
 From a delphi app I want to call D coding without using a dll. 
 Delphi does not know the concept of lib files but can link obj 
 files.

 Linking all single obj files of DRuntime, phobos and my library 
 might be possible but I wonder whether there is a better way.

 Therefore the question, if I have a d lib file which contains 
 all the obj files of DRuntime, phobos and my custom code, is it 
 possible to convert it to exactly 1 obj file?

 Or must 1 obj file correspond to exactly 1 d module?

 Kind regards
 Andre
This should work if you pass the static library files to the linker. It is exactly its job to select what's used from the archive. So you would have to pass your stuff and optionally phobos2 as a static library (but this would also work if linking against phobos2.dll)
Apr 19 2020
parent reply Basile B. <b2.temp gmx.com> writes:
On Sunday, 19 April 2020 at 10:48:04 UTC, Basile B. wrote:
 This should work if you pass the static library files to the 
 linker. It is exactly its job to select what's used from the 
 archive. So you would have to pass your stuff and optionally 
 phobos2 as a static library (but this would also work if 
 linking against phobos2.dll)
BTW I have an example here [1], but it's for FreePascal and under linux, and in the end i've decided to use dynamic library (but with static linking) [2] [1] https://gitlab.com/basile.b/link-with-d [2] https://gitlab.com/basile.b/dexed/-/merge_requests/6
Apr 19 2020
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Sunday, 19 April 2020 at 10:53:09 UTC, Basile B. wrote:
 On Sunday, 19 April 2020 at 10:48:04 UTC, Basile B. wrote:
 This should work if you pass the static library files to the 
 linker. It is exactly its job to select what's used from the 
 archive. So you would have to pass your stuff and optionally 
 phobos2 as a static library (but this would also work if 
 linking against phobos2.dll)
BTW I have an example here [1], but it's for FreePascal and under linux, and in the end i've decided to use dynamic library (but with static linking) [2] [1] https://gitlab.com/basile.b/link-with-d [2] https://gitlab.com/basile.b/dexed/-/merge_requests/6
The only thing I found so far is, Delphi does not support linking .lib files. (Mac os 64 bit compiler though seems to support it). I understand from you, that FreePascal is able to link .lib files. Was my impression false and I can link .lib files with Delphi? Kind regards Andre
Apr 19 2020
parent Basile B. <b2.temp gmx.com> writes:
On Sunday, 19 April 2020 at 11:33:15 UTC, Andre Pany wrote:
 On Sunday, 19 April 2020 at 10:53:09 UTC, Basile B. wrote:
 On Sunday, 19 April 2020 at 10:48:04 UTC, Basile B. wrote:
 This should work if you pass the static library files to the 
 linker. It is exactly its job to select what's used from the 
 archive. So you would have to pass your stuff and optionally 
 phobos2 as a static library (but this would also work if 
 linking against phobos2.dll)
BTW I have an example here [1], but it's for FreePascal and under linux, and in the end i've decided to use dynamic library (but with static linking) [2] [1] https://gitlab.com/basile.b/link-with-d [2] https://gitlab.com/basile.b/dexed/-/merge_requests/6
The only thing I found so far is, Delphi does not support linking .lib files. (Mac os 64 bit compiler though seems to support it). I understand from you, that FreePascal is able to link .lib files. Was my impression false and I can link .lib files with Delphi?
No (sorry for the false hope) I also find this (‑‑linker-option for iOS only). Very surprising. Looks like you would have to use a dll. Note that with static linking of the dll cdecl; external 'mydll'; You don't have to use a loader.
Apr 19 2020