如何使用CLion和MSVC编译器工具链编译wxWidgets Hello World应用程序而没有错误?
How do I compile a wxWidgets Hello World app with CLion and the MSVC compiler toolchain without errors?
我正在尝试使用CLion和MSVC(Visual Studio 2017社区版(编译器工具链编译一个基本的wxWidgets(wxWidgets版本3.1.3(Hello World应用程序。
使用 https://www.wxwidgets.org/downloads/提供的预编译二进制文件。请参阅最新开发版本:3.1.3 下的第一个下载 Windows 二进制文件按钮。我正在使用二进制文件的 64 位版本。
已按照 https://www.wxwidgets.org/blog/2012/08/how-to-use-294-wxmsw-binaries/中的说明操作,了解如何使用二进制文件。
按照 https://www.jetbrains.com/help/clion/quick-tutorial-on-configuring-clion-on-windows.html#MSVC 中有关如何设置 CLion 20.04 以使用 MSVC 编译器的说明进行操作。体系结构设置为amd64
,无平台。
Hello World代码,注释是wxIMPLEMENT_APP(MyApp)
宏最终扩展到的内容:
#include <iostream>
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class MyApp : public wxApp {
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame {
public:
MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
private:
void OnHello(wxCommandEvent &event);
void OnExit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event);
wxDECLARE_EVENT_TABLE();
};
enum {
ID_Hello = 1
};
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Hello, MyFrame::OnHello)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
/* This is what the macro expands to:
extern "C" int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wxCmdLineArgType, int nCmdShow) {
;;
return wxEntry(hInstance, hPrevInstance, 0, nCmdShow);
}
MyApp &wxGetApp() { return *static_cast<MyApp *>(wxApp::GetInstance()); }
wxAppConsole *wxCreateApp() {
wxAppConsole::CheckBuildOptions(
"3" "." "1" "." "3" " (" "wchar_t" ",Visual C++ " "1900" ",wx containers" ",compatible with 3.0" ")",
"your program");
return new MyApp;
}
wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp)
*/
bool MyApp::OnInit() {
MyFrame *frame = new MyFrame("Hello World", wxPoint(50, 50), wxSize(450, 340));
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
: wxFrame(NULL, wxID_ANY, title, pos, size) {
wxMenu *menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&Hello...tCtrl-H",
"Help string shown in status bar for this menu item");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
wxMenu *menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
menuBar->Append(menuHelp, "&Help");
SetMenuBar(menuBar);
CreateStatusBar();
SetStatusText("Welcome to wxWidgets!");
}
void MyFrame::OnExit(wxCommandEvent &event) {
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent &event) {
wxMessageBox("This is a wxWidgets' Hello world sample",
"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent &event) {
wxLogMessage("Hello world from wxWidgets!");
}
制作清单.txt内容:
cmake_minimum_required(VERSION 3.16)
project(MyApp)
set(CMAKE_CXX_STANDARD 14)
set(SRC_FILES
main.cpp
)
add_definitions(-DWXUSINGDLL=1)
add_definitions(-DwxMSVC_VERSION_AUTO=1)
add_definitions(-DwxMSVC_VERSION_ABI_COMPAT=1)
add_definitions(-DUNICODE=1)
add_definitions(-D_UNICODE=1)
include_directories(
includes
E:/cpp/lib/wxWin
E:/cpp/lib/wxWin/include
E:/cpp/lib/wxWin/include/msvc
E:/cpp/Lib/wxWin/lib/vc14x_x64_dll
E:/cpp/Lib/wxWin/lib/vc14x_x64_dll/mswud
)
link_directories(
E:/cpp/Lib/wxWin/lib/vc14x_x64_dll
)
add_executable(${PROJECT_NAME} ${SRC_FILES})
当我尝试编译它时,出现错误:
E:cpplibwxWinincludewx/app.h(900): error C2144: syntax error: 'wxAppInitializer' should be preceded by ';'
E:cpplibwxWinincludewx/app.h(900): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostx64x64cl.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
app.h
有问题的台词:
__unused extern wxAppInitializer wxTheAppInitializer;
我不敢改变app.h
因为它是wxWidgets的一部分。虽然,作为一个实验,我注释掉了__unused
并得到了这些错误:
LINK Pass 1: command "C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostx64x64link.exe /nologo @CMakeFilesManager.dirobjects1.rsp /out:Manager.exe /implib:Manager.lib /pdb:E:cppdevManagercmake-build-debug-msvc15Manager.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -LIBPATH:E:cppLibwxWinlibvc14x_x64_dll kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFilesManager.dir/intermediate.manifest CMakeFilesManager.dir/manifest.res" failed (exit code 1120) with the following output:
MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
Manager.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'C:Apps32JetBrainsappsCLionch-0201.7223.86bincmakewinbincmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
如何消除此问题?
编辑 #1
我用wxWidgets-3.1.3.7z
下载的存档的标题替换了标题,并得到了这些新错误:
LINK Pass 1: command "C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostx64x64link.exe /nologo @CMakeFilesHelloWorld.dirobjects1.rsp /out:HelloWorld.exe /implib:HelloWorld.lib /pdb:E:cppdevManagercmake-build-debug-msvc15HelloWorld.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -LIBPATH:E:cppLibwxWinlibvc14x_x64_dll kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFilesHelloWorld.dir/intermediate.manifest CMakeFilesHelloWorld.dir/manifest.res" failed (exit code 1120) with the following output:
MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
HelloWorld.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'C:Apps32JetBrainsappsCLionch-0201.7223.86bincmakewinbincmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Apps32Microsoft Visual Studio2017CommunityVCToolsMSVC14.14.26428binHostX64x64nmake.exe"' : return code '0x2'
Stop.
问题解决了!
追加到cmakelists.txt
文件:
set_target_properties(${PROJECT_NAME} PROPERTIES
LINK_FLAGS /SUBSYSTEM:WINDOWS
)
它现在生成并运行,但出现以下错误: - 在 CLion 的"运行"窗口中报告:
Process finished with exit code -1073741515 (0xC0000135)
- 从终端 (cmd( 运行程序时:报告以下系统错误消息:
The code execution cannot proceed because
wxmsw313ud_core_vc14x_x64.dll was not found. Reinstalling the
program may fix this problem.
和
The code execution cannot proceed because
wxbase313ud_vc14x_x64.dll was not found. Reinstalling the
program may fix this problem.
将这些文件放在与HelloWorld.exe
相同的文件夹中,问题就解决了。如上面的编辑 #1 所示,还需要将标头替换为下载wxWidgets-3.1.3.7z
存档的标头。
您使用的是 wxWidgets 的修改版本,官方版本在wxTheAppInitializer
声明之前没有任何__unused
。我不知道它是如何到达那里的,但您需要删除它,或者完全确定,删除所有本地标头并将它们替换为您下载wxWidgets-3.1.3-headers.7z
文件中的实际标头。
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 如何改变c++应用程序的视觉效果
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 使用 Visual Studio 2019 构建 Hello World wxwidgets 应用程序时出错
- 如何使用CLion和MSVC编译器工具链编译wxWidgets Hello World应用程序而没有错误?
- Visual Studio 中的 Hello World C++ 应用程序 - 关于预编译标头不同的问题
- 使用 Visual Studio Code 在 Linux 中创建和编译"hello world"应用程序
- 默认的Qt控制台应用程序不会"Hello World"...或做任何其他事情
- 在Windows中的Eclipse C++中运行Hello World应用程序
- 安卓"hello world"应用程序在C++没有JNI
- Qt "hello world" GUI 应用程序无法链接?