Building wxWidgets 2.8.0 as a DLL with MingW/GCC
I have been using the wxWidgets Cross-platform library for my C++ projects for about 3 years now, and I must say it rocks. A stable version 2.8.0 of the library has just been released, which deprecates some of the classes and functions in 2.6 so I had to upgrade. I had some problems initially with setting up my development environment to use the library, because it is distributed as source and thus it is the user’s responsibility to compile it. The authors supply a variety of makefiles for different compilers, but some work without hassles and the others you have to tweak.I use MingW with Dev-C++, so my makefile was makefile.gcc, in the ‘build’ directory under the source tree.
wxWidgets source tree
My first problem was that [compiler] (version 3.4.2, that is) emitted warnings on almost every definition in the source files, like “warning: type attributes are honored only at type definition”. I thought it was a problem with the source code at first, but a little googling and personal research revealed that this was an issue with [compiler] 3.4.x, and had been corrected as at 4.2. My first instincts were to stop compiling and get the latest version of the MingW tools, but I noticed that MingW was still using [compiler] 3.4.5 as its latest! I decided to ignore the warning messages - after all,they ARE just warnings, aren’t they?
The configuration of the library is done in a file called config.gcc, in the same directory as the makefile. There you get to enable/disable options, and specify such things as the build type, vendor specific names, etc. Being my finicky self, I noticed that the makefile creates DLL files with names like “wxmsw28ud_gcc.dll” for the unicode debug shared library build, and “wxmsw28ud.a” for the unicode debug static build (I was creating the monolithic build). I didn’t want the the extra “_gcc” appended to the name of the DLL file, so I started messing with the makefile. I looked for the lines that said
__monodll___depname = \
$(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)
$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gcc$(VENDORTAG).dll
and
ifeq ($(SHARED),1)
ifeq ($(USE_GUI),1)
ifeq ($(USE_OPENGL),1)
__gldll___depname = \
$(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)
$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl_gcc$(VENDORTAG).dll
endif
endif
endif
and I removed the “_gcc$(VENDORTAG)” part. In the “TARGETS” section of the makefile, I also modified the makefile to read similar to the lines below:
ifeq ($(MONOLITHIC),1)
ifeq ($(SHARED),1)
$(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)
$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR).dll: $(MONODLL_OBJECTS) $(OBJS)\monodll_version_rc.o
and
ifeq ($(SHARED),1)
ifeq ($(USE_GUI),1)
ifeq ($(USE_OPENGL),1)
$(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)
$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.dll: $(GLDLL_OBJECTS) $(OBJS)\gldll_version_rc.o
so that static libraries would be output as “libwxmsw28.a” and “libwxmsw28_gl.a”, and the shared library would be “libwxmsw28.dll.a”, “libwxmsw28_gl.dll.a”, “wxmsw28.dll” and “wxmsw28_gl.dll”. You can compare the original wxwidgets makefile and config.gcc, with my own Modified makefile and config.
After doing this, I ran make on the makefile twice; once to build the static version and the second time to build the shared libraries. I can decide to use either version in my development, as the need may arise. You have to note that if you are using the DLL (shared) library, you have to add
-DWXUSINGDLL
to your compiler directives, as this instructs the compiler of the version that you are using. If you don’t, you’ll get linker Info messages during compilation and even compile successfully, but your application will not run.
I am creating a DevC++ DevPack for the latest versions of the MingW compiler tools I used, and my static and shared wxWidgets 2.8, so look out for them in the downloads section.
on March 29th, 2007 at 9:26 pm
Thank’s. For first time i try to use devc++ and widgets, and i dont know how i compile the makefile.
I am looking around but i am first at all those things.