xuchunyang / osx-dictionary.el

Mac OS X Dictionary.app interface for Emacs
139 stars 23 forks source link

Update osx-dictionary.m #33

Closed hw202207 closed 9 months ago

hw202207 commented 9 months ago

Import foundation.h cause compilation error. Turns out it is not necessary.

Shall fix #32 #22

xuchunyang commented 9 months ago

It does not cause any error on my computer. It emits warnings during compilation if I remove it, but since the binary still works fine, I am going to merge this.

➜  osx-dictionary.el git:(master) ✗ clang -O3 -framework CoreServices -framework Foundation osx-dictionary.m -o y
osx-dictionary.m:19:21: warning: receiver 'NSString' is a forward class and corresponding @interface may not exist [-Wreceiver-forward-class]
  NSString* word = [NSString stringWithUTF8String:searchword];
                    ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:256:8: note: forward declaration of class here
@class NSString;
       ^
osx-dictionary.m:19:30: warning: class method '+stringWithUTF8String:' not found (return type defaults to 'id') [-Wobjc-method-access]
  NSString* word = [NSString stringWithUTF8String:searchword];
                             ^~~~~~~~~~~~~~~~~~~~
osx-dictionary.m:21:64: warning: instance method '-length' not found (return type defaults to 'id') [-Wobjc-method-access]
                                          CFRangeMake(0, [word length]));
                                                               ^~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:256:8: note: receiver is instance of class declared here
@class NSString;
       ^
osx-dictionary.m:21:58: warning: incompatible pointer to integer conversion passing 'id' to parameter of type 'CFIndex' (aka 'long') [-Wint-conversion]
                                          CFRangeMake(0, [word length]));
                                                         ^~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:526:52: note: passing argument to parameter 'len' here
CF_INLINE CFRange CFRangeMake(CFIndex loc, CFIndex len) {
                                                   ^
osx-dictionary.m:83:28: warning: instance method '-UTF8String' not found (return type defaults to 'id') [-Wobjc-method-access]
  char* r = (char*)[result UTF8String];
                           ^~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:256:8: note: receiver is instance of class declared here
@class NSString;
       ^
5 warnings generated.
➜  osx-dictionary.el git:(master) ✗ ./y hello
hello | BrE həˈləʊ,hɛˈləʊ, AmE həˈloʊ,hɛˈloʊ |
 A. noun 问候 wènhòu
 B. exclamation
 ① (greeting) 你好 nǐ hǎo; (on phone) 喂 wèi
 ② British (in surprise) 嘿 hēi %
➜  osx-dictionary.el git:(master) ✗ git diff
➜  osx-dictionary.el git:(master) ✗ uname -a
Darwin XudeiMac.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103 arm64
➜  osx-dictionary.el git:(master) ✗ sw_vers
ProductName:        macOS
ProductVersion:     14.2.1
BuildVersion:       23C71
➜  osx-dictionary.el git:(master) ✗ git --no-pager diff
diff --git a/osx-dictionary.m b/osx-dictionary.m
index 9972fbc..34746d3 100644
--- a/osx-dictionary.m
+++ b/osx-dictionary.m
@@ -6,7 +6,6 @@
 // Use: osx-dictionary-cli WORD
 // ============================================================================

-#import <Foundation/Foundation.h>
 #import <CoreServices/CoreServices.h>

 #define isnum(x)\
➜  osx-dictionary.el git:(master) ✗
hw202207 commented 9 months ago

Yeah it still does cause warnings but at least not error which prevents it compilation at all.

Thank you!!

bcc32 commented 7 months ago

I think one of those warnings is unfortunately an error, at least on my mac:

osx-dictionary.m:21:58: error: incompatible pointer to integer conversion passing 'id' to parameter of type 'CFIndex' (aka 'long') [-Wint-conversion]
                                          CFRangeMake(0, [word length]));
                                                         ^~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:530:52: note: passing argument to parameter 'len' here
CF_INLINE CFRange CFRangeMake(CFIndex loc, CFIndex len) {
                                                   ^

Version info:

$ /usr/bin/clang --version
/usr/bin/clang --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: x86_64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin