Skip to content

ncjson.h and dreg.c do not use right export decoration macros #2859

@vawale

Description

@vawale

Version: 4.9.2
Environment:
OS: Windows
Compiler: Visual Studio 16 2019

On Windows to export functions from shared library, functions have to be decorated with __declspec(dllexport) or __declspec(dllimport), which is done correctly in MSC_EXTRA and EXTERNL macros in https://github.com/Unidata/netcdf-c/blob/main/include/ncexternl.h.

However these are not used in ncjson.h - https://github.com/Unidata/netcdf-c/blob/main/include/ncjson.h, which always defines DLLEXPORT to __declspec(dllexport) if the macro is not already defined for windows. This looks incorrect as when the library is used the decorator macro should expand to __declspec(dllimport). The same issue is observed in decorator of getmountpoint definition in https://github.com/Unidata/netcdf-c/blob/main/libdispatch/dreg.c#L20.

Because of this problem when statically linking with netcdf-c library in my shared library, I get the following extra exported symbols from my dll:

NCJaddstring 
NCJappend 
NCJclone 
NCJcvt 
NCJdictget 
NCJdump 
NCJinsert 
NCJnew 
NCJnewstring 
NCJnewstringn 
NCJparse 
NCJparsen 
NCJreclaim 
NCJtotext 
NCJunparse
getmountpoint

I don't want these symbols to be part of my dll exported interface as that can lead to conflicts when user of my library links to netcdf-c as well. I think this issue can be fixed by consistently using MSC_EXTRA or EXTERNL macro definitions from https://github.com/Unidata/netcdf-c/blob/main/include/ncexternl.h as decorators in ncjson.h and dreg.c. I am attaching the diff of a fix fix-export.txt that I tried.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions