How to debug issues with shared library libBearLibTerminal.dylib lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- d-_-b · 2019-08-09 14:04 So I got BearLibTerminal working on linux and windows using the prebuilt shared library, but with no success on macos. I'm using their pascal interface in my unit and after figuring out the `-k'-lBearLibTerminal'` switch to tell linker where to find the dylib I can compile my program on macos but it raises a exception if I try to execute it, as seen below: Code: [Select]air:tui d-_-b$ fpc -k-t -k'-lBearLibTerminal' -B -Mobjfpc engine.lpr Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64 Copyright (c) 1993-2017 by Florian Klaempfl and others Target OS: Darwin for x86_64 Compiling engine.lpr Compiling bltcrt.pas Compiling BearLibTerminal.pas Assembling (pipe) BearLibTerminal.s bltcrt.pas(32,3) Note: Local variable "r" is assigned but never used bltcrt.pas(40,3) Note: Local variable "r" is assigned but never used Assembling (pipe) bltcrt.s Compiling input_handlers.pas Assembling (pipe) input_handlers.s Compiling entity.pas Assembling (pipe) entity.s Compiling render_functions.pas Compiling map_objects.pas map_objects.pas(122,6) Note: Local variable "j" not used Assembling (pipe) map_objects.s Assembling (pipe) render_functions.s Compiling fov_functions.pas Assembling (pipe) fov_functions.s Compiling game_states.pas Assembling (pipe) game_states.s Assembling (pipe) engine.s Linking engine ./libBearLibTerminal.dylib /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.10.5. o engine.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/objpas.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/system.o bltcrt.o input_handlers.o entity.o render_functions.o map_objects.o fov_functions.o game_states.o BearLibTerminal.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/types.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/math.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/unix.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/sysutils.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/errors.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/sysconst.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/unixtype.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/baseunix.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/sysctl.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/unixutil.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/initc.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/ctypes.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/classes.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/typinfo.o /usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/rtlconsts.o /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib//libc.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib cache.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib commonCrypto.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib compiler_rt.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib copyfile.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib corecrypto.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib dispatch.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib dyld.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib keymgr.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib launch.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib macho.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib quarantine.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib removefile.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_asl.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_blocks.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_c.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_configuration.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_coreservices.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_darwin.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_dnssd.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_info.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_kernel.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_m.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_malloc.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_networkextension.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_notify.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_platform.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_pthread.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_sandbox.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_secinit.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_symptoms.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib system_trace.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib unwind.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/lib xpc.tbd 1567 lines compiled, 1.2 sec 3 note(s) issued air:tui d-_-b$ ./engine An unhandled exception occurred at $00007FFF441DE132: EInvalidOp: Invalid floating point operation   $00007FFF441DE132   $00007FFF441DDF78   $00007FFF2E5348B1   $00007FFF2E534856   $00007FFF2E533BBB   $00007FFF2E53065A   $00007FFF2E53015E   $00007FFF2E52FBA2   $00007FFF2E52FB3A   $00007FFF2E4FD8D9   $00007FFF2E4FCC16   $00007FFF2E4FCA9C   $00007FFF2E52F6AD   $00007FFF2E52F111   $00007FFF2E52F35F   $00007FFF2E52EB63   $00007FFF2E52E7F0 I also built their library from source on my machine using cmake and xcode, but that also did not resolve the issue. Any insight or suggestions? Thanks, Edit: Finally got it to work in laz-ide. Shows this error(screenshot cmd+c does not seem to copy the text) and then the assembler window breaks here: Code: [Select]00007FFF441DE122                          : 66 0f 28 0d 56 32 0c 00  movapd 0xc3256(%rip), %xmm1      ; __ASTC_encodeToData.backgroundColor + 94 00007FFF441DE12A                          : 66 0f 57 cb              xorpd  %xmm3, %xmm1 00007FFF441DE12E                          : 66 0f 28 e3              movapd %xmm3, %xmm4 00007FFF441DE132                          : f2 0f 51 c9              sqrtsd %xmm1, %xmm1 Call stack: Code: [Select]#0 CUIRenderer::Draw at :-1 #1 CUIDraw at :-1 #2 _HIThemeCUIDrawWithOptions at :-1 #3 _HIThemeCUIDrawWithRenderer at :-1 #4 _HIThemeDrawAppleMenuTitle at :-1 #5 HIMenuBarView::DrawOnce at :-1 #6 HIMenuBarView::DrawSelf at :-1 #7 HIMenuBarView::DrawWithoutCustomization at :-1 #8 HIMenuBarView::DrawingDelegateHandler at :-1 #9 DispatchEventToHandlers at :-1 To make sure the issue is related to fpc and not a problem with the library im using i tested the python package bearlibterminal-0.15.7-py2.py3-none-macosx_10_9_universal.whl and created a hello world application that works. ---------------------------------------------------------------------- Jonas Maebe · 2019-08-09 15:22 Quote from: d-_-b on August 09, 2019, 04:04:22 pmSo I got BearLibTerminal working on linux and windows using the prebuilt shared library, but with no success on macos. I'm using their pascal interface in my unit and after figuring out the `-k'-lBearLibTerminal'` It's better to add {$linklib BearLibTerminal} to your source code instead. Quoteair:tui d-_-b$ ./engine An unhandled exception occurred at $00007FFF441DE132: EInvalidOp: Invalid floating point operation FPC enables all floating point exceptions by default, because that's what Delphi does and what Pascal programmers expect. Much C code is written with the assumption that all floating point exceptions are disabled. If you need to make use of a C library that triggers floating point exceptions, include the "Math" unit and call SetExcepti onMask([exDenormalized,exInvalidOp,exOverflow,exPrecision,exUnderflow, exZeroDivide]); Note that this will also disable any floating point exceptions in your Pascal code, as this changes a CPU configuration register. ---------------------------------------------------------------------- d-_-b · 2019-08-09 16:00 Quote from: Jonas Maebe on August 09, 2019, 05:22:06 pmMuch C code is written with the assumption that all floating point exceptions are disabled. If you need to make use of a C library that triggers floating point exceptions, include the "Math" unit and call SetExcepti onMask([exDenormalized,exInvalidOp,exOverflow,exPrecision,exUnderflow, exZeroDivide]); Sweet! Added the Math unit and called SetExceptionMask as recommend and now it works!