问题
I've been trying to properly add the open source dns_sd.h library provided by Apple. I am writing a program that uses the BonjourRegistrar class as demonstrated here: link text
I've already written my program on the Mac environment and now I am trying to port it to Windows. The Bonjour SDK comes with several classes, and I am quite confused onto how to correctly add the class to my Qt project. I have tried add the line:
win32:LIBS += c:\dnsssd.lib
in the .pro file with no success. Also, I attempted to add the dns_sd.h and dns_sd.c files into my project and got a couple of errors such as:
'UINT8': does not name a type 'INT8': does not name a type 'UINT16' does not name a type 'INT16' does not name a type
Finally, I am now trying to modify the lib file as described by xcimo in this link link text
I do not know if I am using the correct command to properly modify these files.
回答1:
The .lib distributed by Apple can be used only if you are compiling the Qt application with the MSVC compiler.
Otherwise, like you said, you need a GCC-compatible library (.a). To do that you need to do the following steps:
- Run the reimp tool [0] on the .lib:
reimp dnssd.lib
. A fileDLLStub.obj
will be generated. - Run the gendef tool [1] on the .dll:
gendef dnssd.dll
. A filednssd.def
will be generated. The .dll can be obtained from:C:\Windows\System32
if you are using the 32 bit or fromC:\Windows\SysWOW64
for the 64 bit version. - Assemble the final .a:
dlltool -k -d dnssd.def -l libdnssd.a
. - Add the right path int the .pro file, to the newly created library:
LIBS += -L"/path/to/the/library/file" -ldnssd
[0] - http://sourceforge.net/projects/mingw/files/MinGW/Extension/mingw-utils/mingw-utils-0.4-1/
[1] - http://sourceforge.net/projects/mingw/files/MinGW/Extension/gendef/gendef-1.0.1346/ - gendef is a better alternative to pexports
, because it can convert the stdcall-type libraries from MSVC to the GCC ones, so you can get a proper .def file.
PS: I know the author got it working, but I felt there should be some more detailed instructions on how to get it done -- the information is scattered around the internet.
回答2:
Try adding
DEFINES += _WIN32
to your project file.
回答3:
I figured it out, you need to use reimp and dll tool to modify the lib library to a .a
来源:https://stackoverflow.com/questions/4341179/adding-bonjour-dns-sd-h-library-to-qt-in-windows