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

[macOS] v. 5.9.7 broken on macOS < 10.13: if_dl.h: error: unknown type name 'u_char'; did you mean 'char'? #2360

Closed
barracuda156 opened this issue Jan 25, 2024 · 2 comments · Fixed by #2361

Comments

@barracuda156
Copy link

5.9.7 fails to build now on multiple systems.

On buildbots with clang, x86_64:

/usr/bin/clang -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -arch x86_64 -isysroot/ -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=597 -DPy_LIMITED_API=0x03060000 -DPSUTIL_OSX=1 -I/opt/local/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c psutil/arch/osx/net.c -o build/temp.macosx-10.12-x86_64-cpython-311/psutil/arch/osx/net.o
In file included from psutil/arch/osx/net.c:12:
/usr/include/net/if_dl.h:90:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char  sdl_len;        /* Total length of sockaddr */
        ^
/usr/include/net/if_dl.h:91:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char  sdl_family;     /* AF_LINK */
        ^
/usr/include/net/if_dl.h:92:2: error: unknown type name 'u_short'; did you mean 'short'?
        u_short sdl_index;      /* if != 0, system given index for interface */
        ^
/usr/include/net/if_dl.h:93:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char  sdl_type;       /* interface type */
        ^
/usr/include/net/if_dl.h:94:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char  sdl_nlen;       /* interface name length, no trailing 0 reqd. */
        ^
/usr/include/net/if_dl.h:95:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char  sdl_alen;       /* link level address length */
        ^
/usr/include/net/if_dl.h:96:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char  sdl_slen;       /* link layer selector length */
        ^
psutil/arch/osx/net.c:68:21: warning: array subscript is of type 'char' [-Wchar-subscripts]
            ifc_name[sdl->sdl_nlen] = 0;
                    ^~~~~~~~~~~~~~
1 warning and 7 errors generated.
XCode (https://developer.apple.com/xcode/) is not installed
error: command '/usr/bin/clang' failed with exit code 1

Locally with gcc, on ppc:

/usr/bin/gcc-4.2 -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -arch ppc -isysroot/ -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=597 -DPy_LIMITED_API=0x03060000 -DPSUTIL_OSX=1 -I/opt/local/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c psutil/arch/osx/net.c -o build/temp.macosx-10.6-ppc-cpython-311/psutil/arch/osx/net.o
In file included from psutil/arch/osx/net.c:12:
//usr/include/net/if_dl.h:90: error: expected specifier-qualifier-list before ‘u_char’
psutil/arch/osx/net.c: In function ‘psutil_net_io_counters’:
psutil/arch/osx/net.c:67: error: ‘struct sockaddr_dl’ has no member named ‘sdl_data’
psutil/arch/osx/net.c:67: error: ‘struct sockaddr_dl’ has no member named ‘sdl_nlen’
psutil/arch/osx/net.c:67: error: ‘struct sockaddr_dl’ has no member named ‘sdl_data’
psutil/arch/osx/net.c:67: error: ‘struct sockaddr_dl’ has no member named ‘sdl_nlen’
psutil/arch/osx/net.c:68: error: ‘struct sockaddr_dl’ has no member named ‘sdl_nlen’
XCode (https://developer.apple.com/xcode/) is not installed
error: command '/usr/bin/gcc-4.2' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel

It does something strange. First of all, Xcode is installed. Then, why it needs Xcode at all?
Finally, something got badly broken with headers, apparently. 5.9.5 built fine.

@github-actions github-actions bot added the macos label Jan 25, 2024
ryandesign added a commit to ryandesign/psutil that referenced this issue Jan 25, 2024
In old versions of macOS, net/if_dl.h neglects to include sys/types.h,
which results in build failure:

error: unknown type name 'u_char'; did you mean 'char'?

Including net/if.h first works around the problem because net/if.h
includes sys/types.h.

Fixes giampaolo#2360
@ryandesign
Copy link
Contributor

Sergey also filed this with MacPorts where he noted that it builds fine on macOS 10.13 and later, but not on 10.12 and earlier. This suggested to me that maybe some system header that is automatically included on 10.13 and later that provides the definition of u_char needed to be included manually.

I found that old macOS system headers have a bug that net/if_df.h does not include sys/types.h, but net/if.h does, so including that headers before, rather than after, net/if_dl.h works around the problem; I submitted a PR for that.

More generally, following the convention of including system headers in alphabetical order should minimize these kinds of problems.

There are further build failures on old macOS systems after fixing this. I'll investigate and report that separately.

giampaolo pushed a commit that referenced this issue Jan 26, 2024
In old versions of macOS, net/if_dl.h neglects to include sys/types.h,
which results in build failure:

error: unknown type name 'u_char'; did you mean 'char'?

Including net/if.h first works around the problem because net/if.h
includes sys/types.h.

Fixes #2360
@barracuda156
Copy link
Author

barracuda156 commented May 30, 2024

@ryandesign @giampaolo I see in notes elsewhere sahlberg/libnfs@381883d that sys/socket.h must be included before net/if.h, so the fix above might not have been correct: https://github.com/giampaolo/psutil/pull/2361/files

Though py-psutil 5.9.8 builds fine for me on 10.6, I just checked.

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

Successfully merging a pull request may close this issue.

2 participants