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

dpathmgr.c: error: ‘path’ undeclared when cross-compiling netCDF 4.8.0 #1999

Closed
Alexander-Barth opened this issue May 17, 2021 · 6 comments · Fixed by #2003
Closed

dpathmgr.c: error: ‘path’ undeclared when cross-compiling netCDF 4.8.0 #1999

Alexander-Barth opened this issue May 17, 2021 · 6 comments · Fixed by #2003

Comments

@Alexander-Barth
Copy link
Contributor

I am trying to update the netCDF Julia package to the current version.

  • the version of the software with which you are encountering an issue
    NetCDF 4.8.0

  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.)
    Cross-compilation from Linux to Windows (x86_64-w64-mingw32) in Julia's build tree Yggdrasil.

  • a description of the issue with the steps needed to reproduce it

NetCDF is cross-compiled using the following steps (line 26-46)
https://github.com/JuliaPackaging/Yggdrasil/blob/7a37fabb2eb7c680766aea06af77a055183c92f1/N/NetCDF/common.jl#L26

In addition, we used the option CPPFLAGS=-DH5_USE_110_API.
(#1978 (comment) )

Compiliation succeeds on Linux and Mac OS, but fails on Windows with the error:

2021-05-17T15:55:38.3906619Z [15:55:38] dpathmgr.c: In function ‘NCclosedir’:
2021-05-17T15:55:38.3907622Z [15:55:38] (first use in this function)
2021-05-17T15:55:38.3908452Z [15:55:38]      char* cvtname = NCpathcvt(path);
2021-05-17T15:55:38.3909108Z [15:55:38]                                ^
2021-05-17T15:55:38.3909968Z [15:55:38] dpathmgr.c:359:31: note: each undeclared identifier is reported only once for each function it appears in

For reference the full log files is attached. I am not sure if this error is related to the option -DH5_USE_110_API.
Do you have any idea what could be the issue?
Thanks a lot for any insight!

44.txt

@DennisHeimbigner
Copy link
Collaborator

That is odd. In the tar file for 4.8.0, that whole last section with NCopendir and NCclosedir is disabled. because it is between

#if 0 ... #endif

Is that conditional being ignored for some reason? can you write a simple test program to see if windows ignores the 'if 0' construct?

@Alexander-Barth
Copy link
Contributor Author

Indeed, this is very odd.
This simple test function can indeed be compiled with x86_64-w64-mingw32-gcc testc.c without errors:

#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!");

#if 0
   undeclared_var = 0;
#endif /*0*/

   return 0;
}

However, when I use the -E gcc option to keep the pre-processed files:

# adapted command from libtool --debug
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I../include -I -DH5_USE_110_API -MT libdispatch_la-dpathmgr.lo -MD -MP -MF .deps/libdispatch_la-dpathmgr.Tpo -c dpathmgr.c -DDLL_EXPORT -DPIC -E > dpathmgr.out

I still see the function NCclosedir at line 88489 of dpathmgr.out.

NCclosedir(DIR* ent)
{
    int 
# 358 "dpathmgr.c" 3
       _stat64 
# 358 "dpathmgr.c"
            = 0;
    char* cvtname = NCpathcvt(path);
    if(cvtname == 
# 360 "dpathmgr.c" 3 4
                 ((void *)0)
# 360 "dpathmgr.c"
                     ) {
# 360 "dpathmgr.c" 3
                        (*_errno()) 
# 360 "dpathmgr.c"
                              = 
# 360 "dpathmgr.c" 3
                                2
# 360 "dpathmgr.c"
                                      ; return -1;}
    
# 361 "dpathmgr.c" 3
   _stat64 
# 361 "dpathmgr.c"
        = closedir(cvtname);
    free(cvtname);
    return 
# 363 "dpathmgr.c" 3
          _stat64
# 363 "dpathmgr.c"
              ;
}

@Alexander-Barth
Copy link
Contributor Author

In fact the function NCclosedir is defined twice. The first definition at line 356 triggers the error
if WINPATH is defined.

NCclosedir(DIR* ent)

NCclosedir(DIR* ent)

@DennisHeimbigner
Copy link
Collaborator

ok, that explains it. Let me fix.

@DennisHeimbigner
Copy link
Collaborator

DennisHeimbigner commented May 18, 2021

Still odd that I do not see this error when building under Visual Studio. Oh well, the code is wrong in any case. Wonder if this is a mingw issue? Oh, I know, mingw has dirent.h but visual studio does not.

DennisHeimbigner added a commit to DennisHeimbigner/netcdf-c that referenced this issue May 18, 2021
re: Issue Unidata#1999

NCclosedir code is incorrect. Fix.
Note that this issue crops up when using a non-VisualStudio windows build
such as Mingw because Mingq defines dirent.h, but Visual Studio does not.
@DennisHeimbigner
Copy link
Collaborator

See PR #2003

DennisHeimbigner added a commit to DennisHeimbigner/netcdf-c that referenced this issue May 19, 2021
re: Issue Unidata#1999

NCclosedir code is incorrect. Fix.
Note that this issue crops up when using a non-VisualStudio windows build
such as Mingw because Mingq defines dirent.h, but Visual Studio does not.

Addendum:
Fix some mingw bugs:

1. Modify XGetopt.h to be conditional on _WIN32 instead of _MSC_VER.
2. Make sure sys/stat.h is included in ncpathmgr.h
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 a pull request may close this issue.

2 participants