12

Using MinGW32 on a Windows PC I am trying to compile pySpotify. The first error was that libspotify/api.h was missing. I fixed this by copying the appropriate folder from libspotify into C:\MinGW\include. However now dllwrap is now failing with ld linking. The binaries Spotify distribute are libspotify.dll and libspotify.lib. No matter where I put them (pySpotify folder/subfolders, temp build folder/subfolders and MinGW folder/subfolders) or what I name them (.a, .o & .so) it still shows the same error messages.

The pertinent error is:

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

bok says on github that:

You need to add the API headers in the include path (add something like -I~\libspotify\include to your compiler options) and the shared library in the library path (add -L~\libspotify\lib to your linker options). This will allow the compiler to find the necessary include files, and your linker to find the necessary binary objects.

However the distutils Extension class seems to be deprecated and hard to find documentation for (I believe this is where custom compiler options need to go). Appreciate that ~ may need changed to %USERPROFILE% or similar. Similarly %PYTHONPATH%\Lib\distutils\distutils.cfg has little documentation beyond the [build] compiler=mingw32 stanza. This makes editing the compile/link commands and their options impossible to change.

How do you compile pySpotify on Windows?

EDIT:

By using Python 2.6 and copying libspotify.dll/libspotify.lib to C:\Python26\PCbuild and renaming them to spotify.dll/libspotify.lib I now receive another error message from 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
Metalshark
  • 8,194
  • 7
  • 34
  • 49
  • Perhaps the absolute path isn't read correctly by mingw's ld? That is, try moving libspotify to a relative location and see if that doesn't help. – Nik Reiman Dec 14 '12 at 12:38
  • Hi Nik, thanks for the suggestion - but I've tried copying to every folder/subfolder I can find to no avail: "No matter where I put them (pySpotify folder/subfolders, temp build folder/subfolders and MinGW folder/subfolders)." – Metalshark Dec 14 '12 at 12:51

3 Answers3

1

Not having access to a mingw installation at the moment, I can suggest a few things.

First, ld is known to be picky about order of arguments. Strangely, when I googled for "ld argument order", I got a bunch of pages suggesting that the order doesn't matter, but I have been burned several times by this. I've had the most success with the following argument order:

  1. Switches to ld (ie, -Wall)
  2. Library search paths (ie, -LPATH)
  3. Object files
  4. Libraries (ie, -lspotify)

I noticed in your linker output some references to amd64. I'm not sure how you compiled the other object files that you have, but since libspotify is 32-bit on Windows, I'm guessing that mixing 32/64 bit here is not going to work out too well.

The last thing I can think of is that perhaps the dll extension is confusing to ld, have you tried changing the filename to libspotify.so? I know this is kind of a shot in the dark, but otherwise I'm not sure how to help you further.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
  • I've tried renaming both files to .so, .a and .o. When I tried using MinGW64 it complained it couldn't compile, so I am now using MinGW instead (on 64-bit Windows). With the build script I have no access to argument ordering which is part of the problem. – Metalshark Dec 18 '12 at 07:01
1

I guess you are trying to link a 64bit version of pyspotify against a 32bit version of libspotify. Try to rebuild pyspotify adding the -m32 to CFLAGS and CXXFLAGS

alexp
  • 811
  • 4
  • 10
  • I do not know how to access the CFLAG/CXXFLAGS with setup.py (the build script for pySpotify). – Metalshark Dec 19 '12 at 11:04
  • CFLAGS=-m32 python setup.py should do the trick. Also make sure you have installed a 32bit python. Please notice that the problem may well be reversed: maybe pyspotify was compiled in 32bit and libspotify is 64bit. – alexp Dec 19 '12 at 17:14
  • `'CFLAGS' is not recognized as an internal or external command, operable program or batch file.` is the error you receive on Windows (know this works on *nix). Am going to play around with environment variables and check python is 32 bit. – Metalshark Dec 19 '12 at 19:22
  • Now the build path is build\temp.win32-2.6 (using 32-bit Python 2.6) but still no luck (dllwrap again). – Metalshark Dec 19 '12 at 19:28
  • Everything is 32-bit now apart from Windows itself (updated the error message in the question to reflect this). Tried adding -m32 to the CFLAGS environment variable and saw no difference. – Metalshark Dec 19 '12 at 19:41
0

I've added some instructions on how I got it to compile on the actual ticket for the issue. Let me Know if it helped you!

https://github.com/mopidy/pyspotify/issues/63

JDurman
  • 21
  • 4
  • Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Jan 28 '14 at 11:21
  • I just made an account and the max amount of links I could post were two. I had several links in the solution, so therefore I figured the best way to have all of the information intact was to post a link to the actual ticket were I posted my solution. – JDurman Jan 29 '14 at 01:10
  • the point is to post the _solution here_ (vs. posting a link to a solution elsewhere :-) – kleopatra Jan 29 '14 at 12:27