#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Learning to compile a C extension (linux/newb)


    I want to learn how to play with this code package because I ultimately want to compile it for Python 3.x

    GIT: github.com/engla/keybinder
    tarball: kaizer.se/publicfiles/keybinder/keybinder-3.0-0.3.0.tar.gz
    homepage: kaizer.se/wiki/keybinder/

    But I am super confused as to how the Python part of the compilation works. I've been trying for about 2 straight days now (minus sleep) attempting to figure it out. But so many files get generated by various tools like autoconfig. The Python specific files seems to be located here hgithub.com/engla/keybinder/tree/master/python-keybinder but some of those files don't even look like C or Python. It seems like when you run the configure script for the entire package there is a file named _keybinder.c which gets generated, and I think that is the file that ultimately gets compiled, and I have tried creating my own setup.py file for it but I must be missing certain library links.

    I wish I knew how to take the data which is there, create my own keybinder.c file and my own setup.py script so that I can modify and re-compile specifically the Python/C extension. But at this point, I have no idea how what is in this package becomes a .so file in /usr/local/lib/python2.7/dist-packages/ that I can and have successfully experimented with.

    The closest I have gotten I think think is this C file: pastebin.com/raw.php?i=CuqhsSHK
    and this setup.py file: pastebin.com/raw.php?i=hNtAEy8q

    There is a lot here, and I don't expect that anyone will do this work for me, besides, I want to learn how anyway after all this effort, but I'd highly appreciate some direction. I feel like what I'm trying to accomplish would take some one in the know 2 minutes not two days but I'm sitting here randomly trying stuff hoping that it will work.

    Thank You.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    I tried to build the package following the README instruction and found an error in the examples Makefile. The order of files presented to the loader matters, and the Makefile put main after all the libraries instead of before them. Below is corrected Makefile and use of the new program main. Please report the change back to the project. Thanks, Dave.
    Code:
    $ ./configure
    $ make
    $ sudo make install
    $ cd examples/
    $ make main   # this works on my system with repaired Makefile
    $ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./main
    I then tried to run the example python program which didn't work, and I didn't investigate. Otherwise, I ignored your message.
    Code:
    GTKPKG = gtk+-3.0
    KEYBPKG = keybinder-3.0
    GTK_CFLAGS = $(shell pkg-config --cflags $(GTKPKG))
    GTK_LDFLAGS = $(shell pkg-config --libs $(GTKPKG))
    
    LUA_CFLAGS = $(shell pkg-config --cflags lua5.1)
    LUA_LDFLAGS = $(shell pkg-config --libs lua5.1)
    
    KEYB_FLAGS = $(shell pkg-config --cflags --libs $(KEYBPKG))
    
    CFLAGS ?= -g -O2
    
    VALAC = valac
    
    all: main lua vala
    
    lua: minigtk.so keybinder.so
    
    # Example C program with libkeybinder
    # Following shell command rearranged by b49p23tivg
    main: main.c
    	$(CC) $(CFLAGS) $< $(KEYB_FLAGS) -o $@
    
    # Lua "minigtk" library
    keybinder.so: lkeybinder.c
    	$(CC) $(KEYB_FLAGS) $(CFLAGS) \
    		$(LUA_CFLAGS) $(LUA_LDFLAGS) $< -shared -o $@
    
    minigtk.so: lminigtk.c
    	$(CC) $(GTK_CFLAGS) $(GTK_LDFLAGS) \
    		$(LUA_CFLAGS) $(LUA_LDFLAGS) $< -shared -o $@
    
    vala: vexample
    
    vexample: vexample.vala keybinder.vapi
    	$(VALAC) --pkg $(GTKPKG) --pkg keybinder --vapidir=. $<
    
    clean:
    	rm -f *.so *.lo main vexample
    
    .PHONY: clean all lua vala
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo