Recent

Author Topic: Custom URL Protocol - linker error  (Read 273 times)

gabriemarcelo

  • New Member
  • *
  • Posts: 28
Custom URL Protocol - linker error
« on: August 24, 2019, 09:03:13 pm »
Hi guys, I'm pulling my hair with an error in a desktop app in osx. Using FPC 3.0.4, lazarus 2.0.4
I'm trying to allow my app to respond to a custom URL protocol and used this code from https://raw.githubusercontent.com/transmission-remote-gui/transgui/master/urllistenerosx.pas

Code: Pascal  [Select]
  1. unit URLListenerOSX;
  2. {$mode objfpc}{$H+}
  3. {$modeswitch objectivec2}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, CocoaAll, InternetConfig, AppleEvents;
  9.  
  10. type
  11.   THandlerProc = procedure(const url: string);
  12.  
  13.   { TAppURLHandler }
  14.  
  15.   TAppURLHandler = objcclass(NSObject)
  16.   public
  17.     procedure  getUrlwithReplyEvent(event: NSAppleEventDescriptor; eventReply: NSAppleEventDescriptor); message 'getUrl:withReplyEvent:';
  18.   public
  19.     callBack: THandlerProc;
  20.   end;
  21.  
  22. procedure RegisterURLHandler(HandlerProc: THandlerProc);
  23. var
  24.   handler : TAppURLHandler;
  25.   eventManager: NSAppleEventManager;
  26.  
  27. implementation
  28.  
  29. { TAppURLHandler }
  30.  
  31. procedure TAppURLHandler.getUrlwithReplyEvent(event: NSAppleEventDescriptor; eventReply: NSAppleEventDescriptor);
  32. var
  33.   url : NSString;
  34. begin
  35.   url:=event.paramDescriptorForKeyword(keyDirectObject).stringValue;
  36.   callBack(url.UTF8String);
  37. end;
  38.  
  39. procedure RegisterURLHandler(HandlerProc: THandlerProc);
  40. begin
  41.   handler:=TAppURLHandler.alloc.init;
  42.   handler.callBack:=HandlerProc;
  43.   eventManager:=NSAppleEventManager.sharedAppleEventManager;
  44.   eventManager.setEventHandler_andSelector_forEventClass_andEventID(handler,ObjCSelector(handler.getUrlwithReplyEvent), kInternetEventClass,kAEGetURL);
  45. end;
  46.  
  47. end.
  48.  

In the FormCreate event of the main form, I call the code above with the line

Code: Pascal  [Select]
  1. RegisterURLHandler(@HandleMyCustomURLProtocol);
  2.  

and this is the only line

The project fails to compile with the error

Error: linker: Undefined symbols for architecture i386:
Error: linker:  "_res_9_ninit", referenced from:
An error occurred while linking
myapp.lpr(24,1) Error: Error while linking


If I remove the line in FormCreate the project compilation succeeds

Anyone knows why it's not working? Where can I find more details about the error? Thanks in advance!!!

trev

  • Full Member
  • ***
  • Posts: 185
Re: Custom URL Protocol - linker error
« Reply #1 on: August 28, 2019, 08:26:34 am »
Are you compiling a 32-bit app? If so, try 64 bit.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

Thaddy

  • Hero Member
  • *****
  • Posts: 8680
Re: Custom URL Protocol - linker error
« Reply #2 on: August 28, 2019, 10:56:42 am »
What is your OSX version?
And indeed: are you trying 32 bit code with the latest OSX?
Because 32 bit support is dropped. You need to compile for 64 bit.
Are you doing that? Again, what OSX version...
Most people that want to use threading should learn to patch their jeans first: use a needle.

gabriemarcelo

  • New Member
  • *
  • Posts: 28
Re: Custom URL Protocol - linker error
« Reply #3 on: August 29, 2019, 02:47:08 pm »
Thanks guys for your attention but the error was related to another third-party library. Issue was solved by adding this arguments

Code: Pascal  [Select]
  1. fpc -CF64 -k-framework -k"CoreServices" -k-framework -k"Security" -k-macosx_version_min -k10.7 -k/usr/lib/libresolv.dylib -Tdarwin -Sd
  2.