Unidata / netcdf-c

Official GitHub repository for netCDF-C libraries and utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

vawale opened this issue · comments

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.