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] error: unknown type name 'CFTimeInterval' #2362

Closed
ryandesign opened this issue Jan 25, 2024 · 1 comment · Fixed by #2364
Closed

[macOS] error: unknown type name 'CFTimeInterval' #2362

ryandesign opened this issue Jan 25, 2024 · 1 comment · Fixed by #2364

Comments

@ryandesign
Copy link
Contributor

Summary

  • OS: OS X 10.11
  • Architecture: x86_64
  • Psutil version: 5.9.7
  • Python version: I was using 3.12.1 but I don't think it matters
  • Type: installation

Description

After applying #2361 to fix #2360, the build still fails on OS X 10.11 with these errors:

In file included from psutil/arch/osx/sensors.c:15:
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:250:1: error: unknown type name 'CFTimeInterval'
CFTimeInterval IOPSGetTimeRemainingEstimate(void);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:270:1: error: unknown type name 'CFTypeRef'
CFTypeRef IOPSCopyPowerSourcesInfo(void);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:284:1: error: unknown type name 'CFArrayRef'
CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:284:37: error: unknown type name 'CFTypeRef'
CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
                                    ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:302:1: error: unknown type name 'CFDictionaryRef'
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:302:47: error: unknown type name 'CFTypeRef'
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
                                              ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:302:63: error: unknown type name 'CFTypeRef'
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
                                                              ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:314:1: error: unknown type name 'CFStringRef'
CFStringRef     IOPSGetProvidingPowerSourceType(CFTypeRef snapshot);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:314:49: error: unknown type name 'CFTypeRef'
CFStringRef     IOPSGetProvidingPowerSourceType(CFTypeRef snapshot);
                                                ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:339:1: error: unknown type name 'CFRunLoopSourceRef'
CFRunLoopSourceRef IOPSNotificationCreateRunLoopSource(IOPowerSourceCallbackType callback, void *context);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:359:1: error: unknown type name 'CFRunLoopSourceRef'
CFRunLoopSourceRef IOPSCreateLimitedPowerNotification(IOPowerSourceCallbackType callback, void *context) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:372:1: error: unknown type name 'CFDictionaryRef'
CFDictionaryRef IOPSCopyExternalPowerAdapterDetails(void);
^
psutil/arch/osx/sensors.c:24:5: error: use of undeclared identifier 'CFTypeRef'
    CFTypeRef power_info = NULL;
    ^
psutil/arch/osx/sensors.c:25:5: error: use of undeclared identifier 'CFArrayRef'
    CFArrayRef power_sources_list = NULL;
    ^
psutil/arch/osx/sensors.c:26:5: error: use of undeclared identifier 'CFDictionaryRef'
    CFDictionaryRef power_sources_information = NULL;
    ^
psutil/arch/osx/sensors.c:27:5: error: use of undeclared identifier 'CFNumberRef'
    CFNumberRef capacity_ref = NULL;
    ^
psutil/arch/osx/sensors.c:28:5: error: use of undeclared identifier 'CFNumberRef'
    CFNumberRef time_to_empty_ref = NULL;
    ^
psutil/arch/osx/sensors.c:29:5: error: use of undeclared identifier 'CFStringRef'
    CFStringRef ps_state_ref = NULL;
    ^
psutil/arch/osx/sensors.c:34:5: error: use of undeclared identifier 'power_info'
    power_info = IOPSCopyPowerSourcesInfo();
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
XCode (https://developer.apple.com/xcode/) is not installed
error: command '/usr/bin/clang' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel

I was going to investigate but then had a power outage which interrupted my work so I'll just leave my notes here for now.

Those CF types are surely CoreFoundation types. I saw that you were including a couple individual headers from the IOKit framework, and evidently at least on this old version of macOS, those individual headers aren't including the CoreFoundation headers.

I suspect the solution may be not to include those individual headers but instead include only the top-level header, as is customary for frameworks. In other words, to use IOKit, only use #include <IOKit/IOKit.h>. Hopefully I can test later if that fixes it and if so I'll send a PR.

@ryandesign ryandesign added the bug label Jan 25, 2024
@github-actions github-actions bot added the macos label Jan 25, 2024
ryandesign added a commit to ryandesign/psutil that referenced this issue Jan 29, 2024
This is correct, since this file does use CoreFoundation types, and it
is necessary because on old macOS versions IOKit/ps/IOPowerSources.h,
which is already included and which also uses CoreFoundation types,
forgot to include CoreFoundation/CoreFoundation.h.

Fixes giampaolo#2362
@ryandesign
Copy link
Contributor Author

In other words, to use IOKit, only use #include <IOKit/IOKit.h>.

Well, forget that. Looks like IOKit is not one of those frameworks that uses an umbrella header; there is no IOKit/IOKit.h. And I grepped through the extant IOKit headers and none of them include the ones you're including, so it must be correct for you to include them directly.

The fix, then, is to include CoreFoundation/CoreFoundation.h directly. I've submitted a PR to do that.

giampaolo pushed a commit that referenced this issue Mar 15, 2024
* Include CoreFoundation/CoreFoundation.h

This is correct, since this file does use CoreFoundation types, and it
is necessary because on old macOS versions IOKit/ps/IOPowerSources.h,
which is already included and which also uses CoreFoundation types,
forgot to include CoreFoundation/CoreFoundation.h.

Fixes #2362
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.

1 participant