Jump to content
alank2

Is there a way to use a platform specific win32/win64 DEF file?

Recommended Posts

I have a project that builds a DLL and I have two different .DEF files (one for WIN32, and for WIN64).  I want to avoid making two projects and so I've been removing/adding the correct .DEF file before I build that platform, is there a better way?

Share this post


Link to post

you can try use "Compiler Directives":

Quote

{$IFDEF WIN32}

   // ...  load DLL win32

{$ELSE WIN64}

   // ... load DLL win64

{$ENDIF}

you can create yourself directive too:

Quote

{$DEFINE MyDirectiveX}

//

{$IFDEF MyDirectiveX}

    //...

{$ENDIF}

 

Edited by programmerdelphi2k

Share this post


Link to post

no, no, no! YOUR CODE can, then, just "use the directives" to separate "Win32/Win64" coding...

you use "Project Options" too to choice how all works... including use "Build Events" to determiante what actions your project needs before/after/on pre-linking...

Share this post


Link to post
15 hours ago, alank2 said:

I have a project that builds a DLL and I have two different .DEF files (one for WIN32, and for WIN64).  I want to avoid making two projects and so I've been removing/adding the correct .DEF file before I build that platform, is there a better way?

DEF files are a C/C++ thing, no? Delphi definitely does not need them.

Share this post


Link to post
18 hours ago, alank2 said:

I have two different .DEF files (one for WIN32, and for WIN64).

Why?  What exactly is different between them?  For that matter, why are you using .DEF files in Delphi at all?  That should not be necessary.

18 hours ago, alank2 said:

I want to avoid making two projects

You need to use separate projects if you need to include a different set of files.

18 hours ago, alank2 said:

I've been removing/adding the correct .DEF file before I build that platform, is there a better way?

Not really, except maybe making/finding a preprocessor for .DEF files, or using the project's Build Events to automate the swapping of the .DEF file.

Share this post


Link to post
16 hours ago, programmerdelphi2k said:

no, no, no! YOUR CODE can, then, just "use the directives" to separate "Win32/Win64" coding...

you use "Project Options" too to choice how all works... including use "Build Events" to determiante what actions your project needs before/after/on pre-linking...

Not in a def file, perhaps you aren't familiar with def files. They are used to specify exported functions, typically at the link phase in C and C++ tool chains.

 

See: Module-Definition (.Def) Files | Microsoft Learn

Share this post


Link to post

hi @David Heffernan

ok, if dont... then it cannot!

 

question:  ...and into def files it's not possible define any directive (like in Delphi) to compile 32 or 64bit code?

(please dont be cruel with me  :classic_biggrin:😅

 ☺️

Edited by programmerdelphi2k

Share this post


Link to post
2 hours ago, programmerdelphi2k said:

question:  ...and into def files it's not possible define any directive (like in Delphi) to compile 32 or 64bit code?

Delphi doesn't use .DEF files to begin with.  But even if it did, .DEF files are simply not preprocessed files, so they cannot have directives to generate different code for different compilation setups. To do what you are asking, the project setup must use a separate .DEF file for each platform.

Edited by Remy Lebeau

Share this post


Link to post

Everyone, maybe I should have specified C++Builder.  The DEF files are for compiling two different versions, 32-bit and 64-bit DLL's.

 

32-bit version top two lines:

 

EXPORTS
  CCfgClassNew=_CCfgClassNew

 

64-bit version top two lines:

EXPORTS
  CCfgClassNew=CCfgClassNew

 

The 64-bit lacks the underscore, my goal here being to produce a DLL that uses the same name for the function no matter whether it is 32-bit or 64-bit.  I want to access it as CCfgClassNew either way.

 

Maybe there is no way to do this in a DEF file and I have to do different projects.

Share this post


Link to post
2 hours ago, David Heffernan said:

Doesn't

EXPORTS
  CCfgClassNew

work?

No, it comes up with an error:

[ilink32 Warning] Warning: Attempt to export non-public symbol 'CCfgClassNew'

The problem is that 32-bit mangles the name with an underscore and 64-bit does not, which is why I am using the DEF file to unmangle the 32-bit version of the DLL so it and the 64-bit version have consistent names.

 

ALSO, one more odd thing.  if the DEF file changes in any way, this error is produced when trying to build:

[ilink32 Error] Invalid command line switch for "ilink32". Parameter "ItemSpec" cannot be null.

 

The way to fix it is to remove the DEF file and add the DEF file back again, then it will build without the error.

 

Share this post


Link to post
6 hours ago, alank2 said:

Everyone, maybe I should have specified C++Builder.

Then why did you post this in a Delphi forum?  There is a separate forum for C++Builder:

https://en.delphipraxis.net/forum/41-general-help/

6 hours ago, alank2 said:

The DEF files are for compiling two different versions, 32-bit and 64-bit DLL's.

Even in C++, what I stated earlier still applies.  .DEF files are not pre-processed, so unless you preprocess the file yourself, you will need to use separate .DEF files for 32bit and 64bit compilations.

Share this post


Link to post

Sorry Remy; I saw the "General Help", but didn't look at its parent folder.  I appreciate the help.

Share this post


Link to post

I'll bet that there is a clean solution to your problem, but not the one you are trying. Instead of asking about pre-processing DEF files, why not ask about the root problem, rather than the solution you imagine using, which you now know is not possible.

Share this post


Link to post

To make sure we understand what you are trying to do. You are trying to use the DEF file to specify to the linker which functions to export (and the names of the functions you want them exported as).   <can you confirm this, please?>

Can you confirm that you are using the clang32 compiler for your 32bit code  (if not then first thing to try is to use the clang32 compiler - maybe it's name mangling will be the same as the clang64 (I haven't checked this)).

I am wondering if another approach might work (as suggested by @David Heffernan)

Share this post


Link to post
6 hours ago, Roger Cigol said:

To make sure we understand what you are trying to do. You are trying to use the DEF file to specify to the linker which functions to export (and the names of the functions you want them exported as).   <can you confirm this, please?>

Yes, that is exactly what I am trying to do.

 

>Can you confirm that you are using the clang32 compiler for your 32bit code  (if not then first thing to try is to use the clang32 compiler - maybe it's name mangling will be the same as the clang64 (I haven't checked this)).

 

I am using the classic compiler, I just have more experience with it so I stick with it.  I would think the clang compiler would still mangle/underscore the names for 32-bit code.

 

Share this post


Link to post

All C++ compilers (to my (limited) knowledge) mangle names (because it's the obvious way to track arguments and return values). But it is possible (perhaps even "likely") that clang32 and clang64 adopt the SAME mangling scheme. If this was the case, your need for a separate def file for each compiler would disappear.

Share this post


Link to post
5 hours ago, David Heffernan said:

What about for your 64 bit compilation?

Embarcadero provides only one 64-bit compiler for Windows (unlike three 32-bit compilers for Windows), and it is clang-based.

Edited by Remy Lebeau

Share this post


Link to post
4 hours ago, alank2 said:

Three?

Yup. https://docwiki.embarcadero.com/RADStudio/en/C%2B%2B_Compilers

4 hours ago, alank2 said:

clang

classic

 

What else?

There is 1 classic compiler (bcc32) and 2 separate clang compiler front-ends (bcc32c and bcc32x):

Quote

BCC32C is a Clang-enhanced compiler with a command line flag compatible only with BCC32 (the classic compiler), whereas BCC32X has a command line flag compatible with other C++ Clang-enhanced compilers: BCC64, BCCIOSARM, BCCIOSARM64, and BCCAARM.

 

Apart from the command-line flags they accept, bcc32c and bcc32x are identical. The two front-ends exist for different command-line compatibility, classic (bcc32c with bcc32) and current (bcc32x with other Clang-enhanced compilers).

 

Share this post


Link to post

Interesting - I was reading the differences page and this came up:

 

Clang-enhanced C++ compilers do not allow the use of sizeof in a preprocessor directive, such as #if sizeof(ATypeName) > 20.

 

How can one then test for sizes if this is not an option - is there a workaround/alternative method?

Edited by alank2

Share this post


Link to post

You can use if (sizeof(ATypeName) > 20) { /*.... your code here ...*/ }   in your code (ie it's just the preprocessor #if form that is not handled)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×