- wxWidgets-3.1.3
- Eclipse IDE 4.14.0
- Eclipse CDT 9.10.0.2019x (the latest packages as of 2/2/2020)
- MinGW compiler, installed via MSYS2
- Windows 10 Pro
I have been using Eclipse for years for PHP, Python, JavaScript, and lua. I am, however, new to C++ and Eclipse CDT. I’ve got a reasonable enough grip on C++ syntax and convention that I’m ready to move on to the reason I came to C++, which is GUI. At first I tried Code::Blocks, which seemed simpler (I like wizards!), but I really would prefer an IDE with git integration, and I realised C::B didn’t have that before I managed to get compilation working. So, back to Eclipse.
So far, I have done the following:
- added the MinGW compiler path to %PATH%
- successfully compiled wxWidgets 3.1.3 using SHARED=0 UNICODE=1 MONOLITHIC=0 BUILD=release, these changes made in %WXDIR%buildmswconfig.gcc. The various tutorials I have found wildly disagree on these parameters, but the various responses to people with my problem here and on other forums have all been generally in agreement on them, and with the exception of BUILD, they’re the defaults. So.
- successfully compiled a test program from samples/minimal. The resulting executable runs without needing any other DLLs in the same directory.
Unfortunately, this is where I’m stuck. There are plenty of tutorials and forum posts out there, but I run into one or more of the following problems:
- Not newbie accessible. “Add a link to your wxWidgets directory” but okay, how do I do that, and do you mean the main %WXDIR% code directory or %WXDIR%lib or what?
- Don’t work. “Just File->Import->File System->%WXDIR%” and nope. Did, in fact, get rid of the “not resolved” for SOME references in code pasted from “minimal.cpp”, but not all.
- Explicitly refer to versions of the IDE or Code from, oh, say, ten years ago, and/or contain instructions that cannot be followed in the current version.
Alternately, I would take a recommendation for another GUI toolkit that has accessible instructions for getting the current version of itself working with the current version of Eclipse.
3
Answers
So you start with a brand new project for C++.
Then you add the source code for minimal sample there.
Next you open the project properties you open “C++ Build” -> “Settings” and under “C++ Compiler”->”Directories”, you add all your include directories.
Then you go to “C++ Linker”->”Libraries” and add the libraries and a path to them.
Let us know if you still have problems?
I’ll show how to compile the wxWidgets minimal sample with MinGW and eclipse. First of all, I highly recommend that you build both a debug and a release version of the wxWidgets library. These directions will assume that is the case. I’m not an expert with eclipse, so I can’t guarantee these are the best directions. These directions do work for me, but corrections and improvements are welcome.
There are many, many steps here. But if you get a working project with the minimal sample, you can copy the project and change the code files to use it for further projects.
Before we do anything else, define the
WXWIN
environment variable in eclipse if it not already defined. From the menu select Window->Preferences->C/C++->Build->Environment, and the press the add button to add the variable.The easiest way to build the minimal sample that comes with the library is with the command line. To do this, simply change to the WXWINsamplesminimal folder and enter the exact same command you used to build the library. Since the command given above was
mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 MONOLITHIC=0 BUILD=release
, this will result if the following commands being executed in the shell:If we do the same command with
build=debug
instead we get similar commands with just a few differences:To build the sample with eclipse, we want to make it execute roughly the same commands accounting for the slight differences between the debug and release configuratins. Select File->New->C/C++ project->C++ Managed Build. Enter a project name, select MinGW GCC, make sure the project type is Executable/Empty project, and click the finish button.
Now add a file to the project. You can either
Either way, there should now be a file named minimal.cpp in the project. To build this file, several settings need to be changed. From the menu, select Project->Properties->C/C++ Build->Settings
For GCC C++ Compiler:
__WXMSW__
,_UNICODE
,HAVE_W32API_H
, andNOPCH
.NDEBUG
${WXWIN}include
${WXWIN}libgcc_libmswud
${WXWIN}libgcc_libmswu
Optimize more (-O2)
Default (-g)
-mthreads -W -Wno-ctor-dtor-privacy
at the end of the “Other flags” box.For MinGW C++ Linker:
wxmsw31ud_core
,wxbase31ud
,wxtiffd
,wxjpegd
,wxpngd
,wxzlibd
,wxregexud
, andwxexpatd
wxmsw31u_core
,wxbase31u
,wxtiff
,wxjpeg
,wxpng
,wxzlib
,wxregexu
, andwxexpat
kernel32
,user32
,gdi32
,comdlg32
,winspool
,winmm
,shell32
,shlwapi
,comctl32
,ole32
,oleaut32
,uuid
,rpcrt4
,advapi32
,version
,wsock32
,wininet
,oleacc
, anduxtheme
.${WXWIN}libgcc_lib
-mthreads -mwindows
--subsystem=windows
.-g
to the existing contents.Both the debug and release configurations will now build, but the application isn’t complete quite yet. The first thing done building the minimal application in the command prompt was
According to this link, eclipse just doesn’t support building resource files, so we need to handle this manually.
Now go back Project->Properties->C/C++ Build->Settings->Build Steps.
windres --use-temp-file -i"${ProjDirPath}/sample.rc" -o"${CWD}minimal_sample_rc.o" --define __WXMSW__ --define _UNICODE --include-dir ${WXWIN}libgcc_libmswud --include-dir ${WXWIN}include --define NOPCH
windres --use-temp-file -i"${ProjDirPath}sample.rc" -o${CWD}minimal_sample_rc.o --define __WXMSW__ --define NDEBUG --define _UNICODE --include-dir ${WXWIN}libgcc_libmswu --include-dir ${WXWIN}include --define NOPCH
Next switch back to the Tool Settings tab:
${CWD}minimal_sample_rc.o
These 2 extra steps will make eclipse compile the resource file and link the resources into the final executable.
Very helpful! Also works for the DLL version with library path
${WXWIN}libgcc_dll
instead of${WXWIN}libgcc_lib
.For a standalone executable, one might extract required DLLs from the vxWidgets library. A minimum post-build step for this is …
DEBUG:
RELEASE: