Building a python module and linking it against a MacOSX framework

前端 未结 5 1698
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 05:46

I\'m trying to build a Python extension on MacOSX 10.6 and to link it against several frameworks (i386 only). I made a setup.py file, using distutils and the Extension object.

5条回答
  •  孤城傲影
    2021-02-19 06:32

    I just ran into this myself. I had to bypass distutils, because they appear to hard-code the -undefined dynamic_lookup. Here is the Makefile I'm using to emulate distutils:

    CC = gcc
    CFLAGS = -pipe -std=c99 -fno-strict-aliasing -fno-common -dynamic -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Werror -pedantic -Wall -Wstrict-prototypes -Wshorten-64-to-32 -g -Os -arch i386 -arch x86_64 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
    LD = gcc
    LDFLAGS = -Wl,-F. -bundle -Wl,-F. -arch i386 -arch x86_64 -framework CoreFoundation -framework CoreMIDI -framework Python
    
    project = 
    library = $(project).so
    modules = 
    sources = $(foreach module,$(modules),$(module).c)
    objects = $(sources:.c=.o)
    
    all: $(library)
    
    $(library): $(objects)
        $(LD) $(LDFLAGS) $(objects) -o $@
    
    %.o: %.c Makefile
        $(CC) $(CFLAGS) $< -c -o $@
    
    install: $(library)
        cp $(library) /Library/Python/2.7/site-packages
    
    clean:
            rm -f $(library) $(objects) *~
    

    I'm sure there is a way to get distutils to stop emitting that -undefined argument, but the above worked for me on 10.7

提交回复
热议问题