在MinGW32中使用libspotify .dll/.lib文件编译pySpotify

Met*_*ark 12 c python cpython spotify

使用MinGW32一台Windows PC,我试图编译在pySpotify.第一个错误libspotify/api.h就是缺失了.我固定从复制相应的文件夹这个libspotifyC:\MinGW\include.但是现在dllwrap现在失败了ld linking..二进制文件Spotify分发是libspotify.dlllibspotify.lib.无论我把它们放在哪里(pySpotify文件夹/子文件夹,临时构建文件夹/子文件夹和MinGW文件夹/子文件夹)或我命名它们(.a,.o和.so)仍显示相同的错误消息.

相关的错误是:

C:\MinGW\bin\dllwrap.exe -mdll -static --output-lib build\temp.win32-2.7\Release\src\lib_spotify.a --def build\temp.win32-2.7\Release\src\_spotify.def -s build\temp.win32-2.7\Release\src\module.o build\temp.win32-2.7\Release\src\session.o build\temp.win32-2.7\Release\src\link.o build\temp.win32-2.7\Release\src\track.obuild\temp.win32-2.7\Release\src\album.o build\temp.win32-2.7\Release\src\albumbrowser.o build\temp.win32-2.7\Release\src\artist.o build\temp.win32-2.7\Release\src\artistbrowser.o build\temp.win32-2.7\Release\src\search.o build\temp.win32-2.7\Release\src\playlist.o build\temp.win32-2.7\Release\src\playlistcontainer.o build\temp.win32-2.7\Release\src\playlistfolder.o build\temp.win32-2.7\Release\src\image.o build\temp.win32-2.7\Release\src\user.o build\temp.win32-2.7\Release\src\pyspotify.o build\temp.win32-2.7\Release\src\toplistbrowser.o -LC:\Python26\libs -LC:\Python26\PCbuild -lspotify -lpython26 -lmsvcr90 -o build\lib.win32-2.7\spotify\_spotify.pyd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot find -lspotify
collect2.exe: error: ld returned 1 exit status
dllwrap: gcc exited with status 1
error: command 'dllwrap' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

bok在github上说:

您需要在include路径中添加API头(在编译器选项中添加类似-I~\libspotify\include的内容)和库路径中的共享库(将-L~\libspotify\lib添加到链接器选项中).这将允许编译器找到必要的包含文件,并使链接器找到必要的二进制对象.

然而,distutilsExtension类似乎已被弃用,很难找到文档(我相信这是自定义编译器选项需要去的地方).欣赏~可能需要更改%USERPROFILE%或类似.同样,%PYTHONPATH%\Lib\distutils\distutils.cfg除了[build] compiler=mingw32节之外几乎没有文档.这使得编辑编译/链接命令及其选项无法更改.

你如何在Windows上编译pySpotify?

编辑:

通过使用Python 2.6并将libspotify.dll/libspotify.lib复制到C:\ Python26\PCbuild并将它们重命名为spotify.dll/libspotify.lib我现在从ld收到另一条错误消息:

C:\MinGW\bin\dllwrap.exe -mdll -static --output-lib build\temp.win32-2.6\Release\src\lib_spotify.a --def build\temp.win32-2.6\Release\src\_spotify.def -s build\temp.win32-2.6\Release\src\module.o build\temp.win32-2.6\Release\src\session.o build\temp.win32-2.6\Release\src\link.o build\temp.win32-2.6\Release\src\track.obuild\temp.win32-2.6\Release\src\album.o build\temp.win32-2.6\Release\src\albumbrowser.o build\temp.win32-2.6\Release\src\artist.o build\temp.win32-2.6\Release\src\artistbrowser.o build\temp.win32-2.6\Release\src\search.o build\temp.win32-2.6\Release\src\playlist.o build\temp.win32-2.6\Release\src\playlistcontainer.o build\temp.win32-2.6\Release\src\playlistfolder.o build\temp.win32-2.6\Release\src\image.o build\temp.win32-2.6\Release\src\user.o build\temp.win32-2.6\Release\src\pyspotify.o build\temp.win32-2.6\Release\src\toplistbrowser.o -LC:\Python26\libs -LC:\Python26\PCbuild -lspotify -lpython26 -lmsvcr90 -o build\lib.win32-2.6\spotify\_spotify.pyd
_spotify.exp: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
dllwrap: gcc exited with status 1
error: command 'dllwrap' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

Nik*_*man 1

目前无法访问 mingw 安装,我可以提出一些建议。

首先,ld众所周知,他对参数的顺序很挑剔。奇怪的是,当我在谷歌上搜索“ld argument order”时,我得到了一堆页面表明顺序并不重要,但我已经被这个问题烧伤过好几次了。我通过以下参数顺序取得了最大的成功:

  1. 切换到ld(即,-Wall
  2. 库搜索路径(即-LPATH
  3. 目标文件
  4. 图书馆(即,-lspotify

我注意到你的链接器输出中有一些对 amd64 的引用。我不确定你是如何编译你拥有的其他目标文件的,但由于 libspotify 在 Windows 上是 32 位的,我猜在这里混合 32/64 位不会有很好的效果。

我能想到的最后一件事是,也许 dll 扩展名令人困惑ld,你是否尝试过将文件名更改为libspotify.so?我知道这有点盲目,但除此之外我不知道如何进一步帮助你。