Lisp HUG Maillist Archive

Compiling libraries for LWM 32 on Mac OS X

Hi

I think I have a problem trying to use CFFI with LWM.

Basically I believe that I need to compile code for 32 bits as CFFI gives me the following error message:

CL-USER 9 > (cffi:use-foreign-library cl-autowrap-tests::cl-autowrap-tests-lib)

Error: Unable to load foreign library (CL-AUTOWRAP-TESTS-LIB).
  Could not register handle for external module CL-AUTOWRAP-TESTS::CL-AUTOWRAP-TESTS-LIB:
 no suitable image found.  Did find:
/Users/marcoxa/Projects/Lang/CL/tests/cl-autowrap/cl-autowrap-test.dylib: mach-o, but wrong architecture.
  1 (continue) Try loading the foreign library again.
  2 Use another library instead.
  3 (abort) Return to level 0.
  4 Return to top loop level 0.

Has anybody seen anything like this?

Which leads to the question: what are the clang incantations necessary to produce 32 dylib?  Note that passing -arch x86_32 or -arch i386 does not seem to work.  Also munging the -target argument does not seem to lead to a working dylib.

Thanks

Marco




--
Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01
DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY

Please check: http://cdac.lakecomoschool.org

Please note that I am not checking my Spam-box anymore.
Please do not forward this email without asking me first.





Re: Compiling libraries for LWM 32 on Mac OS X

Hi,

Try flag -m32
together with
-arch i386


Antoniotti Marco <antoniotti.marco@disco.unimib.it> writes:

> Hi 
>
> I think I have a problem trying to use CFFI with LWM.
>
> Basically I believe that I need to compile code for 32 bits as CFFI gives me the following error message:
>
> CL-USER 9 > (cffi:use-foreign-library cl-autowrap-tests::cl-autowrap-tests-lib)
>
> Error: Unable to load foreign library (CL-AUTOWRAP-TESTS-LIB).
> Could not register handle for external module CL-AUTOWRAP-TESTS::CL-AUTOWRAP-TESTS-LIB:
> no suitable image found. Did find:
> /Users/marcoxa/Projects/Lang/CL/tests/cl-autowrap/cl-autowrap-test.dylib: mach-o, but wrong
> architecture.
> 1 (continue) Try loading the foreign library again.
> 2 Use another library instead.
> 3 (abort) Return to level 0.
> 4 Return to top loop level 0.
>
> Has anybody seen anything like this?
>
> Which leads to the question: what are the clang incantations necessary to produce 32 dylib? Note that
> passing -arch x86_32 or -arch i386 does not seem to work. Also munging the -target argument does not
> seem to lead to a working dylib.
>
> Thanks
>
> Marco
>
> --
> Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01
> DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it
> Viale Sarca 336
> I-20126 Milan (MI) ITALY
>
> Please check: http://cdac.lakecomoschool.org
>
> Please note that I am not checking my Spam-box anymore.
> Please do not forward this email without asking me first.
>
>

-- 
Br,
/Alexey

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Compiling libraries for LWM 32 on Mac OS X

Sorry for the noise

$ c++ -dynamiclib cl-autowrap-test.cpp -o libcl-autowrap-test.dylib -arch i386 -arch x86_64

seem to work (the -arch x86_64 may be superfluous).

Cheers

MA




On Jun 14, 2016, at 16:26 , Antoniotti Marco <antoniotti.marco@disco.unimib.it> wrote:

Hi

I think I have a problem trying to use CFFI with LWM.

Basically I believe that I need to compile code for 32 bits as CFFI gives me the following error message:

CL-USER 9 > (cffi:use-foreign-library cl-autowrap-tests::cl-autowrap-tests-lib)

Error: Unable to load foreign library (CL-AUTOWRAP-TESTS-LIB).
  Could not register handle for external module CL-AUTOWRAP-TESTS::CL-AUTOWRAP-TESTS-LIB:
 no suitable image found.  Did find:
/Users/marcoxa/Projects/Lang/CL/tests/cl-autowrap/cl-autowrap-test.dylib: mach-o, but wrong architecture.
  1 (continue) Try loading the foreign library again.
  2 Use another library instead.
  3 (abort) Return to level 0.
  4 Return to top loop level 0.

Has anybody seen anything like this?

Which leads to the question: what are the clang incantations necessary to produce 32 dylib?  Note that passing  -arch x86_32 or -arch i386 does not seem to work.  Also munging the -target argument does not seem to lead to a working dylib.

Thanks

Marco




--
Marco Antoniotti, Associate Professor
tel. +39 - 02 64 48 79 01
DISCo, Università Milano Bicocca U14 2043
http://bimib.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY

Please check: http://cdac.lakecomoschool.org

Please note that I am not checking my Spam-box anymore.
Please do not forward this email without asking me first.






--
Marco Antoniotti, Associate Professor tel. +39 - 02 64 48 79 01
DISCo, Università Milano Bicocca U14 2043 http://bimib.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY

Please check: http://cdac.lakecomoschool.org

Please note that I am not checking my Spam-box anymore.
Please do not forward this email without asking me first.





Re: Compiling libraries for LWM 32 on Mac OS X

Antoniotti Marco <antoniotti.marco@disco.unimib.it> writes:

> Hi 
>
> I think I have a problem trying to use CFFI with LWM.
>
> Basically I believe that I need to compile code for 32 bits as CFFI
> gives me the following error message:
>
> CL-USER 9 > (cffi:use-foreign-library
> cl-autowrap-tests::cl-autowrap-tests-lib)
>
> Error: Unable to load foreign library (CL-AUTOWRAP-TESTS-LIB).
> Could not register handle for external module
> CL-AUTOWRAP-TESTS::CL-AUTOWRAP-TESTS-LIB:
> no suitable image found. Did find:
> /Users/marcoxa/Projects/Lang/CL/tests/cl-autowrap/cl-autowrap-test.dylib:
> mach-o, but wrong architecture.
> 1 (continue) Try loading the foreign library again.
> 2 Use another library instead.
> 3 (abort) Return to level 0.
> 4 Return to top loop level 0.
>
> Has anybody seen anything like this?
>
> Which leads to the question: what are the clang incantations necessary
> to produce 32 dylib? Note that passing -arch x86_32 or -arch i386 does
> not seem to work. Also munging the -target argument does not seem to
> lead to a working dylib.

i386 is a valid architecture on MacOSX (the other is x86_64).

Since you're on Darwin with Mach-O object and library file format, you
can also consider building a fat library including both 32-bit and
64-bit architectures, so that the same library file can be used by
different implementations requiring different architectures.


    lipo -create ${LIBNAME}-i386.dylib ${LIBNAME}-x86_64.dylib \
         -output ${LIBNAME}.dylib

----------------------------------------------------------------------------------
# Example GNU Makefile to generate compilation rules one per
# architecture:

ARCHS=x86_64 i386
DEFS=-DMACOSX
NAME=linear
COMPONENTS=linear  #list of object file names sans extension
VERSION=10.9
VERSION_CLANG=-mmacosx-version-min=$(VERSION)
VERSION_LIBTOOL=-macosx_version_min $(VERSION)
LIBS=-lc -lobjc -framework Foundation

define gen_compilation_rule
$(info # Generating compilation for $1-$2.o)
$1-$2.o : $1.m
	clang $(DEFS) $(VERSION_CLANG) -x objective-c -c -o $$@ -arch $2 $1.m
endef

define gen_link_rule
$(info # Generating link for lib$1-$2.dylib)
lib$1-$2.dylib : $$(foreach object,$3,$$(object)-$2.o)
	libtool -dynamic $$(foreach object,$3,$$(object)-$2.o) -o $$@ $(VERSION_LIBTOOL) $(LIBS)
endef

$(foreach component,$(COMPONENTS),$(foreach arch,$(ARCHS),$(eval $(call gen_compilation_rule,$(NAME),$(arch)))))
$(foreach arch,$(ARCHS),$(eval $(call gen_link_rule,$(NAME),$(arch),$(COMPONENTS))))

lib$(NAME).dylib:$(foreach arch,$(ARCHS),lib$(NAME)-$(arch).dylib)
	lipo -create $^ -output $@
	file $@

----------------------------------------------------------------------------------

And here is the result:


make -k clean liblinear.dylib
# Generating compilation for linear-x86_64.o
# Generating compilation for linear-i386.o
# Generating link for liblinear-x86_64.dylib
# Generating link for liblinear-i386.dylib
rm -f linear *.o *.dylib *~
clang -DMACOSX -mmacosx-version-min=10.9 -x objective-c -c -o linear-x86_64.o -arch x86_64 linear.m
libtool -dynamic linear-x86_64.o -o liblinear-x86_64.dylib -macosx_version_min 10.9 -lc -lobjc -framework Foundation
clang -DMACOSX -mmacosx-version-min=10.9 -x objective-c -c -o linear-i386.o -arch i386 linear.m
libtool -dynamic linear-i386.o -o liblinear-i386.dylib -macosx_version_min 10.9 -lc -lobjc -framework Foundation
lipo -create liblinear-x86_64.dylib liblinear-i386.dylib -output liblinear.dylib
file liblinear.dylib
liblinear.dylib: Mach-O universal binary with 2 architectures
liblinear.dylib (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64
liblinear.dylib (for architecture i386):	Mach-O dynamically linked shared library i386

Compilation finished at Tue Jun 14 20:57:04


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:32 UTC