dylib failure

For the life of me, I blew 12 hours yesterday trying to get a dylib to work.

I have a SmartDongle and it works well with windows. On the Mac side, it comes with a libsmartdongle.dylib library.

But, if I use the example Xojo app and reference this library, I keep getting FunctionNotFound Exception, it cannot see any of the functions! The library is written in C, and uses LIBUSB.

So I downloaded the source code, had to make some serious changes in the makefile to support the later xcode running on my Sierra machine. I couldnt compile the i386 side of the code, but I was able to compile the X86_64 side though. Referenced the newly compiled library, nothing. Still function not found error!!

So to make sure I am not going entirely insane, I tried roughing up a quick and dirty Excel VBA app to reference the lib, I kept getting run time error 53, file not found. No matter where I stick that stupid dylib, nothing can see it! So I put the dylib with the App executable, and did a FolderItem get Item and it says its there. But, if I reference it in the Soft Declare, Function Not Found. I put that dylib everywhere I possibly could. disabled system integrity so I could dump it in /usr/lib, even dumped it in /usr/local/lib as well, dumped it in my Documents folder, Hard Drive root, and even the application directory. Nothing works!

The library is written in C and compiled in C, so the “Extern C” fix doesn’t apply here. And even if it did, its referenced in the Source Code. I took the original library and ran some command line tools on it to make sure the functions werent mangled, and they are not. Also, it IS in fact a universal binary with i386 and x86_64, No PowerPC code at all.

I am at a loss! Any ideas? Also if i compile the example C code that comes with the dylib source code, I can access the dongle no problem. but Xojo just wont take this dylib whatsoever. As a last-ditch effort, I tried setting the Environment to compile in 64-bit mode instead of 32 but it made no difference.

I grabbed a MacBook Air which is still on 10.10 instead of 10.12, and all the same problems still exist. What I cannot understand is the App compiles with a bunch of its own Dylibs for the Xojo framwork, etc. and obviously those work or the App wouldnt run! I dont get it…

I would attach the Dylib, but I dont see an attach function. You can however, get it here:

Any thoughts on this? No matter how hard I try, I just cannot get any of the subroutines in that particular dylib to register to Xojo.

The libsmartdongle.dylib might have dependencies on other libraries or frameworks relative to the folder it is placed. In that case it would have to be installed in the correct folder, not in an arbitrary one.

When you try to load the dylib with dlopen you get the error message “image not found” which is an indication for that.

  1. you need to put the dylib in the right location in the debug application
  • a copy file step that copies it to the frameworks folder is needed
  1. the path to the dylib is wrong

try this

Thanks for the replies.

However, I remember sticking the dylib in the Frameworks folder when I “view contents” of the compiled app itself. And I tried the same @executable_path and it gave me a function not found error.

I will try it again with your zip file just to make positively sure.

Also the Read Me file says this library depends on LIBUSB which hast to be installed. So I installed it the only way the internet tells me how, and thats using brew. Maybe there is another way? I dont know.

well I altered it and ran it an did not get a function not found so …

Well I will give it a shot.

So where do I put the dylib?

See my previous post that said exactly where it should go and how to get it there

[quote=339565:@Norman Palardy]1) you need to put the dylib in the right location in the debug application

  • a copy file step that copies it to the frameworks folder is needed
  1. the path to the dylib is wrong

try this

The path is fixed in the project I posted
And there’s a copy file step in there as well
You should be able to download, decompress it and open in the IDE and hit run

I just now downloaded it and tried. FunctionNotFoundException.

no idea
downloaded it
unzipped it
opened it in 2017r1.1
tried every button and not one function not found error

In case it helps, I am running a Late 2011 Macbook with MacOS 10.12.5 Sierra. And I am running the latest version of Xojo…

When I click a button, that little red spider looking bug pops up with this:

Could not load SmartDongleLedRed from @executable_path/…/Frameworks/libsmartdongle.dylib.

I guess there is a blackhole in this machine. Ready to ditch mac and go back to PC.

That message means that for some reason the dylib is still not in the right place
Examine the CopyFileStep in the Mac OS Target under Build Settings
Make sure it is set like

JUST to be sure use Project > Run Paused
The IDE will build the debug version of the app and reveal it
Right click on the Debug app and Select “Show Package Contents”
Then navigate to Contents > Frameworks and make sure libsmartdongle.dylib IS in there
If so then navigate back up to where the debug app is and double click it so it runs

I dont have a webserver available to drop images, so I tossed it my drive.


sure looks like its in the right spot

Yea I know, but something is wrong somewhere. What machine and OS are you running? Maybe somethings screwed up on my end. I did a disk utility firstaid and came back clean. So hmmmm

On 10.11.6 this works fine
Not 10.12 (which I just tried)
The only thing I can see that seems like it might be an issue is the dylib contains both 32 and 64 bit code
What happens if you compile JUST for 32 bit and debug as 32 bit ?

I’m back. I wiped this machine out and reinstalled a base copy of Sierra with Xojo and it did the same thing. Just saw your post.

I cant compile for just 32 bit because I cant install LIBUSB for 32-bit. if I use MacPORTS which installs LIBUSB-Legacy that this lib depends on, only downloads the x86_64 portion of it and not the i386 version. And I am not sure how to fix this?

I can probably split the existing library apart into its 32 and 64 counterparts? I think the Xcode command line tools have something that can do this.

used lipo to extract the i386 out of the dylib, Same thing. FunctionNotFound. I even tried the 64 bit only, and universal, and changed to x86 64 build in the compiler. Nothing.

I wonder what they did in Sierra to prevent this from working… hmm…

FIXED IT! Almost…

Had to re-compile the dylib as a 64-bit only library using latest xcode and latest command line tools with libusb, I already did this once previously before I formatted this machine.

Grabbed the 64-bit ONLY dylib, and renamed it, used your zip that does the copy and reference, and set the Architecture to x86 64-bit for build.

That worked, I can query the serial number of the dongle! BUT… a big BUT, if I do any kind of read, it will crash on a SIGSEGV fault.

Process:               My Application.debug [1619]
Path:                  /Users/USER/Desktop/*/My Application.debug.app/Contents/MacOS/My Application.debug
Identifier:            com.mycompany.MyApplication
Version:               ??? (
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           My Application.debug [1619]
User ID:               501

Date/Time:             2017-07-09 10:31:20.457 -0400
OS Version:            Mac OS X 10.12.1 (16B2657)
Report Version:        12
Anonymous UUID:        830E9B50-AA02-CCB2-1FEF-17012FA78591

Time Awake Since Boot: 6000 seconds

System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

Application Specific Information:
Performing @selector(performClick:) from sender XOJButton 0x60000015c9e0

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_c.dylib             	0x00007fffbfd90b52 strlen + 18
1   XojoFramework                 	0x000000010d4f246c StringFromCString + 45
2   My Application.debug          	0x000000010d275238 SmartDongle.checkDongle%s% + 4552 (/SmartDongle:106)
3   My Application.debug          	0x000000010d266908 Window1.Window1.btnCheckValid_Action%%o<Window1.Window1>o<PushButton> + 280 (/Window1:135)
4   My Application.debug          	0x000000010d26c455 Delegate.IM_Invoke%%o<PushButton> + 53
5   My Application.debug          	0x000000010d26c4c4 AddHandler.Stub.15%% + 52
6   libsystem_trace.dylib         	0x00007fffbff8cc41 _os_activity_initiate + 61
7   com.apple.AppKit              	0x00007fffa8d5b770 -[NSApplication(NSResponder) sendAction:to:from:] + 456
8   com.apple.AppKit              	0x00007fffa88440d8 -[NSControl sendAction:to:] + 86
9   com.apple.AppKit              	0x00007fffa8844000 __26-[NSCell _sendActionFrom:]_block_invoke + 136
10  libsystem_trace.dylib         	0x00007fffbff8cc41 _os_activity_initiate + 61
11  com.apple.AppKit              	0x00007fffa8843f58 -[NSCell _sendActionFrom:] + 128
12  com.apple.AppKit              	0x00007fffa88868d9 -[NSButtonCell _sendActionFrom:] + 98
13  libsystem_trace.dylib         	0x00007fffbff8cc41 _os_activity_initiate + 61
14  com.apple.AppKit              	0x00007fffa884283c -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481
15  com.apple.AppKit              	0x00007fffa8886616 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798
16  com.apple.AppKit              	0x00007fffa88411f7 -[NSControl mouseDown:] + 832
17  XojoFramework                 	0x000000010d3865bb 0x10d343000 + 275899
18  com.apple.AppKit              	0x00007fffa8ed191f -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341
19  com.apple.AppKit              	0x00007fffa8ece13c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942
20  com.apple.AppKit              	0x00007fffa8ecd5da -[NSWindow(NSEventRouting) sendEvent:] + 541
21  XojoFramework                 	0x000000010d391ebe 0x10d343000 + 323262
22  com.apple.AppKit              	0x00007fffa8d576f5 -[NSApplication(NSEvent) sendEvent:] + 1145
23  XojoFramework                 	0x000000010d38196c 0x10d343000 + 256364
24  My Application.debug          	0x000000010d245ba7 Delegate.Invoke%% + 7
25  My Application.debug          	0x000000010d1b6621 Application._CallFunctionWithExceptionHandling%%o<Application>p + 273
26  XojoFramework                 	0x000000010d4e64e5 0x10d343000 + 1717477
27  XojoFramework                 	0x000000010d3818e6 0x10d343000 + 256230
28  com.apple.AppKit              	0x00007fffa85d70b9 -[NSApplication run] + 1002
29  XojoFramework                 	0x000000010d4e489b RuntimeRun + 40
30  My Application.debug          	0x000000010d2221f8 REALbasic._RuntimeRun + 24
31  My Application.debug          	0x000000010d279540 _Main + 848 (/#main:86)
32  My Application.debug          	0x000000010d278911 main + 65
33  My Application.debug          	0x000000010d178ad4 start + 52

Thread 1:
0   libsystem_kernel.dylib        	0x00007fffbfe894e6 __workq_kernreturn + 10
1   libsystem_pthread.dylib       	0x00007fffbff717b5 _pthread_wqthread + 1426
2   libsystem_pthread.dylib       	0x00007fffbff71211 start_wqthread + 13

Thread 2:
0   libsystem_kernel.dylib        	0x00007fffbfe894e6 __workq_kernreturn + 10
1   libsystem_pthread.dylib       	0x00007fffbff71622 _pthread_wqthread + 1023
2   libsystem_pthread.dylib       	0x00007fffbff71211 start_wqthread + 13

Thread 3:
0   libsystem_kernel.dylib        	0x00007fffbfe894e6 __workq_kernreturn + 10
1   libsystem_pthread.dylib       	0x00007fffbff717b5 _pthread_wqthread + 1426
2   libsystem_pthread.dylib       	0x00007fffbff71211 start_wqthread + 13

Thread 4:
0   libsystem_kernel.dylib        	0x00007fffbfe894e6 __workq_kernreturn + 10
1   libsystem_pthread.dylib       	0x00007fffbff717b5 _pthread_wqthread + 1426
2   libsystem_pthread.dylib       	0x00007fffbff71211 start_wqthread + 13

Thread 5:
0   libsystem_kernel.dylib        	0x00007fffbfe894e6 __workq_kernreturn + 10
1   libsystem_pthread.dylib       	0x00007fffbff717b5 _pthread_wqthread + 1426
2   libsystem_pthread.dylib       	0x00007fffbff71211 start_wqthread + 13

Thread 6:: com.apple.NSEventThread
0   libsystem_kernel.dylib        	0x00007fffbfe8141a mach_msg_trap + 10
1   libsystem_kernel.dylib        	0x00007fffbfe80867 mach_msg + 55
2   com.apple.CoreFoundation      	0x00007fffaaa51ae4 __CFRunLoopServiceMachPort + 212
3   com.apple.CoreFoundation      	0x00007fffaaa50f61 __CFRunLoopRun + 1361
4   com.apple.CoreFoundation      	0x00007fffaaa507b4 CFRunLoopRunSpecific + 420
5   com.apple.AppKit              	0x00007fffa872f7d4 _NSEventThread + 205
6   libsystem_pthread.dylib       	0x00007fffbff71aab _pthread_body + 180
7   libsystem_pthread.dylib       	0x00007fffbff719f7 _pthread_start + 286
8   libsystem_pthread.dylib       	0x00007fffbff71221 thread_start + 13

Thread 7:
0   libsystem_kernel.dylib        	0x00007fffbfe894e6 __workq_kernreturn + 10
1   libsystem_pthread.dylib       	0x00007fffbff717b5 _pthread_wqthread + 1426
2   libsystem_pthread.dylib       	0x00007fffbff71211 start_wqthread + 13

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x000000010d5fc430  rbx: 0x6961662074736f48  rcx: 0x6961662074736f48  rdx: 0x6961662074736f48
  rdi: 0x6961662074736f40  rsi: 0x0000000000000007  rbp: 0x00007fff52a86400  rsp: 0x00007fff52a86400
   r8: 0x0000000000000007   r9: 0x00007fffc8b1e2c8  r10: 0x000000010ff99100  r11: 0x000000010d4f243f
  r12: 0x00007fff52a867a0  r13: 0x00007fff52a867b0  r14: 0x0000000000000600  r15: 0x00007fff52a86790
  rip: 0x00007fffbfd90b52  rfl: 0x0000000000010202  cr2: 0x000000010d275021
Logical CPU:     2
Error Code:      0x00000000
Trap Number:     13

Model: MacBookPro8,1, BootROM MBP81.0047.B32, 2 processors, Intel Core i5, 2.4 GHz, 4 GB, SMC 1.68f98
Graphics: Intel HD Graphics 3000, Intel HD Graphics 3000, Built-In
Memory Module: BANK 0/DIMM0, 2 GB, DDR3, 1333 MHz, 0x80CE, 0x4D34373142353737334448302D4348392020
Memory Module: BANK 1/DIMM0, 2 GB, DDR3, 1333 MHz, 0x80CE, 0x4D34373142353737334448302D4348392020
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0xD6), Broadcom BCM43xx 1.0 (
Bluetooth: Version 5.0.1f7, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en1
Serial ATA Device: Samsung SSD 850 EVO 250GB, 250.06 GB
Serial ATA Device: HL-DT-ST DVDRW  GS31N
USB Device: USB 2.0 Bus
USB Device: Hub
USB Device: Expansion
USB Device: IR Receiver
USB Device: USB 2.0 Bus
USB Device: FaceTime HD Camera (Built-in)
USB Device: Hub
USB Device: Apple Internal Keyboard / Trackpad
USB Device: SmartDongle Security Key
USB Device: BRCM2070 Hub
USB Device: Bluetooth USB Host Controller
Thunderbolt Bus: MacBook Pro, Apple Inc., 25.1