Difference between revisions of "Compiling wxWidgets 2.6.2 to develop Code::Blocks (MSW)"

From Code::Blocks
Line 106: Line 106:
 
<br>
 
<br>
 
1.  When creating a wx project in codeblocks, the link stage fails with cannot find -lwxmsw.  I needed to:<br>
 
1.  When creating a wx project in codeblocks, the link stage fails with cannot find -lwxmsw.  I needed to:<br>
copy C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw26.a to C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw.a  <br>Edit:(? - no make sense)<br>
+
copy C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw26.a to C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw.a  <br>
 
copy C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw26_stc.a to C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw_stc.a <br>
 
copy C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw26_stc.a to C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw_stc.a <br>
 
+
Edit:(? - no make sense)<br>
 
or mess with the autogenerated makefile (they don't use WX_VER anymore it seems...) which is more of a hassle. <br>
 
or mess with the autogenerated makefile (they don't use WX_VER anymore it seems...) which is more of a hassle. <br>
 
<br>
 
<br>

Revision as of 22:50, 1 January 2006

These are the instructions to compile wxWidgets so that you can compile Code::Blocks on your own.

NOTE: These instructions are MS Windows (TM) specific, but because we are using MinGW it should be possible to use these instructions with some modifications on other platforms.

Install MinGW

If you don't have the Code::Blocks + MinGW bundle, grab the latest MinGW stuff from the MinGW site and install it under a directory you like. NOTE: In these instructions we're calling the MinGW directory <MINGW>, so you have to replace that with you're own directory.

If you DO have the Code::Blocks + MinGW bundle, or have already installed MINGW on your own, you can skip this section.

NOTE: The files are compressed in the tar.gz format. You need a third-party extraction utility to unzip them. (like 7-zip)

You need at least the following files:

GDB is not really needed, but could be usefull for debugging.

After you install, make sure you have the following directories under your path:

  • <MINGW>\bin;
  • <MINGW>\mingw32\bin;

Download and Install the wxWidgets source code

The wxWidgets 2.6.1 distribution can be found at the wxWidgets website. (Note that there is also a winhelp file available.) You can choose between an installer and a zip file. You can just get the zip file because the installer is also a zipped version.

If you use the plain zip version, make sure to unzip using the full path. Otherwise the directories won't be created correctly.

NOTE: Download and apply the patches for wxWidgets 2.6.1 source code. wxWidgets Patches for 2.6.1. Various wxMSW fixes: http://www.wxwindows.org/patch.htm ftp://biolpc22.york.ac.uk/pub/2.6.1/wxWidgets-2.6.1-Patch01.zip

NOTE: In the rest of these instructions we are calling the wxWidgets directory <WXWIN> you have to change it to your own directory. (e.g. "c:\wxWidgets-2.6.1")

NOTE: you do not need MSYS. Furthermore, you cannot have MSYS in your path, or the wxWidgets compilation will fail. Thus if you have MSYS installed, ensure that <MSYS>\bin is not in your path before compiling wxWidgets. wxWidgets must be compiled from a "regular" command line (cmd.exe), not from a unix-like shell. BTW, The same problem would probably arise as well if cygwin is in the path.

Check make version

If you didn't install MingW yourself you have to make sure you have the right version of make. Open the command prompt and type:

mingw32-make -v

If the version is 3.80 or greater it is allright to go on, else you have to install the new make.

Building wxWidgets

Now it is time to compile wxWidgets, open the command promt and change to the wxWidgets directory:

cd <WXWIN>\build\msw

NOTE: The following directions do not work with msys, or other forms of Unix on windows.

Regaurding warning: type attributes are honored only at type definition:
the warnings are because the makefile turned all warnings on... you can easily edit it at ur wishes -lowjoel (Moderator wxWidgets forum) {http://www.solidsteel.nl/users/wxwidgets/viewtopic.php?t=3324&start=0&postdays=0&postorder=asc&highlight=&sid=12dc997430a4cb2bc99f0175699f58de}

Now we are on the right place we are first going to clean up the source:

mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 clean 

NOTE: make sure you use the same options to clean that you use for the build step below. the clean target uses these environment variables and only cleans that version of the generated object and library files (so it will actually not clean the intended files if these variables are not present)
NOTE: if you still have problems with compiling after cleaning, you may want to remove the directory in the build\msw directory. (it contains object files...) When everything is clean we can compile wxWidgets:

mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 VENDOR=cb

NOTE: these options are the official Code::Blocks options. When you want another version of wxWidgets (unicode or debug) you have to make sure you build a MONOLITHIC version. (One big dll) Now you can get a cup of coffee, or do something else, because this could take a long time.

Build the STC library (Not needed for CVS HEAD version of Code::Blocks)

If you closed the command prompt, you have to open it again. We are going to the STC directory

cd ..\..\contrib\build\stc

We clean the source:

mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 clean

And we going to compile it. Make sure you have the same build options as before.

mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 VENDOR=cb

So now everything is compiled for using with codeblocks.

Copy libraries

When compilation is finished it is usefull to copy the libs to another directory. By doing this you can make several builds (e.g. debug and release).

  • So first we create a directory this could be done in <WXWIN>\lib.
  • Then we go to the directory <WXWIN>\lib\gcc_dll (could called diffrent when you changed the build options)
  • Now we move all the files (.a .dll) and the directory (msw) to the directory of your choice. (for me it is <WXWIN>\lib\codeblocks)

NOTE: Make sure you everything is removed from the directory <WXWIN>\lib\gcc_dll else you can get trouble when compiling another version.

Setting up paths

Everything is done now, and we can start compiling Code::Blocks, couldn't we? No! First we have to setup the paths. Open the codeblocks project (CodeBlocks-wx2.6.0.cbp) and go to the Build options. From there you have to go to the tab Directories and Compiler. Here you have to add the following paths (Remember to replace <WXWIN>)

  • <WXWIN>\lib\codeblocks\msw
  • <WXWIN>\include
  • <WXWIN>\contrib\include

The first path is used to find the right setup.h for the build you are using. The other two are for the normal include files.

Now go to the Linker tab and add the following path:

  • <WXWIN>\lib\codeblocks

NOTE: You have to replace this with the directory of your own choice in the previous section!

Finally, go to the resource tab and add the following path (Remember to replace <WXWIN>)

  • <WXWIN>\include

Now you are finished with the configuration and you can hit the compile button (CTRL-F9). Be aware that Code::Blocks does not officially support wxWidgets 2.6.1 so it is possible that new files are not yet in the project. You have to do this by yourself.

Post compilation steps (before running C::B)

When compilation process is finished, simply run the update.bat script. It will ensure that all resource files (that C::B uses) are in the right place and up to date.

Note: This step requires appropriate zip command, which you likely have already set up and working. However, in case you have not, you should find something usable here.


Edit: I didn't see any update.bat script but no matter. Two changes to this howto to get everything to work.
1. When creating a wx project in codeblocks, the link stage fails with cannot find -lwxmsw. I needed to:
copy C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw26.a to C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw.a
copy C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw26_stc.a to C:\wxWidgets-2.6.1\lib\codeblocks\libwxmsw_stc.a
Edit:(? - no make sense)
or mess with the autogenerated makefile (they don't use WX_VER anymore it seems...) which is more of a hassle.

2. You will still get --enable-auto-import errors. Looks like you just need to add a define:
project->build options->compiler->#defines
WXUSINGDLL

Lastly it will look for wxmsw26_gcc_cb.dll and not find it. You have three possibilities

  • put wxmsw26_gcc_cb.dll and wxmsw26_stc_gcc_cb.dll in your PATH
  • or put wxmsw26_gcc_cb.dll and wxmsw26_stc_gcc_cb.dll in C:\windows\system32
  • or add C:\wxWidgets-2.6.1\lib\codeblocks to compile -> compiler options -> programs -> additional paths


Rebuild and everything should run ok.

Building wxWidgets 2.6.1 mingw32 & vc++ toolkit 2003


I'll just throw in my notes on the process for both compiler versions as getting vc++ toolkit to work is quite a pain. Code blocks needs a couple of changes to support wxWidgets on the vc++ toolkit seamlessly.


for mingw32 compiler



cd <WXWIN>\build\msw
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb clean
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb
stc is no longer needed for latest codeblocks (cvs version) which uses wxscintilla:
cd ..\..\contrib\build\stc
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb clean
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb
cd <WXWIN>\lib; move gcc_dll codeblocks_gcc

codeblocks

project->build options
	directories->compiler
		<WXWIN>\lib\codeblocks_gcc\msw
		<WXWIN>\include
		<WXWIN>\contrib\include
	directories->linker
		<WXWIN>\lib\codeblocks_gcc
	directories->resource compiler
		<WXWIN>\include
	compiler->#defines
		WXUSINGDLL

compile->compiler options
	programs->additional paths
		C:\wxWidgets-2.6.1\lib\codeblocks_gcc
-OR- copy C:\wxWidgets-2.6.1\lib\codeblocks_gcc\wxmsw26_gcc_cb.dll
     to application exe directory or c:\windows\system32
-OR- change project->properties->targets->execution working dir
     to C:\wxWidgets-2.6.1\lib\codeblocks_gcc (not recommended)

copy C:\wxWidgets-2.6.1\lib\codeblocks_gcc\libwxmsw26.a
to C:\wxWidgets-2.6.1\lib\codeblocks_gcc\libwxmsw.a
copy C:\wxWidgets-2.6.1\lib\codeblocks_gcc\libwxmsw26_stc.a
to C:\wxWidgets-2.6.1\lib\codeblocks_gcc\libwxmsw_stc.a

compile->rebuild

for vc++ toolkit 2003 compiler


install VCToolkitSetup.exe
install PlatformSDK
install .NET Framework SDK Version 1.1
run PlatformSDK->Run all Windows XP 32-bit Build Environment (Retail) batch files (find them in PlatformSDK\Setup)
C:\Program Files\Microsoft Visual C++ Toolkit 2003\Vc7\bin\vcvars32.bat (not needed)

The following environment vars must be set/modified/added via 'Control Panel | System | Advanced | Environment Variables'.

set DOTNETSDK=C:\Program Files\Microsoft.NET\SDK\v1.1 (not needed)
set MSVC=C:\Program Files\Microsoft Visual C++ Toolkit 2003
set MSSDK=C:\Program Files\Microsoft Platform SDK
set VC7=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
set INCLUDE=%MSVC%\include;%MSSDK%\include
set LIB=%MSVC%\lib;%MSSDK%\lib;%VC7%\lib
set PATH=%MSVC%\bin;%MSSDK%\bin;%PATH%
set PATH=%PATH%;%MSSDK%\bin\Win64

cd <WXWIN>\build\msw
nmake -f makefile.vc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb clean
nmake -f makefile.vc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb
stc is no longer needed for latest codeblocks (cvs version) which uses wxscintilla:
cd ..\..\contrib\build\stc
nmake -f makefile.vc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb clean
nmake -f makefile.vc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode VENDOR=cb
cd <WXWIN>\lib; move vc_dll codeblocks_vc

codeblocks

project->build options
	directories->compiler
		<WXWIN>\lib\codeblocks_vc\msw 
		<WXWIN>\include 
		<WXWIN>\contrib\include
	directories->linker
		<WXWIN>\lib\codeblocks_vc
	directories->resource compiler
		<WXWIN>\include
	compiler->#defines
		WXUSINGDLL
	compiler->compiler flags
		enable c++ exception handling (or other options: /GX [same as /EHsc])
	compiler->other options
		delete -D__GNUWIN32__
	linker->link libraries
		delete ctl3d32

compile->compiler options
	programs->additional paths
		C:\wxWidgets-2.6.1\lib\codeblocks_vc
-OR- copy C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw26_vc_cb.dll
     to application exe directory or c:\windows\system32
-OR- change project->properties->targets->execution working dir
     to C:\wxWidgets-2.6.1\lib\codeblocks_vc (not recommended)

compile->compiler options
	programs->additional paths
		C:\Program Files\Microsoft Platform SDK\Bin
 	directories->compiler
		add C:\Program Files\Microsoft Platform SDK\Include		
	directories->linker
		add C:\Program Files\Microsoft Platform SDK\Lib

copy C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw26.exp
     to C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw.exp
copy C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw26.lib
     to C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw.lib
copy C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw26_stc.exp
     to C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw_stc.exp
copy C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw26_stc.lib
     to C:\wxWidgets-2.6.1\lib\codeblocks_vc\wxmsw_stc.lib

compile->rebuild


building from the commandline (wxwidgets demos)
nmake -f makefile.vc SHARED=1 MONOLITHIC=1 BUILD=release

Building unicode wxWidgets & CodeBlocks

I'm assuming you're using wxWidgets-2.6.2 and it's installed in c:\. Modify for different minor revisions or install paths.

1.  grab the latest SVN source
2.  open CodeBlocks-NewBuild.cbp with a text editor:
    replace all occurances of wxmsw26 with wxmsw26u
    replace all occurances of msw" with mswu"
    save this as CodeBlocks-NewBuild-unicode.cbp 
3.  open up a recent version of codeblocks which supports the new build .cbp files.  one of the latest svn binaries which you can find in the forums is your best bet
4.  open the CodeBlocks-NewBuild-unicode.cbp project file
5.  goto Project->Build options->Custom variables
    set WX_CFG=Unicode
6.  save the project and close codeblocks for the changes to take effect (reload the custom variables for the project)
7.  open codeblocks again and the project file

8.  rename any existing rename c:\wxWidgets-2.6.2\lib\gcc_dll to c:\wxWidgets-2.6.2\lib\gcc_dllNonUnicode
9.  open a start menu->run->cmd.exe prompt
    cd to c:\wxWidgets-2.6.2\build\msw
10. type:
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 CFG=Unicode VENDOR=cb
11. open c:\wxWidgets-2.6.2\lib\gcc_dllUnicode\msw\wx\setup.h
    make sure you have
    #define wxUSE_UNICODE 1
    (and not 0)

12. go back to codeblocks and select compile->rebuild
    set the wx global variable to c:\wxWidgets-2.6.2 if it prompts
13. once it finishes, run update.bat

Building codeblocks from source (using makefile)

Codeblocks can be used to build the source but here is how to build using just makefiles.

build wxWidgets-2.6.1 dll using mingw32
   mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 VENDOR=cb clean
   mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 VENDOR=cb
copy C:\wxWidgets-2.6.1\lib\gcc_dll to C:\wxWidgets-2.6.1\lib\gcc_dllUnicode (copy since wxDockIt expects gcc_dll to exists)
checkout CVS source codeblocks module (used VERSION_1_0 branch)
(beware path lengths - best to checkout to root directory - c:\)
download http://prdownloads.sourceforge.net/wxextended/wxDockIt_2.1.zip?download
extract wxDockIt to codeblocks\src\src
patch codeblocks\src\src\wxDockit\build\msw\makefile.gcc
   change "$(CXX) -shared -fPIC -o $@ $(WXDOCKIT_DLL_OBJECTS) $(LDFLAGS) -mthreads -L$(WX_DIR)$(__WXLIBPATH_FILENAMES) -L..\..\$(__WXDOCKIT_OUTPUT_FOLDER_FILENAMES_1) $(__DEBUGINFO) -mthreads -Wl,--out-implib,..\..\lib\gcc_dll\libwxdockit$(WXLIBPOSTFIX).a  -lwxmsw$(WX_VERSION)$(WXLIBPOSTFIX)_adv -lwxbase$(WX_VERSION)$(WXLIBPOSTFIX)_xml -lwxmsw$(WX_VERSION)$(WXLIBPOSTFIX)_core -lwxbase$(WX_VERSION)$(WXLIBPOSTFIX) -lwxtiff$(WX3RDPARTLIBPOSTFIX) -lwxjpeg$(WX3RDPARTLIBPOSTFIX) -lwxpng$(WX3RDPARTLIBPOSTFIX) -lwxzlib$(WX3RDPARTLIBPOSTFIX) -lwxregex$(WXLIBPOSTFIX) -lwxexpat$(WX3RDPARTLIBPOSTFIX) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32"
   to     "$(CXX) -shared -fPIC -o $@ $(WXDOCKIT_DLL_OBJECTS) $(LDFLAGS) -mthreads -L$(WX_DIR)$(__WXLIBPATH_FILENAMES) -L..\..\$(__WXDOCKIT_OUTPUT_FOLDER_FILENAMES_1) $(__DEBUGINFO) -mthreads -Wl,--out-implib,..\..\lib\gcc_dll\libwxdockit$(WXLIBPOSTFIX).a  -lwxmsw$(WX_VERSION)$(WXLIBPOSTFIX) -lwxtiff$(WX3RDPARTLIBPOSTFIX) -lwxjpeg$(WX3RDPARTLIBPOSTFIX) -lwxpng$(WX3RDPARTLIBPOSTFIX) -lwxzlib$(WX3RDPARTLIBPOSTFIX) -lwxregex$(WXLIBPOSTFIX) -lwxexpat$(WX3RDPARTLIBPOSTFIX) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32"
compile wxDockIt
   cd codeblocks\src\src\wxDockit\build\msw
   mingw32-make -f makefile.gcc WX_DIR=C:\wxWidgets-2.6.1 WX_SHARED=1 WX_DEBUG=0 WX_UNICODE=1 WX_VERSION=26 clean
   mingw32-make -f makefile.gcc WX_DIR=C:\wxWidgets-2.6.1 WX_SHARED=1 WX_DEBUG=0 WX_UNICODE=1 WX_VERSION=26
move codeblocks\src\src\wxDockit\build\msw\gcc_dll to codeblocks\src\src\wxDockit\build\msw\gcc_dllUnicode
edit codeblocks\src\src\Makefile.wx2.6
   change WX_DIR=C:/Devel/wxWindows-2.6.1 to WX_DIR=C:/wxWidgets-2.6.1
   change WX_CFG=NonUnicode to WX_CFG=Unicode
   global search+replace: replace " -lwxmsw26" with " -lwxmsw26u"
   global search+replace: replace "/msw" with "/mswu"
   replace "-Lsrc/wxDockit/lib" with "-Lsrc/wxDockit/lib/gcc_dll$(WX_CFG)"
   replace "..\wxDockit\lib\libwxdockit.a" with "src\wxDockit\lib\gcc_dll$(WX_CFG)\libwxdockitu.a"
edit C:\wxWidgets-2.6.1\lib\gcc_dllUnicode\mswu\wx\setup.h
   change "#define wxUSE_UNICODE 0" to "#define wxUSE_UNICODE 1"
start->run->cmd
cd codeblocks\src
mingw32-make -f Makefile.wx2.6 clean
mingw32-make -f Makefile.wx2.6
download ftp://ftp.info-zip.org/pub/infozip/MSDOS/zip231x.zip (infozip)
put zip.exe in some directory in your PATH (e.g. C:\MinGW\bin)
copy C:\wxWidgets-2.6.1\lib\gcc_dllUnicode\wxmsw26u_gcc_cb.dll to codeblocks\src\output\wxmsw26u_gcc_cb.dll and codeblocks\src\devel\wxmsw26u_gcc_cb.dll
copy src\src\wxDockit\lib\gcc_dllUnicode\wxdockitu.dll to and codeblocks\src\output\wxdockitu.dll and codeblocks\src\devel\wxdockitu.dll
update.bat
output\CodeBlocks.exe


Note:
If you are compiling the unicode version of wxWidgets (UNICODE=1) and CodeBlocks, then linker errors like:

wxscintilla.cpp:2551: undefined reference to `_imp___ZNK8wxString11BeforeFirstEc'
wxscintilla.cpp:2552: undefined reference to `_imp___ZNK8wxString10AfterFirstEc'
wxscintilla.cpp:2724: undefined reference to `_imp___ZN6wxFileC1EPKcNS_8OpenModeE'
wxscintilla.cpp:2736: undefined reference to `_imp___ZN6wxFileC1EPKcNS_8OpenModeE'

mean that you forgot to change "#define wxUSE_UNICODE 0" to "#define wxUSE_UNICODE 1" in wx\setup.h