简体   繁体   English

在 CMAKE 和 Visual Studio 中使用 wxWidgets

[英]Using wxWidgets with CMAKE and visual studio

Every time I try to build my project with CMAKE having the wxWidgets as library I get a lot of linker errors LNK I even get two errors for just compiling my main.cpp that only includes this :每次我尝试使用具有 wxWidgets 作为库的 CMAKE 构建我的项目时,我都会收到很多链接器错误 LNK 我什至在编译仅包含以下内容的 main.cpp 时遇到两个错误:

#include "wx/wx.h"
int main(){
    return 0;
}

I just downloaded the source code of wxwidgets, put it in a lib folder and linked it with cmake This is my CMakeLists.txt :我刚刚下载了 wxwidgets 的源代码,放在 lib 文件夹中并用 cmake 链接这是我的 CMakeLists.txt :

cmake_minimum_required(VERSION 3.10)

# set the project name
project(wxtest VERSION 1.0)

add_subdirectory(libs/wxWidgets)
add_executable(wx_test WIN32 src/main.cpp)
target_link_libraries(wx_test wx::net wx::core wx::base)

Here are the errors: Error LNK1120 1 unresolved externals以下是错误:Error LNK1120 1 unresolved externals
Error LNK2019 unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)函数“int __cdecl invoke_main(void)”(?invoke_main@@YAHXZ)中引用的错误LNK2019未解析的外部符号WinMain

Is there anything wrong with linking the wxWidgets lib to my project ?将 wxWidgets 库链接到我的项目有什么问题吗?

wxWidgets programs are compiled as GUI Win32 applications and so use WinMain() entry point by default, which you don't define. wxWidgets 程序被编译为 GUI Win32 应用程序,因此默认情况下使用WinMain()入口点,您没有定义。

The usual way to define it is by using wxIMPLEMENT_APP() macro, but you may also do it manually if you really need to -- but you must define it, one way or the other.定义它的常用方法是使用wxIMPLEMENT_APP()宏,但如果确实需要,您也可以手动进行定义——但您必须以一种或另一种方式定义它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM