From: Krzysztof Kobus on
Hi,

I have a problem with linking python module with my application on mac in order to make the module available in "embedded python".

My python module is contained in j3kmodule.cxx file and module initialization function is exported in j3kmodule.h

j3kmodule.h:
------------
PyMODINIT_FUNC PyInit_j3k(void);


j3kmodule.cxx:
--------------
PyMODINIT_FUNC
PyInit_j3k(void)
{
PyObject *m = NULL;

if ((m = PyModule_Create(&j3k_module)) == NULL)
return NULL;

return m;
}


Then in my application in KkPython.cxx file I have:

KkPython.cxx:
-------------

#include "j3kmodule.h"

/* Add a builtin module, before Py_Initialize */
PyImport_AppendInittab("j3k", PyInit_j3k);


I link my application with the module and get following linking error on mac although on open suse linux exactly the same procedure works fine:

g++ -headerpad_max_install_names -o ../../bin/render.app/Contents/MacOS/render main.o KkPython.o -lkkbase -L/Users/kk/dev/J3K/trunk/j3ksrc/examples/render/../../lib/ -lQtSolutions_PropertyBrowser-2.5 -lpython3.1 /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so -framework OpenGL -framework AGL
ld: warning in /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so, file is not of required architecture
Undefined symbols:
"_PyInit_j3k", referenced from:
_PyInit_j3k$non_lazy_ptr in KkPython.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [../../bin/render.app/Contents/MacOS/render] Error 1


I appreciate any hints,

best greetings,

Krzysztof Kobus



From: Benjamin Kaplan on
On Tue, Jan 5, 2010 at 7:33 AM, Krzysztof Kobus <kk720801(a)yahoo.com> wrote:
> Hi,
>
> I have a problem with linking python module with my application on mac in order to make the module available in "embedded python".
>
> My python module is contained in  j3kmodule.cxx file and module initialization function is exported in j3kmodule.h
>
> j3kmodule.h:
> ------------
> PyMODINIT_FUNC PyInit_j3k(void);
>
>
> j3kmodule.cxx:
> --------------
> PyMODINIT_FUNC
> PyInit_j3k(void)
>  {
>  PyObject *m = NULL;
>
>  if ((m = PyModule_Create(&j3k_module)) == NULL)
>    return NULL;
>
>  return m;
>  }
>
>
> Then in my application in KkPython.cxx file I have:
>
> KkPython.cxx:
> -------------
>
> #include "j3kmodule.h"
>
> /* Add a builtin module, before Py_Initialize */
> PyImport_AppendInittab("j3k", PyInit_j3k);
>
>
> I link my application with the module and get following linking error on mac although on open suse linux exactly the same procedure works fine:
>
> g++ -headerpad_max_install_names -o ../../bin/render.app/Contents/MacOS/render main.o KkPython.o -lkkbase -L/Users/kk/dev/J3K/trunk/j3ksrc/examples/render/../../lib/ -lQtSolutions_PropertyBrowser-2.5 -lpython3.1 /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so -framework OpenGL -framework AGL
> ld: warning in /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so, file is not of required architecture
> Undefined symbols:
>  "_PyInit_j3k", referenced from:
>      _PyInit_j3k$non_lazy_ptr in KkPython.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> make: *** [../../bin/render.app/Contents/MacOS/render] Error 1
>
>
> I appreciate any hints,
>
> best greetings,
>
> Krzysztof Kobus
>

Well, it seems that one of your files is a different architecture than
the others. Based on the location, I'd say it's i386 while the rest of
it would be PowerPC. You can cross-compile but you can't link an i386
library to a PowerPC library.
From: Krzysztof Kobus on
Hi,


> > Well, it seems that one of your files is a different architecture than
> > the others. Based on the location, I'd say it's i386 while the rest of
> > it would be PowerPC. You can cross-compile but you can't link an i386
> > library to a PowerPC library.

Thank you for the hint. I have checked with "file" command the format of the
libraries on mac and got following result:

one of my application's libraries:
libkkbase.dylib: Mach-O dynamically linked shared library i386

my python module that has been built using standard python distutils:
j3k.so: Mach-O bundle i386

I am not actually sure what's the difference between "bundle" and "dynamically
linked shared library" on mac and if they can be linked together? Perhaps I
should configure distutils on mac somehow specially to make the module ready for
embedding?

Thanks,

KK


> On Tue, Jan 5, 2010 at 7:33 AM, Krzysztof Kobus wrote:
> > Hi,
> >
> >
> I have a problem with linking python module with my application on mac
> in order to make the module available in "embedded python".
> >
> > My python module is contained in j3kmodule.cxx file and module initialization
> function is exported in j3kmodule.h
> >
> > j3kmodule.h:
> > ------------
> > PyMODINIT_FUNC PyInit_j3k(void);
> >
> >
> > j3kmodule.cxx:
> > --------------
> > PyMODINIT_FUNC
> > PyInit_j3k(void)
> > {
> > PyObject *m = NULL;
> >
> > if ((m = PyModule_Create(&j3k_module)) == NULL)
> > return NULL;
> >
> > return m;
> > }
> >
> >
> > Then in my application in KkPython.cxx file I have:
> >
> > KkPython.cxx:
> > -------------
> >
> > #include "j3kmodule.h"
> >
> > /* Add a builtin module, before Py_Initialize */
> > PyImport_AppendInittab("j3k", PyInit_j3k);
> >
> >
> >
> I link my application with the module and get following linking error
> on mac although on open suse linux exactly the same procedure works
> fine:
> >
> > g++ -headerpad_max_install_names -o
> ../../bin/render.app/Contents/MacOS/render main.o KkPython.o -lkkbase
> -L/Users/kk/dev/J3K/trunk/j3ksrc/examples/render/../../lib/
> -lQtSolutions_PropertyBrowser-2.5 -lpython3.1
> /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so
> -framework OpenGL -framework AGL
> > ld: warning in
> /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so,
> file is not of required architecture
> > Undefined symbols:
> > "_PyInit_j3k", referenced from:
> > _PyInit_j3k$non_lazy_ptr in KkPython.o
> > ld: symbol(s) not found
> > collect2: ld returned 1 exit status
> > make: *** [../../bin/render.app/Contents/MacOS/render] Error 1
> >
> >
> > I appreciate any hints,
> >
> > best greetings,
> >
> > Krzysztof Kobus
> >




From: Diez B. Roggisch on
Krzysztof Kobus schrieb:
> Hi,
>
> I have a problem with linking python module with my application on mac in order to make the module available in "embedded python".
>
> My python module is contained in j3kmodule.cxx file and module initialization function is exported in j3kmodule.h
>
> j3kmodule.h:
> ------------
> PyMODINIT_FUNC PyInit_j3k(void);
>
>
> j3kmodule.cxx:
> --------------
> PyMODINIT_FUNC
> PyInit_j3k(void)
> {
> PyObject *m = NULL;
>
> if ((m = PyModule_Create(&j3k_module)) == NULL)
> return NULL;
>
> return m;
> }
>
>
> Then in my application in KkPython.cxx file I have:
>
> KkPython.cxx:
> -------------
>
> #include "j3kmodule.h"
>
> /* Add a builtin module, before Py_Initialize */
> PyImport_AppendInittab("j3k", PyInit_j3k);
>
>
> I link my application with the module and get following linking error on mac although on open suse linux exactly the same procedure works fine:
>
> g++ -headerpad_max_install_names -o ../../bin/render.app/Contents/MacOS/render main.o KkPython.o -lkkbase -L/Users/kk/dev/J3K/trunk/j3ksrc/examples/render/../../lib/ -lQtSolutions_PropertyBrowser-2.5 -lpython3.1 /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so -framework OpenGL -framework AGL
> ld: warning in /Users/kk/dev/J3K/trunk/j3ksrc/python/modules/build/lib.macosx-10.3-i386-3.1/j3k.so, file is not of required architecture
> Undefined symbols:
> "_PyInit_j3k", referenced from:
> _PyInit_j3k$non_lazy_ptr in KkPython.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> make: *** [../../bin/render.app/Contents/MacOS/render] Error 1
>
>
> I appreciate any hints,

The missing symbol looks like a C++-symbol - but Python is C. Do you
maybe miss the

extern "C"

declaration.

Diez
From: Krzysztof Kobus on
Hi,

>The missing symbol looks like a C++-symbol - but Python is C. Do you maybe miss the
> extern "C"

>
> declaration.

I have not specified extern "C" as I assume it is a part of
PyMODINIT_FUNC define. At least documentation says so:

"Note that PyMODINIT_FUNC declares the function as PyObject * return type,
declares any special linkage declarations required by the platform, and for C++
declares the function as extern "C"."

Regards,

KK