Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

Commit

Permalink
Maintenance patch. Haven't touched this in a while, and apparently
Browse files Browse the repository at this point in the history
something changed on my workstation, because native modules would
no longer import. See pymex.c for more details.
  • Loading branch information
Ken Watford committed Mar 23, 2010
1 parent e73cee2 commit d9149a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ MATLAB_SCRIPT ?= matlab
TMW_ROOT ?= $(shell ${MATLAB_SCRIPT} -e | grep MATLAB= | sed s/^MATLAB=//)

CFLAGS=$(shell ${PYTHON}-config --cflags)
CLIBS=$(shell ${PYTHON}-config --libs)
LDFLAGS=$(shell ${PYTHON}-config --ldflags) -L$(shell ${PYTHON}-config --prefix)/lib
CLIBS=
#CLIBS=$(shell ${PYTHON}-config --libs)
LDFLAGS=$(shell ${PYTHON}-config --ldflags)
#-L$(shell ${PYTHON}-config --prefix)/lib

#CFLAGS=%CFLAGS%
#CLIBS=%CLIBS%
#LDFLAGS=%LDFLAGS%

BUILDBRANCH = $(shell git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
ifeq ($(BUILDBRANCH),)
Expand Down Expand Up @@ -44,11 +50,11 @@ ${TARGET}: pymex.c sharedfuncs.c commands.c *module.c pymex.h .debug_${DEBUG}
@rm -f .debug_0
@touch .debug_1

test: ${TARGET} *.py
test: $(TARGET) *.py
${MATLAB_SCRIPT} -nojvm -nodisplay \
-r "pyimport nose; exit(unpy(~nose.run()));"

.PHONY: clean
.PHONY: clean test

clean:
rm -f .debug_* pymex.mex*
Expand Down
16 changes: 16 additions & 0 deletions pymex.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
or do `c = pymex` for a list. */
#include "pymex.h"
#include <mex.h>
#include <dlfcn.h>
#define XMACRO_DEFS "commands.c"

/* Macros used during x-macro expansion. */
Expand Down Expand Up @@ -68,6 +69,21 @@ static void ExitFcn(void) {

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
if (!Py_IsInitialized()) {
/*
This dlopen is currently needed because I have
recently been unable to import python shared
library modules (like, say, numpy). I spent half
a day staring at ld's manpage and trying various
combinations to no avail. I even managed to compile
against the static libpython2.6-pic.a and could
verify the presence and globalness of the symbols,
but could not determine a way to get the loaded
libraries to actually use them.
Should probably make this line configurable in the
makefile... later.
*/
dlopen("libpython2.6.so", RTLD_LAZY | RTLD_GLOBAL);
Py_Initialize();
PYMEX_DEBUG("[python: initialized]\n");
initmexmodule();
Expand Down
5 changes: 5 additions & 0 deletions test_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from nose.tools import *
from nose.plugins.skip import SkipTest

def test_import():
import numpy

0 comments on commit d9149a5

Please sign in to comment.