Skip to content
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

Fix undefined references when using Visual Studio #1732

Merged
merged 7 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ IF(WIN32)
SET(BUILD_DLL ON CACHE BOOL "")
ADD_DEFINITIONS(-DDLL_NETCDF)
ADD_DEFINITIONS(-DDLL_EXPORT)
ADD_DEFINITIONS(-DUTF8PROC_DLLEXPORT)
ENDIF()
ENDIF()
# Did the user specify a default minimum blocksize for posixio?
Expand Down Expand Up @@ -891,11 +890,20 @@ IF(ENABLE_EXTRA_TESTS)
ENDIF()

# Option to use bundled XGetopt in place of getopt(). This is mostly useful
# for MSVC builds. If not building utilities, getopt() isn't required at all.
# for MSVC builds. If not building utilities or some tests,
# getopt() isn't required at all.
IF(MSVC)
OPTION(ENABLE_XGETOPT "Enable bundled XGetOpt instead of external getopt()." ON)
IF(ENABLE_XGETOPT)
SET(USE_X_GETOPT ON CACHE BOOL "")
# Copy XGetopt.c to everywhere it is needed. Avoids
# inconsistent code
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncgen3/)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncgen/)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncdump/)
ENDIF()
ENDIF()

Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This file contains a high-level description of this package's evolution. Release

## 4.8.0 - TBD

* [Bug Fix] Add necessary __declspec declarations to allow compilation
of netcdf library without causing errors or (_declspec related)
warnings [https://github.com/Unidata/netcdf-c/issues/1725].
* [Enhancement] When a filter is applied twice with different
parameters, then the second set is used for writing the dataset
[https://github.com/Unidata/netcdf-c/issues/1713].
Expand Down
80 changes: 40 additions & 40 deletions include/XGetopt.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
// XGetopt.h Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef XGETOPT_H
#define XGETOPT_H
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#if defined(DLL_NETCDF)
# if defined(DLL_EXPORT)
# define GTOPT_EXTRA __declspec(dllexport)
# else
# define GTOPT_EXTRA __declspec(dllimport)
# endif
GTOPT_EXTRA extern int optind, opterr;
#else
extern int optind, opterr;
#endif
extern TCHAR *optarg;
int getopt(int argc, TCHAR *argv[], TCHAR *optstring);
#endif //XGETOPT_H
// XGetopt.h Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////


#ifndef XGETOPT_H
#define XGETOPT_H

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#if 0
#ifdef _MSC_VER
# ifdef DLL_EXPORT
# define GTOPT_EXTRA __declspec(dllexport)
# else
# define GTOPT_EXTRA __declspec(dllimport)
# endif
#else
# define GTOP_EXTRA
#endif
#endif

#define GTOPT_EXTRA
GTOPT_EXTRA extern int optind, opterr;
GTOPT_EXTRA extern TCHAR* optarg;
GTOPT_EXTRA extern int getopt(int argc, TCHAR *argv[], TCHAR *optstring);

#endif //XGETOPT_H
4 changes: 2 additions & 2 deletions include/netcdf_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ EXTERNL int nc_var_filter_remove(int ncid, int varid, unsigned int id);
last arg is void*, but is actually H5Z_class2_t*.
It is void* to avoid having to reference hdf.h.
*/
EXTERNL int nc_filter_client_register(unsigned int id, void*/*H5Z_class2_t* */);
EXTERNL int nc_filter_client_register(unsigned int id, void*);
EXTERNL int nc_filter_client_unregister(unsigned int id);
EXTERNL int nc_filter_client_inq(unsigned int id, void*/*H5Z_class2_t* */);
EXTERNL int nc_filter_client_inq(unsigned int id, void*);

/* HDF5 specific filter info */
typedef struct NC4_Filterspec {
Expand Down
1 change: 0 additions & 1 deletion libdap2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
int verbose;
char* fileurl;
int debug;
extern int ocdebug;

/* Forward */
static void usage(void);
Expand Down
10 changes: 8 additions & 2 deletions libsrc/XGetopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
///////////////////////////////////////////////////////////////////////////////


#ifndef DLL_EXPORT
#define DLL_EXPORT
#endif

#include "XGetopt.h"


Expand Down Expand Up @@ -144,9 +148,11 @@
//
///////////////////////////////////////////////////////////////////////////////

TCHAR *optarg; // global argument pointer
int optind = 0; // global argv index
GTOPT_EXTRA TCHAR *optarg; // global argument pointer
GTOPT_EXTRA int optind = 0; // global argv index
GTOPT_EXTRA int opterr; // print error

GTOPT_EXTRA
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
{
static TCHAR *next = NULL;
Expand Down
3 changes: 2 additions & 1 deletion nc_test4/tst_dims2.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ main(int argc, char **argv)
nc_type xtype_in;
char name_in[NC_MAX_NAME + 1];
int i;
nc_set_log_level(4);
nc_set_log_level(0);

if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

/*create dimensions*/
Expand Down
3 changes: 2 additions & 1 deletion nc_test4/tst_fills.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ main(int argc, char **argv)
char vals[MAX_VALS];
int i;

nc_set_log_level(4);
nc_set_log_level(0);

if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

/* Define dimensions and two vars, a 1D coordinate var for
Expand Down
2 changes: 1 addition & 1 deletion nc_test4/tst_filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ echo "*** Testing multiple filters"
rm -f ./multifilter.nc ./multi.txt ./smulti.cdl
rm -f nccopyF.cdl nccopyF.nc ncgenF.cdl ncgenF.nc
${execdir}/tst_multifilter
${NCDUMP} -hs ./multifilter.nc >./multi.cdl
${NCDUMP} -hs multifilter.nc >./multi.cdl
# Remove irrelevant -s output
sclean ./multi.cdl ./smulti.cdl
diff -b -w ${srcdir}/ref_multi.cdl ./smulti.cdl
Expand Down
43 changes: 20 additions & 23 deletions ncdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# University Corporation for Atmospheric Research/Unidata.

# See netcdf-c/COPYRIGHT file for more info.
IF(BUILD_SHARED_LIBS AND WIN32)
remove_definitions(-DDLL_EXPORT)
remove_definitions(-DDLL_NETCDF)
ENDIF()
#IF(BUILD_SHARED_LIBS AND WIN32)
# remove_definitions(-DDLL_EXPORT)
# remove_definitions(-DDLL_NETCDF)
#ENDIF()

SET(ncdump_FILES ncdump.c vardata.c dumplib.c indent.c nctime0.c utils.c nciter.c)
SET(nccopy_FILES nccopy.c nciter.c chunkspec.c utils.c dimmap.c list.c)
Expand Down Expand Up @@ -272,25 +272,22 @@ ENDIF()

ENDIF()

IF(MSVC)
SET_TARGET_PROPERTIES(ncdump
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
SET_TARGET_PROPERTIES(nccopy
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
SET_TARGET_PROPERTIES(ncvalidator
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)

IF(ENABLE_DAP)
SET_TARGET_PROPERTIES(ocprint
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
ENDIF(ENABLE_DAP)

ENDIF()

#IF(MSVC)
# SET_TARGET_PROPERTIES(ncdump
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# SET_TARGET_PROPERTIES(nccopy
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# SET_TARGET_PROPERTIES(ncvalidator
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# IF(ENABLE_DAP)
# SET_TARGET_PROPERTIES(ocprint
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# ENDIF(ENABLE_DAP)
#ENDIF()

INSTALL(TARGETS ncdump RUNTIME DESTINATION bin COMPONENT utilities)
INSTALL(TARGETS nccopy RUNTIME DESTINATION bin COMPONENT utilities)
Expand Down
2 changes: 1 addition & 1 deletion ncdump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ inttags.cdl inttags4.cdl ref_inttags.cdl ref_inttags4.cdl \
ref_tst_ncf213.cdl tst_h_scalar.sh run_utf8_nc4_tests.sh \
tst_formatx3.sh tst_formatx4.sh ref_tst_utf8_4.cdl \
ref_tst_nc4_utf8_4.cdl tst_inttags.sh tst_inttags4.sh CMakeLists.txt \
XGetopt.c tst_bom.sh tst_inmemory_nc3.sh tst_dimsizes.sh \
tst_bom.sh tst_inmemory_nc3.sh tst_dimsizes.sh \
tst_inmemory_nc4.sh tst_fileinfo.sh run_ncgen_tests.sh \
ref_test_360_day_1900.nc ref_test_365_day_1900.nc \
ref_test_366_day_1900.nc ref_test_360_day_1900.cdl \
Expand Down
Loading