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

Windows compile #268

Merged
merged 3 commits into from
Aug 13, 2020
Merged

Windows compile #268

merged 3 commits into from
Aug 13, 2020

Conversation

brucenairn
Copy link
Contributor

I wanted to build netcdf-fortran for Windows 10 using Intel Fortran 19.0 (v 2) and VS 2017. I needed to make a few changes to get this to work. I added stub functions for parallel I/O when netcdf-c was built without parallel I/O, as mine was. I separated the build steps for C and Fortran code, built the C code to object files and linked into the Fortran code. This prevents the Fortran flags from being applied to the C code. My netcdf-c library was built as a shared (DLL) library, netcdf-fortran was built as a static library.
I hope this is helpful. I'm new to this, please let me know if I should have done something different.

Parallel I/O stub functions in new file nf_nc_noparallel.f90
Included in compile when netcdf-c library built without parallel I/O
Return NC_ENOPAR, same as netcdf-c
Separate C code from Fortran so C code gets C flags at compile
Allows proper build on Windows
@CLAassistant
Copy link

CLAassistant commented Jul 4, 2020

CLA assistant check
All committers have signed the CLA.

@WardF
Copy link
Member

WardF commented Jul 6, 2020

Thank you, this looks great! I'll review it and merge or follow up. This is the proper procedure for submitting a PR, certainly. Thanks!

@jaimergp
Copy link

jaimergp commented Aug 4, 2020

Thanks for the work here! We are excited it might enable us to provide netcdf-fortran on Conda Forge! Subscribed to follow the updates.

ADD_LIBRARY(netcdff ${netcdff_SOURCES})
TARGET_LINK_LIBRARIES(netcdff PUBLIC netCDF::netcdf)
TARGET_LINK_LIBRARIES(netcdff ${NETCDF_C_LIBRARY})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brucenairn CMake is throwing a warning on this line for me, on OSX (I do not have a way to test it on Windows with the Intel compilers). I can add the PUBLIC keyword, which resolves the warning but results in -lnetcdf being passed to the linker twice. Does this patch still work on Windows if you were to remove this line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this comment before but it may not have gone through, much to my dismay. I am anxious to get this in as well :). Great work!

Previous target_link_libraries have keywoord signatures, so
NETCDF_C_LIBRARY needs one, per Cmake CMP0023
PRIVATE libraries are linked to, but are not made part of the
link interface.
@WardF WardF merged commit 10ec92e into Unidata:master Aug 13, 2020
@WardF
Copy link
Member

WardF commented Aug 13, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants