Unsolved Linking for Unicode
-
Hello,
How do I link a project for Unicode?
This works:
TEMPLATE = app TARGET = QtMfc2 # DEFINES -= UNICODE # DEFINES += _AFXDLL WINVER=0x0500 ...
But when I try this:
TEMPLATE = app TARGET = QtMfc2 DEFINES += _UNICODE UNICODE _AFXDLL WINVER=0x0500 ...
I get the error message:
LNK2019: unresolved external symbol _WinMain@16 referenced in function __tmainCRTStartup
msvcrtd.lib(crtexew.obj)I'm using Qt 5.5 msvc2010.
Thanks
-
Hi, do you have the same LNK2019 error if you build your project in Release mode?
-
Yes - same message. I think the program is looking for a different entry point.
-
Here is the whole file:
TEMPLATE = app
TARGET = QtMfc2DEFINES += _UNICODE UNICODE _AFXDLL WINVER=0x0500
QMAKE_LIBS_QT_ENTRY =HEADERS = childview.h mainframe.h qtmfc.h stdafx.h
SOURCES = childview.cpp mainframe.cpp qtmfc.cpp stdafx.cpp
RC_FILE = qtmfc.rcexists(config.pri):infile(config.pri, SOLUTIONS_LIBRARY, yes): CONFIG += qtwinmigrate-uselib
TEMPLATE += fakelib
QTWINMIGRATE_LIBNAME = $$qtLibraryTarget(QtSolutions_MFCMigrationFramework-head)
TEMPLATE -= fakelib
QTWINMIGRATE_LIBDIR = $$PWD/lib
unix:qtwinmigrate-uselib:!qtwinmigrate-buildlib:QMAKE_RPATHDIR += $$QTWINMIGRATE_LIBDIRINCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
LIBS += -luser32qtwinmigrate-uselib:DEFINES *= _AFXDLL
qtwinmigrate-uselib:!qtwinmigrate-buildlib {
LIBS += -L$$QTWINMIGRATE_LIBDIR -l$$QTWINMIGRATE_LIBNAME
} else {
SOURCES += ..\QtSrc\qwinwidget.cpp ..\QtSrc\qwinhost.cpp ..\QtSrc\qmfcapp.cpp
HEADERS += ..\QtSrc\qwinwidget.h ..\QtSrc\qwinhost.h ..\QtSrc\qmfcapp.h
}win32 {
qtwinmigrate-buildlib:DEFINES += QT_QTWINMIGRATE_EXPORT
else:qtwinmigrate-uselib:DEFINES += QT_QTWINMIGRATE_IMPORT
}
contains(QT_MAJOR_VERSION, 5): QT += widgets gui-private -
@carljoerger said in Linking for Unicode:
... I think the program is looking for a different entry point.
Yes, I think this is one place where MFC is showing its age. According to this support page you need to change the entry point to wWinMainCRTStartup.
There's a command switch for the Linker to do that (/Entry) but I didn't find any example on how to set that switch from your .pro file. As a workaround, try inserting this line in your .pro file:
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:CONSOLE,5.01
It should have more or less the same effect...
-
@hskoglund said in Linking for Unicode:
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:CONSOLE,5.01
Thank you - that got me closer. Now the message is:
LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup
msvcrtd.lib (crtexe.obj)I'm working through the qtwinmigrate tutorial.
Step 1 is to add a Qt dialog to a MFC application - I did that.
Step 2 is to move the application from the Visual Studio environment to the Qt environment.
Since my application is Unicode, I need to be able to #define UNICODE.Thank you.
-
@hskoglund said in Linking for Unicode:
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:CONSOLE,5.01
I also tried creating my own WinMain, but I get an assertion failure
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
theApp.InitInstance();
} -
Got it - thank you hskoglund for your help.
Here is the function I added:
extern int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
In LPTSTR lpCmdLine, int nCmdShow);int __stdcall WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// call shared/exported WinMain
return AfxWinMain(hInstance, hPrevInstance, (LPTSTR)lpCmdLine, nCmdShow);
} -
@carljoerger Nicely done!
P.S. This could be useful for me also, before I switched to Qt I used MFC for almost 20 years, and I've got some stragglers that needs converting...
-
@carljoerger if your problem is solved please don't forget to mark your post as such. Thank you.