+1  A: 

If you're new to C++ programming there are several issues you have to grasp to accomplish your task:

  • Source files (*.cpp) contain the actual source code, while header files (*.h) just declare what's inside a source file. You have to include all headers in your source files that use classes/functions/variables from other source files.
  • You need to understand how the preprocessor works. AFAIK C# does not have one. The wikipedia article should give you a good overview: http://en.wikipedia.org/wiki/C_preprocessor
  • Assuming you want to use TagLib as a dynamic library you have to create a Qt project for just building TagLib as a .dll (.pro file directives TEMPLATE=lib, CONFIG+=dll)
  • If you want to create a dynamic library out of a source files you have to mark the functions you want to use later as exportable. In TagLib this is done by defining the preprocessor macro MAKE_TAGLIB_LIB (in your taglib .pro file: DEFINES+=MAKE_TAGLIB_LIB)
  • Then you have to build the dynamic library (in your pro file: TEMPLATE=lib, then adding all sources and headers of taglib). When you use gcc this will result in two files TagLib.dll and libTagLib.a.
  • When building your application you have to include the header files of TagLib in your source and tell the compiler about the library (in your .pro file: LIBS+=libTagLib.a)
  • In your code you simply include the header file from your library. Let's say you want to use TagLib::Tag in your source file, then you must #include <taglib/tag.h>; You also have to tell the compiler (to be precise: the preprocessor) where it can find the taglib directory. In your .pro file you do this by adding INCLUDEPATH+=/path/to/taglib.

These are the big points and are not an in-depth explanation of what you have to do. Please ask more detailed questions if you have a problem when realizing this points.

For more information look at the qmake manual: http://doc.trolltech.com/4.6/qmake-variable-reference.html#libs

Wolfgang Plaschg
Thanks for your response. I understand h/cpp and I mostly get the preprocessor (I have some Obj-C experience).TagLib actually comes with a *.pro file, and after a little tweaking I got it to compile. (It had a few errors, but I think it was config related.) Your recommended config is a bit different, but I think it could be more correct for Windows.Anyways, I was able to produce a libTagLib.a and I added it to my *.pro file. However I'm unsure how to then reference this file in my code. Do you have any additional details on how to use external libraries in Qt's C++?
jocull
I added some information. HTH
Wolfgang Plaschg
Do I have to have the *.h files available as well as the *.lib? Doesn't that defeat the purpose of a compiled library?
jocull
Actually I have a *.a, not *.lib.
jocull
Have have an .a file: Perfect. That's what gcc needs.
Wolfgang Plaschg
A .h file just declares class and methods, not how they are implemented. So, yes, you need them and you need to #include them. No, that does not defeat the purpose of a compiled library, since no "productive" code is contained in them.
Wolfgang Plaschg
Ok, this is all good to know. I think I am really close with this. I have compiled TagLib with Qt Creator into libTagLib.a (in release mode) and included the lib and include paths in my *.pro. I will edit my question to post what I currently have. However now my problem is that when I actually try to use anything, the compiler tells me I have an undefined reference to a garbled up name. I assume this means that it can't find the library that I specified? I'm fairly sure I have it written correctly.
jocull
Yes, the linker can't find the library. Please check your `LIBS+=...` path. It must contain the path to libTagLib.a also!
Wolfgang Plaschg
Be sure to compile TagLib with `DEFINES+=MAKE_TAGLIB_LIB`
Wolfgang Plaschg
I'm fairly certain the LIBS += is correct, because if I change it then the compiler complains that it can't find the file. I tried recompiling with DEFINES+=MAKE_TAGLIB_LIB but it's still giving me the same errors. I'm about out of ideas. Is there a specific compiler that I have to do this with? Am I missing a configure step?
jocull
I've tried doing this on Mac and Linux... but I get no *.a files out of my compiles. I will post my steps above in the original question. I'm not sure how to define MAKE_TAGLIB_LIB when I am doing this with the command line. Ideas?
jocull
I've noticed that if I use a *.dll (since I am on Windows primarily) the compiler seems to complain less about my LIBS. Per the recommendation of a few forums I've read, I switched my LIB += include. I will edit it above.
jocull
OK more updates... I *WAS* able to compile and use taglib on MacOSX! In that case, I compiled it in release mode with Qt Creator from the provided *.pro file. No issues. Set the INCLUDEPATH += and the LIB += to the *.a and it worked. Great! Windows is a different story...
jocull
Windows throws tons of DLL reference warnings and even a few errors when compiling with Qt Creator (I think it uses mingw32-make and mingw32-g++??). If I comment a couple lines out I can get it to compile, but the *.a files never work. It always complains about undefined references to things like '_imp___ZNK6TagLib7FileRef6isNullEv'. I can compile with no errors or warnings if I run the configure with MSYS, use CMAKE to create the makefiles (specified for for mingw32-make), and then make them with mingw32-make. This *.a is about 1MB larger, but has the same undefined issues...
jocull
I read on another forum somewhere that you should define ENABLE_STATIC=ON when compiling tagLib and you want the end-result to be static. I haven't noticed a difference on my Windows builds. Incidentally, how are you supposed to define these variables when running './configure' or 'make'?
jocull
This is getting complicated. I've tried 100 more things, so I just broke this off into a more specific question now that I halfway know what I'm talking about... http://stackoverflow.com/questions/3878883/compiling-static-taglib-1-6-3-libraries-for-windows
jocull