dylib failure

Just to mention, the lipo extracted x86_64 produced the same FunctionNotFound. The re-compiled version was the only one that ran, albeit crashing.

Just in case anyone is curious, Here is my makefile:

CC = gcc 
CFLAGS = -O -Wall
MACLIB = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

all:  example1 example2a example2b example3a example3b example4

example1: example1.c smartdongle aes
	$(CC) $(CFLAGS) /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices  -o $@ $< smartdongle.o

example2a: example2a.c smartdongle
	$(CC) $(CFLAGS) /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices -o $@ $< smartdongle.o

example2b: example2b.c smartdongle
	$(CC) $(CFLAGS) /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices -o $@ $< smartdongle.o

example3a: example3a.c smartdongle aes
	$(CC) $(CFLAGS) /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices -o $@ $< aes.o smartdongle.o

example3b: example3b.c smartdongle aes
	$(CC) $(CFLAGS) /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices -o $@ $< aes.o smartdongle.o

example4: example4.c smartdongle
	$(CC) $(CFLAGS) /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices -o $@ $< smartdongle.o

smartdongle: smartdongle.c 
	$(CC) $(CFLAGS) -c $<

aes: aes.c
	$(CC) -c $<

# Test for AES
test:
	$(CC) -DAES_TEST aes.c -o $@
	- ./test

maclibrary:
	#$(CC) $(CFLAGS) -m32 -fPIC -c $(MACLIB) smartdongle.c -o smartdongle.o
	#$(CC) $(CFLAGS) -m32 -fPIC -c $(MACLIB) aes.c -o aes.o
	#$(CC) -m32 $(MACLIB) smartdongle.o aes.o -o libsmartdongle_32.dylib -dynamiclib /opt/local/lib/libusb-legacy/libusb-legacy.a 
	$(CC) $(CFLAGS) -m64 -fPIC -c $(MACLIB) smartdongle.c -o smartdongle.o
	$(CC) $(CFLAGS) -m64 -fPIC -c $(MACLIB) aes.c -o aes.o
	$(CC) -m64 $(MACLIB) smartdongle.o aes.o -o libsmartdongle_64.dylib -dynamiclib /opt/local/lib/libusb-legacy/libusb-legacy.a -framework IOKit -framework CoreFoundation -framework CoreServices
	#lipo -create libsmartdongle_32.dylib libsmartdongle_64.dylib -o libsmartdongle.dylib
	#rm -f libsmartdongle_32.dylib
	#rm -f libsmartdongle_64.dylib

linuxlibrary:
	$(CC) $(CFLAGS) -m32 -fPIC -c smartdongle.c -o smartdongle.o
	$(CC) $(CFLAGS) -m32 -fPIC -c aes.c -o aes.o
	$(CC) -m32 smartdongle.o aes.o -o libsmartdongle_32.so -shared -lusb
	$(CC) $(CFLAGS) -m64 -fPIC -c smartdongle.c -o smartdongle.o
	$(CC) $(CFLAGS) -m64 -fPIC -c aes.c -o aes.o
	$(CC) -m64 smartdongle.o aes.o -o libsmartdongle_64.so -shared -lusb

clean:
	rm -f  *.o *.so *.dylib example1 example2a example2b example3a example3b example4

Its fully functional now! Turns out that if the P1/P2 keys are wrong (Specific to each dongle), it causes the SIGSEGV crash. It does NOT do this on windows, so I find that strange. Anyways…

Its working now :slight_smile:

Having to compile & run as 64 bit when you have a 64 bit dylib makes sense
32 bit apps cant load 64 bit dylibs/dlls and 64 bit apps cant load & use 32 bit dylibs/dlls
This isn’t unique to OS X

Sure, but when I export the 32 bit dylib, and compile 32 bit xojo it doesnt work.

Something about this specific config does work. However, I cant figure out the crashes. if the dongle isnt present it will crash as well when I hit a button.

Only way to avoid a crash is if the dongle is present and the keys are correct. It shouldnt do that.

could be some dependent lib missing for 32 bit
have you run otool -L on the dylib to see if thats the case ?
however, OS X is moving to requiring 64 bit apps in the near future so I’m not sure I would worry about 32 bit at all

No, I have not tried otool.

But just when I thought I had this nipped in the bud, that FunctionNotFound exception rears its ugly head again.

So, my ultimate project is a Console app. So, I created the copyfile thing, dragged the dylib in there, it says Frameworks in the dropdown box. And changed the MacLib constant to match what you had.

FunctionNotFound again. I checked my “Libs” folder that it creates for the console app, and it shows the dylib in there. But my guess is the @executable_path thing is wrong for Console apps.

Here is my otool -L output: (This is the supplied dylib, not my recompiled one)

Mikes-MacBook-Pro:SmartDongle libusb 0.15 mbates14$ otool -L libsmartdongle.dylib
libsmartdongle.dylib:
	libsmartdongle_64.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/local/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.5.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 830.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
Mikes-MacBook-Pro:SmartDongle libusb 0.15 mbates14$ 

Whats funny is it shows libusb-0.1.4.dylib as in that folder, and as current version 9.5.0, but if I “ls” that folder in terminal, there isnt anything there.

ls /usr/local/lib/libusb* ???
it better be there

for a console app the path would be different