views:

149

answers:

1

I am having a super hard time compiling and using TagLib 1.6.3 in my Qt project. I've tried everything I can think of. TagLib claims that it is supported through CMake but I'm not having any luck. Furthermore, I'm confused about what kinds of files I even need for my Qt libs!

I've built *.a files, *.lib, and *.dll. From what I understand thus far... I believe that since I'm working in Windows *.lib is what I want. No matter what I do, I always end up with "undefined references" to any TagLib functions I try to use when I try to compile my Qt project. I have tried MinGW32, MSYS, Visual Studio 2008, and even cross-compiling for Windows on Linux. All turning up nothing.

What makes even less sense to me is that if I compile the same TagLib source with Qt on Mac (g++ I think?) it works fine! Somewhere in my Windows compilation procedures I have to be going wrong. I have been smacking my face on my desk for probably about 30 (on and off) hours trying to figure this out.

Since Qt uses minGW must I compile TagLib with the same compiler?

If I compile *.lib's with Visual Studio are they not compatible?

Are *.a libraries even usable in Windows? (assuming minGW)

I'm still trying to get a handle on this C++ stuff, but after reading countless forum threads and other questions I'm still coming up short. Here is what I have been working with in CMake currently...

cmake -G "MinGW Makefiles" -DENABLE_STATIC=ON -DHAVE_ZLIB=0 -DWITH_MP4=1 -DMAKE_TAGLIB_LIB=1
cmake --build ./

This generates a single *.a file of ~2MB in size. The working library on Mac was ~3MB, and the *.lib from Visual Studio was ~4MB in Release mode. Please someone save me from this C++ cross platform command line madness because I am at my wit's end. I would probably even pay you to just compiling me some %!$#&ing libraries. Thanks.

+1  A: 

Since Mac works for you, I'm just talking about Win32.

Ok, this are my Taglib.pro and an excerpt of my project.pro: https://gist.github.com/449ea81ce92f52399f41. Check them out. My Taglib may be a bit outdated, so take care, some files you may have could be missing there. Also take care of the relative paths. They are all relative to the .pro file.

I just ran cmake . inside the taglib directory. This should result in a config.h and a taglib_config.h

You definitly only need the libTaglib.a when you use QtCreator and mingw-gcc. *.lib are MSVC specific!

Wolfgang Plaschg
This is great information to have, thanks. In the past I have been smashing all the *.h files into one directory for my INCLUDEPATH to make it easier to manage. Is this incorrect? Also I haven't been including DEPENDPATH because I didn't know I needed it.
jocull
To be honest I'm not sure if you need DEPENDPATH, but it doesn't hurt either. Since TagLib itself relies on proper Include Paths smashing all .h files into one directory is not a good idea but not the source of your linker problem!
Wolfgang Plaschg
Im not 100% sure about this: You're compiling TagLib as a shared library, but your linker complains about some symbols. Make sure your linker does know that the symbols from TagLib are _dynamically_ loaded, not _statically_! Make sure you **don't** have defined `TAGLIB_STATIC` **nor** `MAKE_TAGLIB_LIB` when compiling your program. Read `taglib_export.h` carefully as this file is the pivotal point for exporting or importing symbols.
Wolfgang Plaschg
Just so I understand this, I **do** want to compile TagLib statically, but when I am compiling my program TagLib is now considered a **shared** resource. Is that correct?
jocull
Do you have any efficient methods that you use to export all the *.h files in their current directory structures? It's a mess the way it is currently.
jocull
When you create a .dll and a .a file you create a **shared** resource. To link TagLib statically (ie. directly) into your binary, just add TagLib's sources to your .pro file (with `SOURCES`) and define `TAGLIB_STATIC`.
Wolfgang Plaschg
Ok, that clarifies, thanks. In that case, I'm currently working with a **shared** TagLib build. I actually got it to build with Qt (finally) and I have it configured like you showed. I have everything compiling with no errors, but once I run I get an error immediately: QtTrayTime.exe exited with code -1073741515 ... From the Googling I've done I'm assuming this means that I did something wrong with linking my shared library. I made a Gist of what I have currently: http://gist.github.com/615451
jocull
Glad to hear that. Try to copy `TagLib.dll` into the same directory as your QtTrayTime.exe.
Wolfgang Plaschg
AHHHH IT WORKS! You are the best man, thanks so much for all of your help. This has been the bane of my existence for days. I should have thought of that (it's what you have to do in C#) but this C++ stuff is throwing me for a loop pretty hard. Can you explain to me why since we define things like win32:LIBS += why I have to manually copy the DLL? Is the LIBS += just for the compiler's use, but I have to manually copy the DLL for the .exe's use? Why isn't it like this on Mac?
jocull
Thanks to your help I was also able to statically compile the TagLib source files into my project. It was as easy as adding the *.h and *.cpp files to my project and adding DEFINES += TAGLIB_STATIC=1. I also copied over the FRAMEWORK_HEADERS and QMAKE_BUNDLE_DATA for Mac from the original TagLib *.pro. Thanks again!
jocull