[MacPorts] #71548: gtk-osx-application-gtk2 build error: cannot find protocol declaration for 'NSString'
MacPorts
noreply at macports.org
Sat Dec 14 18:12:34 UTC 2024
#71548: gtk-osx-application-gtk2 build error: cannot find protocol declaration for
'NSString'
---------------------------------------+----------------------
Reporter: barracuda156 | Owner: mascguy
Type: defect | Status: assigned
Priority: Normal | Milestone:
Component: ports | Version: 2.10.5
Resolution: | Keywords:
Port: gtk-osx-application-gtk2 |
---------------------------------------+----------------------
Comment (by kencu):
I find chatgpt is really great for these kinds of build errors.
Here’s what it says:
The errors and warnings you're seeing during the compilation process
appear to stem from a mix of deprecated API usage and syntax issues in the
code. I'll break down the issues for you:
### 1. **Deprecation Warning** (`GTimeVal` is deprecated)
{{{
/opt/local/include/gtk-2.0/gtk/gtktooltips.h:73:3: warning: 'GTimeVal' is
deprecated: Use 'GDateTime' instead [-Wdeprecated-declarations]
73 | GTimeVal last_popdown;
}}}
**Explanation**: The code is using `GTimeVal`, which is a deprecated
structure in the GLib library. The warning suggests using `GDateTime`
instead, which is the recommended modern API for date and time handling.
**Solution**:
- To fix this warning, you'll need to update the code to replace
`GTimeVal` with `GDateTime`. This requires modifying how the time is
handled in the code.
- Check the parts of the codebase that deal with `GTimeVal` and refactor
them to use `GDateTime` instead. For example, `g_time_val_to_timeval()`
and similar functions are deprecated in favor of `g_date_time_*`
functions.
### 2. **Syntax Error** (`expected '>' before '*' token`)
{{{
GtkApplicationDelegate.c:76:83: error: expected '>' before '*' token
76 | -(void) application: (NSApplication*)theApplication openFiless:
(NSArray<NSString *> *) files
|
^
}}}
**Explanation**: This error is likely due to incorrect Objective-C syntax.
Specifically, the `<NSString *>` is incorrectly placed in the method
declaration.
**Solution**:
- In Objective-C, you can't use generics syntax (like `<NSString *>`)
directly in method signatures unless you're using a specific compiler that
supports it (like Clang). The correct syntax would be to use `NSArray *`
and cast it to `NSArray<NSString *> *` if needed.
**Fixed declaration**:
{{{objective-c
-(void) application: (NSApplication *)theApplication openFiles: (NSArray
*)files;
}}}
If you need type safety for `NSString`, you can cast it inside the method
body, or use `NSArray<NSString *> *` in a context where it’s valid (e.g.,
in the class definition or with modern compilers).
### 3. **Protocol Declaration Not Found** (`cannot find protocol
declaration for 'NSString'`)
```
GtkApplicationDelegate.c:76:1: error: cannot find protocol declaration for
'NSString'
```
**Explanation**: This error suggests that the compiler cannot find the
definition for `NSString`, which is part of the Foundation framework in
macOS.
**Solution**: Ensure that the proper headers are included in your file. In
Objective-C, you typically need to import the Foundation framework.
**Add this at the top of your file**:
```objective-c
#import <Foundation/Foundation.h>
```
### Putting it All Together:
- Refactor your code to avoid using deprecated types like `GTimeVal` in
favor of `GDateTime`.
- Fix the Objective-C method declaration for `openFiles` to avoid using
invalid generic syntax.
- Ensure the `Foundation` framework is imported so that `NSString` and
other Foundation types are recognized.
### Final Considerations:
- If you're working with GTK 2 and Objective-C, ensure that your build
environment is set up correctly with the necessary headers and libraries.
- If you need further help refactoring the code or if this is part of a
larger project, feel free to provide more context!
--
Ticket URL: <https://trac.macports.org/ticket/71548#comment:2>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list