[Lazarus] Dynamic library dependency error
Hi All, I try to make a dynamic library and get this error: paintrect.pas(0,0) Fatal: Can not find unit Controls used by paintrect. Check if package LCLBase is in the dependencies. The source code of my library is: library liboval; {$mode objfpc}{$H+} uses paintrect, oval; function GetPainter: TPainter; begin end; exports GetPainter; begin end. And the used paintrect.pas is attached. Any hint is greatly appreciated. Thanks, Shannonunit paintrect; {$mode objfpc}{$H+} interface uses Classes, Controls, ExtCtrls, Graphics, Types, SysUtils, LCLType; type TPainter = class abstract public OnKeyDown: TKeyEvent; OnKeyUp: TKeyEvent; OnUTF8KeyPress: TUTF8KeyPressEvent; OnMouseDown: TMouseEvent; OnMouseEnter: TNotifyEvent; OnMouseLeave: TNotifyEvent; OnMouseMove: TMouseMoveEvent; OnMouseUp: TMouseEvent; OnMouseWheel: TMouseWheelEvent; OnMouseWheelDown: TMouseWheelUpDownEvent; OnMouseWheelUp: TMouseWheelUpDownEvent; procedure Paint(Canvas: TCanvas; Rect: TRect); virtual abstract; end; { TPaintRect } TPaintRect = class private align: TAlign; box: TPaintBox; _span: Real; painters: TStringList; //array of TPainter; prect: TPaintRect; FOnKeyDown: TKeyEvent; FOnKeyUp: TKeyEvent; FOnMouseDown: TMouseEvent; FOnMouseEnter: TNotifyEvent; FOnMouseLeave: TNotifyEvent; FOnMouseMove: TMouseMoveEvent; FOnMouseUp: TMouseEvent; FOnMouseWheel: TMouseWheelEvent; FOnMouseWheelDown: TMouseWheelUpDownEvent; FOnMouseWheelUp: TMouseWheelUpDownEvent; FOnPaint: TNotifyEvent; FOnUTF8KeyPress: TUTF8KeyPressEvent; function GetRect(Invert: Boolean = False): TRect; function GetSpan: Real; procedure SetSpan(AValue: Real); procedure OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure OnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure OnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure OnMouseEnter(Sender: TObject); procedure OnMouseLeave(Sender: TObject); procedure OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure OnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure OnMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure OnMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); procedure OnMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); procedure OnPaint(Sender: TObject); procedure OnUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char); procedure Initialize; public property Span: Real read GetSpan write SetSpan; constructor Create(ABox: TPaintBox; AnAlign: TAlign; ASpan: Real); constructor Create(ARect: TPaintRect; AnAlign: TAlign; ASpan: Real); destructor Destroy; override; procedure AddPainter(AName: string; APainter: TPainter); end; implementation { TPaintRect } function TPaintRect.GetRect(Invert: Boolean): TRect; var pr : TRect; function Size: Integer; begin case align of alBottom, alTop: Result := pr.Bottom - pr.Top; else Result := pr.Right - pr.Left; end; if _span 1 then begin Result := Round(_span * Result); end else begin if _span 0 then Result := 0 else if _span Result then Result := Trunc(_span); end; end; begin if Assigned(prect) then pr := prect.GetRect(True) else pr := Rect(0, 0, box.ClientWidth - 1, box.ClientHeight - 1); if align in [alNone, alClient, alCustom] then begin if Invert then Result := Rect(0, 0, 0, 0) else Result := pr; end else if Invert then begin case align of alBottom: Result := Rect(pr.Left, pr.Top, pr.Right, pr.Bottom-Size); alLeft: Result := Rect(pr.Left+Size, pr.Top, pr.Right, pr.Bottom); alRight: Result := Rect(pr.Left, pr.Top, pr.Right-Size, pr.Bottom); alTop: Result := Rect(pr.Left, pr.Top+Size, pr.Right, pr.Bottom); end; end else begin case align of alBottom: Result := Rect(pr.Left, pr.Bottom-Size+1, pr.Right, pr.Bottom); alLeft: Result := Rect(pr.Left, pr.Top, pr.Left+Size-1, pr.Bottom); alRight: Result := Rect(pr.Right-Size+1, pr.Top, pr.Right, pr.Bottom); alTop: Result := Rect(pr.Left, pr.Top, pr.Right, pr.Top+Size-1); end; end; end; function TPaintRect.GetSpan: Real; begin Result := _span; end; procedure TPaintRect.SetSpan(AValue: Real); begin _span := AValue; box.Invalidate; end; procedure TPaintRect.OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var i: Integer; p: TPainter; begin for i := 0 to painters.Count - 1 do begin p := TPainter(painters.Objects[i]); if Assigned(p.OnKeyDown) then p.OnKeyDown(Sender, Key, Shift); end; if Assigned(FOnKeyDown) then
Re: [Lazarus] Dynamic library dependency error
On 22/1/13 2:22, xrfang wrote: I try to make a dynamic library and get this error: paintrect.pas(0,0) Fatal: Can not find unit Controls used by paintrect. Check if package LCLBase is in the dependencies. You need to add LCLBase as a project dependency. Use the Project Inspector's Add button to show the Add to Project dialog. Project - Project Inspector, then in the Project Inspector click the middle tab to open the New Requirement page, and in the Package Name combo dropdown choose LCLBase from the long list presented. Then click the [Create New Requirement] button, and you're done - the new package requirement will be listed under Required Packages node in the Project Inspector. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Dynamic library dependency error
Hi Howard, Thanks for your info. After adding LCLBase to dependencies, I get these errors: /usr/bin/ld: warning: link.res contains output sections; did you forget -T? /usr/bin/ld: /home/xrfang/Desktop/paintrect/lib/x86_64-linux/paintrect.o: relocation R_X86_64_32S against `_$PAINTRECT$_Ld1' can not be used when making a shared object; recompile with -fPIC /home/xrfang/Desktop/paintrect/lib/x86_64-linux/paintrect.o: 无法读取符号: 错误的值 liboval.lpr(14) Error: Error while linking where 无法读取符号: 错误的值 means cannot read symbol: illegal value. What's wrong here? Thanks, Shannon 在 二, 1月 22, 2013 at 10:41 下午,Howard Page-Clark h...@talktalk.net 写道: On 22/1/13 2:22, xrfang wrote: I try to make a dynamic library and get this error: paintrect.pas(0,0) Fatal: Can not find unit Controls used by paintrect. Check if package LCLBase is in the dependencies. You need to add LCLBase as a project dependency. Use the Project Inspector's Add button to show the Add to Project dialog. Project - Project Inspector, then in the Project Inspector click the middle tab to open the New Requirement page, and in the Package Name combo dropdown choose LCLBase from the long list presented. Then click the [Create New Requirement] button, and you're done - the new package requirement will be listed under Required Packages node in the Project Inspector. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Dynamic library dependency error
Le 22/01/2013 16:14, xrfang a écrit : Hi Howard, Thanks for your info.  After adding LCLBase to dependencies, I get these errors: /usr/bin/ld: warning: link.res contains output sections; did you forget -T? /usr/bin/ld: /home/xrfang/Desktop/paintrect/lib/x86_64-linux/paintrect.o: relocation R_X86_64_32S against `_$PAINTRECT$_Ld1' can not be used when making a shared object; recompile with -fPIC /home/xrfang/Desktop/paintrect/lib/x86_64-linux/paintrect.o: æ— æ³•è¯»å�–符å�·: 错误的值 liboval.lpr(14) Error: Error while linking where æ— æ³•è¯»å�–符å�·: 错误的值 means cannot read symbol: illegal value. What's wrong here? Try adding -fPIC -dFPC_PIC into program's options, Other section Tha's what I use when building shared libraries. Antonio. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Dynamic library dependency error
Thanks, I added -fPIC and it worked, it seems no need to add -dFPC_PIC? Also I found a small problem. While create a new shared library and compile fpc always complain that -WR is invalid. I have to uncheck Relocatable option to fix this. I think this is a bug in lazarus project template, what do you think? 2013/1/23 Antonio Fortuny a.fort...@sitasoftware.lu Le 22/01/2013 16:14, xrfang a écrit : Hi Howard, Thanks for your info.  After adding LCLBase to dependencies, I get these errors: /usr/bin/ld: warning: link.res contains output sections; did you forget -T? /usr/bin/ld: /home/xrfang/Desktop/**paintrect/lib/x86_64-linux/**paintrect.o: relocation R_X86_64_32S against `_$PAINTRECT$_Ld1' can not be used when making a shared object; recompile with -fPIC /home/xrfang/Desktop/**paintrect/lib/x86_64-linux/**paintrect.o: æ— æ³•è¯»å –ç¬¦å ·: 错误的值 liboval.lpr(14) Error: Error while linking where æ— æ³•è¯»å –ç¬¦å ·: 错误的值 means cannot read symbol: illegal value. What's wrong here? Try adding -fPIC -dFPC_PIC into program's options, Other section Tha's what I use when building shared libraries. Antonio. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus