开发者

Compiling TagLib into Qt C++ Project on Windows

I am currently trying to make the move from C# and break free from my platform boundaries by using Qt / C++.

I was using TagLibSharp in my old project, but I'm now trying to use the original C++ source found here:

http://developer.kde.org/~wheeler/taglib.html

I am in a world of hurt trying to compile this into my application. Most of this Linux based C++ is gibberish to me and I don't know how to properly include this library into my project with Qt. I'm using Qt Creator for the bulk of my work (everything I possibly can).

Can anyone please point me to some helpful tutorial or guides? Anything to help me understand what I am even doing with this source would be greatly appreciated. I have a very thorough understanding of C# and Windows programming, but I don't exactly have a good handle on what I'm doing with these types of open source projects.

Thanks!

EDIT - THE ANSWER IS HERE I decided to post another question that was a bit more refined for it.

Compiling static TagLib 1.6.3 libraries for Windows

Some older edits...

I now have TagLib compiled with Qt, but am running into "Undefined reference" errors.

*.pro

INCLUDEPATH += ../$${TARGET}/taglib-win32
LIBS += -L"..\\$${TARGET}\\taglib-win32"
LIBS += -llibtag #It seems to want this to be a *.dll, not a *.a?
DEFINES += TAGLIB_NO_CONFIG

*.cpp

#include <tag.h>
#include <fileref.h>
...
//None of these work, even though they are similar to examples given in TagLib source.
TagLib::FileRef f("03.flac");
TagLib::String test = f.tag()->album();
TagLib::FileName *n = new TagLib::FileName("test");
TagLib::FileRef *f = new TagLib::FileRef();

Here are some examples of the exact errors:

./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:20: undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE' 
./debug\mythread.o:C:\Users\jocull\Documents\开发者_Go百科My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:21: undefined reference to `_imp___ZNK6TagLib7FileRef3tagEv' 
./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:42: undefined reference to `_imp___ZN6TagLib6StringD1Ev' 
./debug\mythread.o:C:\Users\jocull\Documents\My Dropbox\Code\QT\QtTrayTime-build-desktop/../QtTrayTime/mythread.cpp:42: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev' 
collect2: ld returned 1 exit status 

Command line steps using g++ (Mac/Linux)

  1. ./configure --enable-shared=false --enable-static=true
  2. make
  3. ??? No *.a or *.lib files created


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜