如何使用 qmake 在 OSX 10.6 上链接为 .so 而不是 .dylib

发布于 2024-08-28 07:56:51 字数 1433 浏览 5 评论 0原文

我正在尝试使用 SWIG 来包装一些 C++ 代码以便与 Python 一起使用。正如此处所述,它似乎是需要将我的 C++ 代码链接到 .so 文件,而不是 .dylib 文件。该线程建议将 libtool-module 标志结合使用进行链接,但我正在使用 qmake,并且需要有关如何执行此操作的更精确的说明。

我的 .pro 文件(用于 qmake)如下所示:

TEMPLATE = lib
TARGET = 
CONFIG += qt debug console plugin no_plugin_name_prefix
QT += opengl
DEPENDPATH += . libgm src
INCLUDEPATH += . libgm src /usr/include/python2.6/
LIBS += -L/usr/lib -lpython
MOC_DIR = .moc
OBJECTS_DIR = .tmp
DESTDIR = bin
TARGET = _mylibname
DEFINES  += COMPILE_DL=1

HEADERS += <my_headers> \
           src/swig_wrap.h

SOURCES += <my_sources>
           src/swig_wrap.cxx

我首先使用 Eclipse 构建器调用 swig,然后调用 qmake,然后调用 make

cd src/
swig -c++ -python swig.i
cd ..
qmake -spec macx-g++
make all

编译并链接工作正常,但给我留下了 bin/_mylibname.dylib,当我运行我的 python 应用程序时,语句 import _mylibname 失败。

有谁知道我如何让 qmake 构建 *.so 而不是 *.dylib,可能使用 libtool (或任何其他方式我不在乎)?我的平台:

  • Mac OS X Snow Leopard (10.6)
  • Python 2.6
  • SWIG 1.3.31
  • qmake 2.01a with Qt 4.6.2
  • g++ i686-apple-darwin10-g++-4.2.1

我对链接问题不太了解,所以请温柔点:-)

奥莱

I am trying to use SWIG to wrap some C++ code for the use with Python. As described here it seems to be necessary to link my C++ code against an .so file, not a .dylib file. The thread suggests to use libtool in combination with the -module flag to link, but I am using qmake and need more precise instructions on how I do that.

My .pro file (for qmake) looks like this:

TEMPLATE = lib
TARGET = 
CONFIG += qt debug console plugin no_plugin_name_prefix
QT += opengl
DEPENDPATH += . libgm src
INCLUDEPATH += . libgm src /usr/include/python2.6/
LIBS += -L/usr/lib -lpython
MOC_DIR = .moc
OBJECTS_DIR = .tmp
DESTDIR = bin
TARGET = _mylibname
DEFINES  += COMPILE_DL=1

HEADERS += <my_headers> \
           src/swig_wrap.h

SOURCES += <my_sources>
           src/swig_wrap.cxx

I am invoking first swig, then qmake, then make using Eclipse builders:

cd src/
swig -c++ -python swig.i
cd ..
qmake -spec macx-g++
make all

Compile and Link works fine, but leaves me with bin/_mylibname.dylib, and when I run my python application, the statement import _mylibname fails.

Does anyone know how I can get qmake to build a *.so instead of a *.dylib, possibly using libtool (or any other way for all I care)? My platform:

  • Mac OS X Snow Leopard (10.6)
  • Python 2.6
  • SWIG 1.3.31
  • qmake 2.01a with Qt 4.6.2
  • g++ i686-apple-darwin10-g++-4.2.1

I am not very knowledgable with linking issues, so please be gentle :-)

Ole

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2024-09-04 07:56:51

我想你可能有两个问题。

为了使输出文件成为 .so 文件,我设置了编译选项 -o mylib.so 并强制 gcc 正确命名该文件。

我认为您可能遇到的另一个问题是,在 Mac 上,链接 python 库与在 Linux 机器上不同。我发现在 mac 上你不使用 -lpython 链接到 python 库,而是使用 -framework python 然后链接器会找到正确的库。

I think you might have two issues.

To get the output file to be a .so file, I set the compile option -o mylib.so and that forced gcc to name the file correctly.

The other issue I think you might have is that on the Mac, linking against the python lib is not the same as on a Linux machine. What I found that was on the mac you don't use -lpython to link to the python lib, but rather use -framework python and then the linker will find the correct lib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文