Skip to content

Export C++ symbols in dynamic Windows libraries #140

@ischoegl

Description

@ischoegl

Abstract

At the moment, symbols in dynamic libraries are not exported in Windows, i.e.

> dumpbin /exports cantera_shared.dll
Microsoft (R) COFF/PE Dumper Version 14.31.31104.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file cantera_shared.dll

File Type: DLL

  Summary

        1000 .00cfg
       19000 .data
        5000 .idata
       40000 .pdata
       F9000 .rdata
        B000 .reloc
      5E3000 .text
        1000 .tls

does not list any symbols (whereas running dumpbin /LINKERMEMBER cantera_shared.lib for the static library lists an extensive list of symbols - at least for the C API?)

Motivation

Describe the need for the proposed change:

  • What problem is it trying to solve? ... allow access to C++ methods in shared dynamic libraries
  • Why is this a good solution? ... make shared dynamic libraries usable on Windows platforms

The ability of accessing Cantera C++ classes and functions at run-time will open additional pathways for the definition of alternative API's and uses in 3rd party applications.

Possible Solutions

Per SO answer, a platform-independent preprocessor macro

// If we are Microsoft C/C++ Compiler
#if defined(_MSC_VER)
    #if defined(DLL_EXPORT)
        #define API __declspec(dllexport)
    #else
        #define API __declspec(dllimport)
    #endif

// If we are non Windows (Export by default) or compiling to a StaticLibrary
#else
    #define API 
#endif

will properly export symbols for classes / functions that include the API decoration. Note: this is just copy-paste from SO, and thus is untested / may need tweaks. There are likely parts of the SCons build that will have to be adjusted.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions