-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"multiple definition" linking error when compiling netCDF v4.9.0 with GCC 11.3.0 #2419
Comments
There seems to be two distinct implementations of the JSON bits in the codebase, one in pair of separate The purpose of Here This linking problem is masked when linking against shared libraries as the single-header implementation in the object files is preferred over the implementation in the shared library. Amusingly enough, depending on executable/library load order, the shared library may end up using a symbol defined in the executable or a previously loaded library rather than its own symbol. One workaround that seems to do the trick for my non-netcdf test case is to mark the function declarations and definitions in the single-file implementation |
Your json analysis is correct. I wanted it to be possible to build |
We puzzled together a patch that allows us to bypass this problem, by adding |
Yes,I am following a similar path by using a macro that gets |
re: Issue Unidata#2419 There are effectively two json subsystems in netcdf-c. 1. ncjson.[ch] in libnetcdf 2. netcdf_json.h for use by plugins so they can be built without need for libnetcdf. The netcdf_json.h file is constructed from the concatenation of ncjson.h plus ncjson.c. It turned out that in doing this, I was leaving some symbols externally visible so that if, for some reason, a plugin was built and needed libnetcdf, then symbol conflicts arose. The solution is to prefix the declarations in ncjson.[ch] with a macro (OPTSTATIC) that can be resolved to either nothing or to "static". Then in netcdf_json.h, it resolves to "static" and prevents the symbol conflicts. Note that netcdf_json.h is constructed once in netcdf-c/include/Makefile.am with the rule named "makepluginjson". This means that it is included in the distribution. However, this also means that if ncjson.[ch] is changed, then it is necessary to invoke makepluginjson explicitly to rebuild netcdf_json.h
See PR #2448 |
When trying to compile netCDF v4.9.0 with GCC 11.3.0 + binutils 2.38 + CMake 3.23.1 on RHEL 8.4, we're hitting the following linker error:
To reproduce:
We are not seeing this problem with netCDF v4.8.1 using the exact same compiler toolchain (GCC 11.3.0 + binutils 2.38) and CMake (3.23.1) on RHEL 8.4...
The text was updated successfully, but these errors were encountered: