简体   繁体   中英

Building wxWidgets Hello world

The wxWidgets hello world example does not provide sufficient information to build wxWidgets in any one particular environment.

The Code::Blocks wxWidgets hello world example does provide sufficient information, but it does not seem likely that a newbie, or even a quite sophisticated user, could figure out all the necessary steps on their own, because there are arcane magic words required.

The Code Yarns example uses CMake, thus could run in many particular environments, but seems to assume that you have already set up wxWidgets and compiled it for your particular environment, and there does not seem to be a CMakeLists.txt file to compile wxWidgets for your particular environment.

wxWidgets is supposed to be cross platform and cross environment, and I am trying to set up a project to compile in several environments: on Windows10 Visual Studio, Windows 10 TDM-GCC, Windows 10 Code::Blocks, Ubuntu Code::Blocks, and Ubuntu 10 gcc.

And apart from the Code::Blocks environments, having trouble. Apart from Code::Blocks, I cannot find "Hello World" examples that actually set up wxWidgets on the target so that the Hello World will actually compile and run.

The wxWidgets samples directory is not particularly useful, since the samples assume an environment, and do not describe setting up that environment and the actions that will cause the sample to build and run.

Installation guide

I know this is a old question but I struggled really hard to find a guide for an installation on wxwidgets. You can use the vckpg importer by Microsoft. Make sure you have git installed before you follow this routine. I will write this for Windows with Visual Studio 2017:

  1. Clone the following repository to a directory of your choice: git clone https://www.github.com/Microsoft/vcpkg
  2. Then open up powershell (ps) (run it as admin) and navigate to the cloned vcpkg folder
  3. Now in ps, while you are in the vcpkg folder run the following command \\.vcpkg integrate install so we have a user-wide integration of the vcpkg paket manager and can #include libraries in our c++ projects

  4. Now to install wxwidgets 32-Bit run \\.vcpkg install wxwidgets --triplet x86-windows . For the 64-Bit Version run \\.vcpkg install wxwidgets --triplet x64-windows

  5. Now open up the properties of your project in Visual Studio.
  6. For the integration of the 64-Bit wxwidgets version choose all configurations and as plattform x64. Then go to C/C++ -> General -> Additional Include Directories and add the following folderpath YOUR_FOLDER_PATH\\vcpkg\\packages\\wxwidgets_x64-windows\\include;YOUR_FOLDER_PATH\\vcpkg\\packages\\wxwidgets_x64-windows\\lib . Do the same for the x86 configuration but with the wxwidgets_x86-windows folderpath instead.
  7. As a last step go to in the properties under C/C++ -> Preprocessor and under the point Preprocessordefinition add the following as extra point WXUSINGDLL=1 (do it for the x64 and for the x86 plattform configuration if you want to use both)

Now you should be able to use the library and run the hello world project.

To build an app, first you need to have the library compiled. To achieve that you can get precompiled binaries or the sources (see Downloads ) and compile them yourself (see Building ).

Instructions might still not be perfect for everyone, and you are welcome to improve them - even call it your first contribution ;)

我正在寻找的安装说明可以在 wxWidgets/docs/install.txt 中找到

There are multiple ways to setup wxWidgets on Windows and use it in a project. If your project is going to use CMake there are 2 main options (other than compiling stuff yourself some other way):

  1. Use vcpkg - which, in theory, is the easiest, but I couldn't get it to work (in time). Here is some info on that: https://www.wxwidgets.org/blog/2019/01/wxwidgets-and-vcpkg/ The problem is find_package couldn't find the package, so then I just went to 2:
  2. Download the lastest compiled headers, libs & bins from the wxwidgets and put them in a folder like c:/wxwidgets . Then, in your Cmake file, before the call to find_package , do:

SET(wxWidgets_ROOT_DIR "c:/wxwidgets/")

SET(wxWidgets_LIB_DIR "c:/wxwidgets/lib/vc14x_x64_dll")

SET(wxWidgets_CONFIGURATION "mswd")

The LIB_DIR is using VS2019 x64 in my case. mswd just means build this for Debug

Finally, when adding the executable, do not forget the WIn32:

add_executable(membot WIN32 ${project_SRCS})

PS: Remember to extract the headers include folder near the lib .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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