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

[Linux, SDL_bgi 2.6.0] Error while linking: undefined reference to 'xkbhit' #1

Open
rchastain opened this issue Jan 31, 2023 · 4 comments

Comments

@rchastain
Copy link

rchastain commented Jan 31, 2023

Hello! Congratulations for this very nice project.

I installed on Linux SDL_bgi 2.6.0. When I try to compile an example from ubgi, I get this error:

[roland@localhost examples (master)]$ fpc -B -Fu.. exus.pas
Free Pascal Compiler version 3.2.0 [2020/07/05] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling exus.pas
exus.pas(3,2) Note: APPTYPE is not supported by the target OS
Compiling /home/roland/Documents/pascal/sources/ubgi/ubgi.pas
Linking exus
/usr/bin/ld : /home/roland/Documents/pascal/sources/ubgi/ubgi.o : dans la fonction « UBGI_$$_KEYPRESSED$$BOOLEAN » :
ubgi.pas:(.text.n_ubgi_$$_keypressed$$boolean+0xa) : référence indéfinie vers « kbhit »
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode

After taking a look into ubgi.pas, I tried this.

function KeyPressed(): Boolean;
begin
{$IFDEF LINUX}
  Result := XKbHit() <> 0;
{$ELSE}
  Result := KbHit() <> 0;
{$ENDIF}
end;

With that modification, I can compile the example. (But I understood later that it wasn't the correct solution. See correct solution below.)

@rchastain rchastain changed the title [Linux, SDL_bgi-2.6.0] Error while linking: undefined reference to 'xkbhit' [Linux, SDL_bgi 2.6.0] Error while linking: undefined reference to 'xkbhit' Jan 31, 2023
@rchastain
Copy link
Author

rchastain commented Jan 31, 2023

After I installed SDL_bgi 3.0.0.

With the original ubgi unit, I get the error undefined reference to kbhit. With the modified ubgi, I get undefined reference to xkbhit!

I don't know why my patch doesn't work with that version of the library.

@rchastain
Copy link
Author

Solution for SDL_bgi 3.0.0:

(*
  Returns 1 when a key is pressed, excluding special keys
  (Ctrl, Shift, etc.); in 'slow mode', a screen refresh is performed.
  If an SDL_QUIT event occurs, QUIT is returned.
*)
function KbHit(): Integer;
  cdecl; external LIB_UBGI name LIB_FNPFX + 'k_bhit';//'kbhit';

(*
  Returns 1 when any key is pressed, including special keys
  (Ctrl, Shift, etc.) in 'slow mode', a screen refresh is performed.
  If an SDL QUIT event occurs, QUIT is returned.
*)
function XKbHit(): Integer;
  cdecl; external LIB_UBGI name LIB_FNPFX + 'xkb_hit';//'xkbhit';

{ ... }

function KeyPressed(): Boolean;
begin
//{$IFDEF LINUX}
//  Result := XKbHit() <> 0;
//{$ELSE}
  Result := KbHit() <> 0;
//{$ENDIF}
end;

@rchastain
Copy link
Author

For 2.6.0, the solution was:

function KbHit(): Integer;
  cdecl; external LIB_UBGI name LIB_FNPFX + 'bgi_kbhit';//'kbhit';

{ ... }

function KeyPressed(): Boolean;
begin
//{$IFDEF LINUX}
//  Result := XKbHit() <> 0;
//{$ELSE}
  Result := KbHit() <> 0;
//{$ENDIF}
end;

@rchastain
Copy link
Author

Pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant