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:
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:
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.
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 WXWIN\samples\minimal 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:
windres --use-temp-file -i../../samples/sample.rc -ogcc_mswu\minimal_sample_rc.o --define __WXMSW__ --define NDEBUG --define _UNICODE --include-dir .\..\..\lib\gcc_lib\mswu --include-dir ./../../include --include-dir . --include-dir ./../../samples --define NOPCH
g++ -c -o gcc_mswu\minimal_minimal.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I.\..\..\lib\gcc_lib\mswu -I.\..\..\include -W -Wall -I. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -MTgcc_mswu\minimal_minimal.o -MFgcc_mswu\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswu\minimal.exe @gcc_mswu\minimal.exe.rsp -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows -lwxmsw31u_core -lwxbase31u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet -loleacc -luxtheme
If we do the same command with build=debug
instead we get similar commands with just a few differences:
windres --use-temp-file -i../../samples/sample.rc -ogcc_mswud\minimal_sample_rc.o --define __WXMSW__ --define _UNICODE --include-dir .\..\..\lib\gcc_lib\mswud --include-dir ./../../include --include-dir . --include-dir ./../../samples --define NOPCH
g++ -c -o gcc_mswud\minimal_minimal.o -g -O0 -mthreads -DHAVE_W32API_H -D__WXMSW__ -D_UNICODE -I.\..\..\lib\gcc_lib\mswud -I.\..\..\include -W -Wall -I. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -MTgcc_mswud\minimal_minimal.o -MFgcc_mswud\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswud\minimal.exe @gcc_mswud\minimal.exe.rsp -g -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows -lwxmsw31ud_core -lwxbase31ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxregexud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet -loleacc -luxtheme
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:
${WXWIN}\include
${WXWIN}\lib\gcc_lib\mswud
${WXWIN}\lib\gcc_lib\mswu
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
, and wxexpatd
wxmsw31u_core
, wxbase31u
, wxtiff
, wxjpeg
, wxpng
, wxzlib
, wxregexu
, and wxexpat
kernel32
, user32
, gdi32
, comdlg32
, winspool
, winmm
, shell32
, shlwapi
, comctl32
, ole32
, oleaut32
, uuid
, rpcrt4
, advapi32
, version
, wsock32
, wininet
, oleacc
, and uxtheme
.${WXWIN}\lib\gcc_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
windres --use-temp-file ...
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}\lib\gcc_lib\mswud --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}\lib\gcc_lib\mswu --include-dir ${WXWIN}\include --define NOPCH
Next switch back to the Tool Settings tab:
These 2 extra steps will make eclipse compile the resource file and link the resources into the final executable.