Compiling static TagLib 1.6.3 libraries for Window

2019-01-24 13:16发布

问题:

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:

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!



回答2:

This blog post details the whole process described in this thread.

The blog post author, Joel, was nice enough to provide the binaries of taglib 3.6.3 compiled for windows.



回答3:

I use cmake for my projects.Here is my cmake file for a media player I made that uses taglib. I installed taglib to /usr/local/ (this way I don't have to change anything when I compile in Linux). The important parts have an arrow.

project(qtmu3)
find_package(Qt4 REQUIRED)
-> find_library(TAGLIB_LIB tag PATH /usr/local/lib/)
set(QT_USE_PHONON TRUE)
set(QTMU_SRCS main.cpp mainwindow.cpp WidgetMarqueeLabel.cpp single_application.cpp)
set(QTMU_MOC_HDRS mainwindow.h WidgetMarqueeLabel.h single_application.h)
set(QTMU_UI_FILES mainwindow.ui)
set(QTMU_RSRC_FILES myresources.qrc)
-> include_directories(/usr/local/include/taglib/)
set(CMAKE_CXX_FLAGS "-mwindows")
include(${QT_USE_FILE})
QT4_WRAP_UI( QTMU_UI_HDRS ${QTMU_UI_FILES})
QT4_WRAP_CPP( QTMU_MOC_SRCS ${QTMU_MOC_HDRS})
QT4_ADD_RESOURCES(QTMU_RSRC_SRCS ${QTMU_RSRC_FILES})
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
ADD_EXECUTABLE(qtmu3 ${QTMU_SRCS} ${QTMU_MOC_SRCS} ${QTMU_RSRC_SRCS} ${QTMU_UI_HDRS})
-> TARGET_LINK_LIBRARIES(qtmu3 ${QT_LIBRARIES} ${TAGLIB_LIB}) 

The last one, just the ${TAGLIB_LIB} is important. hope that helps someone.