Qt 5.4静态构建产生“未解析的外部符号”链接错误在Visual Studio 2013中 [英] Qt 5.4 static build produces "unresolved external symbol" link error in Visual Studio 2013

查看:972
本文介绍了Qt 5.4静态构建产生“未解析的外部符号”链接错误在Visual Studio 2013中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Qt 5.4的静态构建。因为没有预编译的静态构建可用,你必须自己从Qt源代码构建一个。



我的环境如下:




  • Windows 7 x64

  • Visual Studio 2013 Ultimate Update 4

  • in 1.2.4

  • 已安装ActivePerl / ActivePython(构建Qt源所需)



过程如下(参见Qt Documentation> Qt 5.4> Qt for Windows - 从源码构建):




  • 下载qt-everywhere- -src-5.4.0.zip

  • 解压缩到临时文件夹

  • 按照这里(基本上,这类似于打开一个Visual Studio命令提示符并向路径变量添加一些路径)

  • 使用以下命令运行configure

      configure -c ++ 11 -mp -release -static -nomake tests -nomake examples -prefix D:\ Qt\qt-5.4.0-x86-msvc2013-compact-static -platform win32 -msvc2013 -opengl桌面-no-icu -skip webkit 


  • 运行 nmake nmake install




<



然后在Visual Studio中,我将现有Qt项目的Qt版本更改为 D:\ Qt \ qt-5.4.0-x86-msvc2013-compact-static ,因为这是上述过程的输出文件夹。



,现在我得到以下类型的未解决的符号错误(构建配置释放):

 错误LNK2001:未解决的外部符号__imp__glBindTexture @ 8。 Qt5Gui.lib(qopenglfunctions.obj)
...
错误LNK2001:未解析的外部符号_hb_blob_create。 Qt5Gui.lib(qharfbuzzng.obj)
...
错误LNK2001:未解析的外部符号_hb_face_create_for_tables。 Qt5Gui.lib(qharfbuzzng.obj)
....
错误LNK2001:未解析的外部符号_WSAAsyncSelect @ 16。 Qt5Core.lib(qeventdispatcher_win.obj)

使用类似选项的共享库/动态链接构建c $ c> -platform win32-msvc2013 -opengl桌面-no-icu -skip webkit )可以正常工作。



错误?






更新1月6日



1)正如评论中已经提到的,这个可能是Qt中的一个错误,所以我创建了一个错误报告(QTBUG-43636),后来我发现一个可能相关的错误-38913)。 (对不起,我可以发布不超过2个链接)



2)我找到了(感谢karlphillip)




  • Ws2_32.lib 解析一个错误消息(103个)

  • opengl32.lib 解析47个错误消息



这意味着现在只有 55错误消息

解决方案

我找到了解决方案: b
$ b

您必须将以下库添加到Visual Studio中的其他依赖项:



Ws2_32.lib
opengl32.lib
qtharfbuzzng.lib



然后,我的项目终于编译了。



但是,这不是故事的结尾:



虽然已成功编译,我的应用程序显示以下错误启动时显示消息:


此应用程序无法启动,因为无法找到或加载Qt平台插件windows。


要解决这个问题,您必须为您的其他依赖关系添加更多的库:



imm32.lib
winmm.lib
Qt5PlatformSupport.lib
qwindows.lib



...以及以下到您的其他图书馆目录:



$(QTDIR)\plugins\platforms



...以及以下到您的源代码:

  #include< QtPlugin> 
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

完成!最后,我能够链接到静态Qt库。



这是值得的努力: $ b

我的应用程序的冷启动时间从大约10秒显着提高到不到1秒。而不是14 MB的DLL文件,我只需要部署一个单一的8 MB EXE文件。


I want to use a static build of Qt 5.4. Since there is no precompiled static build available, you have to build one from the Qt source code yourself.

My environment is the following:

  • Windows 7 x64
  • Visual Studio 2013 Ultimate Update 4
  • Qt5 Visual Studio Add-in 1.2.4
  • ActivePerl / ActivePython installed (required to build Qt source)

My procedure was the following (cf. Qt Documentation > Qt 5.4 > Qt for Windows - Building from Source):

  • Download qt-everywhere-opensource-src-5.4.0.zip
  • Extract to a temp folder
  • Open a command prompt as described here (basically, this is similar to open a "Visual Studio Command Prompt" and adding some paths to the path variable)
  • Run configure with the following command

    configure -c++11 -mp -release -static -nomake tests -nomake examples -prefix D:\Qt\qt-5.4.0-x86-msvc2013-compact-static -platform win32-msvc2013 -opengl desktop -no-icu -skip webkit
    

  • Run nmake and nmake install

All this run through without errors.

Then in Visual Studio, I changed the Qt version of an existing Qt project to D:\Qt\qt-5.4.0-x86-msvc2013-compact-static as this was the output folder of the above procedure.

However, now I get tons of unresolved symbol errors of the following kind (build configuration "release"):

error LNK2001: unresolved external symbol "__imp__glBindTexture@8". Qt5Gui.lib(qopenglfunctions.obj)
...
error LNK2001: unresolved external symbol "_hb_blob_create".    Qt5Gui.lib(qharfbuzzng.obj)
...
error LNK2001: unresolved external symbol "_hb_face_create_for_tables". Qt5Gui.lib(qharfbuzzng.obj)
....
error LNK2001: unresolved external symbol "_WSAAsyncSelect@16". Qt5Core.lib(qeventdispatcher_win.obj)

A shared library / dynamic linking build with similar options (-platform win32-msvc2013 -opengl desktop -no-icu -skip webkit) works just fine.

What am I doing wrong?


Update Jan 6th:

1) As already mentioned in the comments, this may be a bug in Qt, so I created a bug report (QTBUG-43636), and later I found a probably related bug (QTBUG-38913). (Sorry, I can post no more than 2 links)

2) I found out (thanks to karlphillip) that you can reduce the number of error messages if you add some libraries to your additional dependencies in Visual Studio

  • Ws2_32.lib resolves one error message (out of 103)
  • opengl32.lib resolves 47 error messages

This means there are now "only" 55 error messages left. Maybe there are still more libraries missing?

解决方案

I found the solution:

You have to add the following libraries to your additional dependencies in Visual Studio:

Ws2_32.lib opengl32.lib qtharfbuzzng.lib

Then, my project finally compiled.

However, that is not the end of the story:

Although successfully compiled, my application showed the following error message on startup:

This application failed to start because it could not find or load the Qt platform plugin "windows".

To solve this, you have to add even more libraries to your additional dependencies:

imm32.lib winmm.lib Qt5PlatformSupport.lib qwindows.lib

...and the following to your additional library directories:

$(QTDIR)\plugins\platforms

...and the following to your source code:

#include <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

Done! Finally, I was able to link against static Qt libraries.

It was worth the effort:

The cold startup time of my application improved dramatically from about 10 seconds to less than 1 second. And instead of 14 MB DLL-files I only have to deploy a single 8 MB EXE-file.

这篇关于Qt 5.4静态构建产生“未解析的外部符号”链接错误在Visual Studio 2013中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆