This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
> To whom it may concern: > > > > I have written a host of NetCDF functions in C that I use > on Linux with gcc. I have tried to port the source code to Windows and > am trying to compile with LCC in MATLAB. I have read the documentation > provided for using NetCDF in Windows (set the preprocessor flag > DLL_NETCDF, and place the ncgen.exe, ncdump.exe, netcdf.dll and .lib > file in WINDOWS\system32\), but I am getting errors in the netcdf.h file > when compiling; the compiler does not understand the function > __declspec(dllimport). Is this supposed to be included from the > netcdf.dll library? Do I need to compile the netcdf.dll from scratch > and not use the prebuilt one for Windows? Any help would be > appreciated. Here is the compiler command I am using and output. > > > > "lcc -c -Zp8 -I"C:\Program Files\MATLAB704\sys\lcc\include" > -DMATLAB_MEX_FILE -DDLL_NETCDF -noregistrylookup -Fogetncground.obj > -I"C:\Program Files\MATLAB704"\extern\include -I"C:\Program > Files\MATLAB704"\simulink\include -DNDEBUG getncground.c" > Howdy Jeremy! Unfortunately I don't have the LCC compiler, nor do I use MATLAB, nor do I know how to compile C code into it. (I didn't even know you could do that!) I believe MATLAB already can read netCDF files - is that correct? If so, you should not have to install or build the netcdf library, because it is already there and being used. I don't know if netcdf access come with MATLAB or whether you have to somehow install it, but I would think the easiest way to proceed would be to get netCDF working within MATLAB. Once that is working, try compiling your code again. To answer some of your specific questions: The __declspec(dllimport) is a Microsoft thing that is required in windows-based compilers to "import" the function from the DLL. How can MATLAB provide a compiler on windows that doesn't use declspec? I don't know, obviously. That surprises me. What you need to do is find out how LCC wants you to tell it that nc_open (for example) is coming from a DLL. (I know, in gcc you don't have to tell it, but in Windows you do.) Once you figure out what LCC wants instead of __declspec, you can see how to get the netcdf.h file to reflect that. You should not have to compile netcdf from scratch - but how to get LCC to use a DLL is not clear to me. Surely there are others who have gotten their own C/netcdf code working withing MATLAB on windows. I suggest you ask on the netcdf mailing list, and whatever matlab mailing list seems appropriate. Good luck, Ed Ticket Details =================== Ticket ID: QTJ-204110 Department: Support netCDF Priority: Normal Status: Closed