Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building simple Qt application after installation failed #1442

Open
usernameiwantedwasalreadytaken opened this issue Jul 12, 2017 · 11 comments
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@usernameiwantedwasalreadytaken
Copy link

usernameiwantedwasalreadytaken commented Jul 12, 2017

I've installed the qt5 module and I'm trying to build a simple project with just one file:

#include <QtWidgets/QApplication.h>
#include <QtWidgets/QMainWindow.h>

int main(int argc, char** argv) {
	QApplication app { argc, argv };
	QMainWindow mainWindow;

	mainWindow.show();
	return app.exec();
}

Visual Studio can compile fine, but gives me the following error when linking:

1>------ Build started: Project: Basic, Configuration: Release Win32 ------
1>main.cpp
1>Qt5AxServer.lib(qaxserver.obj) : error LNK2001: unresolved external symbol "class QAxFactory * __cdecl qax_instantiate(void)" (?qax_instantiate@@YAPAVQAxFactory@@XZ)
1>C:\Tests\Qt\QtSamples\Release\Basic.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Basic.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any ideas how I might solve this?

P.S.: With a Debug build I've got many more linking errors...

I'm using Visual Studio 2017 Community.

Thanks in advance.

@usernameiwantedwasalreadytaken usernameiwantedwasalreadytaken changed the title Building simple Qt application after installation Building simple Qt application after installation failed Jul 12, 2017
@usernameiwantedwasalreadytaken
Copy link
Author

usernameiwantedwasalreadytaken commented Jul 20, 2017

So, if I manually delete Qt5AxServer.lib and Qt5AxServerd.lib from <vcpkg>\installed\*\lib and <vcpkg>\installed\*\debug\lib everything works.

@ras0219-msft ras0219-msft added category:port-bug The issue is with a library, which is something the port should already support category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist labels Jul 20, 2017
@ShinNoNoir
Copy link
Contributor

I'd like to add that for the Debug configuration, <vcpkg>\installed\*\debug\lib\Qt5Bootstrap.lib should also be deleted. Qt5Bootstrap.lib is linked with MD_DynamicRelease and is only meant for Release builds.

@ShinNoNoir
Copy link
Contributor

Reading a bit more about Qt, it seems that depending on your use case, you either:

  • Link qtmain.lib (rel) or qtmaind.lib (dbg);
  • Or link Qt5AxServer.lib (rel) or Qt5AxServerd.lib (dbg).

Source: http://doc.qt.io/qt-5/activeqt-server.html

Does vcpkg offer any way of selecting which libs will be included in the linking process?

@ShinNoNoir
Copy link
Contributor

Does vcpkg offer any way of selecting which libs will be included in the linking process?

Okay, after browsing through some source files and other portfile.cmakes, I think the following probably should happen:

  • debug\lib\Qt5Bootstrap.lib must be deleted;
  • Qt5AxServer.lib should be moved from lib to lib\manual-link;
  • Qt5AxServerd.lib should be moved from debug\lib to debug\lib\manual-link;
  • qtmain.lib should be moved from lib to lib\manual-link;
  • qtmaind.lib should be moved from debug\lib to debug\lib\manual-link;

Users need to:

  • Explicitly add qtmain.lib/qtmaind.lib as a dependency for Qt desktop applications for release/debug configurations.
  • Explicitly add Qt5AxServer.lib/Qt5AxServerd.lib as a dependency for Qt ActiveX server applications for release/debug configurations.

ShinNoNoir added a commit to ShinNoNoir/vcpkg that referenced this issue Sep 6, 2017
This commit moves a few .lib files to subfolders to prevent them from
automatically getting linked:

Qt5Bootstrap (dbg):
This lib is linked against a release version of the CRT and is only
meant for release builds. For debug builds, this lib should not be
linked at all.

qtmain (rel), qtmaind (dbg),
Qt5AxServer (rel), Qt5AxServerd (dbg):
These libs are mutually exclusive. The user either links against
qtmain(d) for desktop applications or against Qt5AxServer(d) for ActiveX
servers.

See microsoft#1442 for more information.
ShinNoNoir added a commit to ShinNoNoir/vcpkg that referenced this issue Jul 7, 2018
This commit fixes part of a previous issue:
microsoft#1442

In this older issue, Qt5Bootstrap.lib was originally placed in
debug/lib, causing it to be automatically linked in Visual Studio
for debug builds. This caused linking errors, since Qt5Bootstrap.lib
is linked against a different runtime (as detailed in the issue).

The solution back then, as implemented in PR
  microsoft#1847
, was to place this file elsewhere.

The same approach is taken here in this commit. However, the Qt5 port
is nowadays modular and complicates matters. The qt5-base package
produces the problematic .lib file and should be responsible for moving
the file elsewhere, yet at the same time the qt5-tools package
depends on this .lib file.

Ideally, the qt5-tools port should be patched such that it would find
Qt5Bootstrap.lib in its new location. Unfortunately, the path to
Qt5Bootstrap.lib appears in a Makefile that is generated by qmake based
on a *.pro and a qt.conf file, a process which I do not yet fully
understand.

As an alternative, I opted for temporarily copying the Qt5Bootstrap files
to their original location before building the qt5-tools package and
clean up afterwards.
@JackBoosY
Copy link
Contributor

Hi @usernameiwantedwasalreadytaken, thanks for reporting this issue.
Since qt5 has been upgraded to 5.12.5, this issue may be fixed.
So please update vcpkg and rebuild qt5.

Thanks.

@JackBoosY
Copy link
Contributor

@Neumann-A I think this issue is resolved in some PRs, is it correct?

@Neumann-A
Copy link
Contributor

@JackBoosY: I think this:

Qt5AxServer.lib should be moved from lib to lib\manual-link;
Qt5AxServerd.lib should be moved from debug\lib to debug\lib\manual-link;

still needs to be resolved

@JackBoosY JackBoosY removed the category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist label Nov 4, 2020
@DietmarSchulz
Copy link

After doing that the execution seems to bind to tesseract and the output is:
Starting java -Xms512m -Xmx1024m -Djava.library.path=. -jar ./ScrollView.jar
ScrollView: Waiting for server...
ScrollView: Waiting for server...

@JonLiu1993
Copy link
Member

@Neumann-A, since qt5 has been upgraded to 5.12.5, could you please see if this issue is resolved in some PR?

@Neumann-A
Copy link
Contributor

@JonLiu1993 just look at the file list. If the files mentioned by me above are in manual-link it is resolved otherwise it is not solved.

@Cheney-W Cheney-W assigned Cheney-W and unassigned JackBoosY Dec 6, 2022
KOConchobhair pushed a commit to KOConchobhair/vcpkg-registry that referenced this issue Jun 27, 2023
This commit moves a few .lib files to subfolders to prevent them from
automatically getting linked:

Qt5Bootstrap (dbg):
This lib is linked against a release version of the CRT and is only
meant for release builds. For debug builds, this lib should not be
linked at all.

qtmain (rel), qtmaind (dbg),
Qt5AxServer (rel), Qt5AxServerd (dbg):
These libs are mutually exclusive. The user either links against
qtmain(d) for desktop applications or against Qt5AxServer(d) for ActiveX
servers.

See microsoft/vcpkg#1442 for more information.
@arappazzo
Copy link

I've found the same issue in a VS solution of a CUDA project (I've pasted the error below just as reminder)

Qt5AxServer.lib(qaxserver.obj) : error LNK2001: unresolved external symbol "class QAxFactory * __cdecl qax_instantiate(void)" (?qax_instantiate@@YAPAVQAxFactory@@xz)

I have the Qt plugin installed in my VS installation. Still, the CUDA project has nothing to do with Qt. I mean, is there a way to fully disable Qt plugins from VS? Is there a way to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

No branches or pull requests

9 participants