Difference between revisions of "Tips'n'Tricks"

From Code::Blocks
(Finished merging Running under colinux)
Line 1: Line 1:
== Personalities ==
+
====[[Personalities]]====
 
+
====[[Fixing Internal Errors]]====
In Code::Blocks context, personalities are different sets of settings each tailored for a different workflow. Let me explain.
+
====[[Running under colinux]]====
 
 
The "default" personality is, well, Code::Blocks as you know it :)
 
 
 
By default, all available plugins are loaded and all the manager panes are open (project manager, message manager, etc).
 
Now, let's assume that you want a more lightweight Code::Blocks to quickly work on testing single-source files. Most plugins are not needed for this kind of job so it would be wise to remove them from the loading process. You would also like the manager panes to be hidden by default.
 
 
 
To accomplish the above task, a new Code::Blocks personality should be created. Here is how:
 
 
 
*Find the shortcut to Code::Blocks on your desktop. If there isn't any, create one.
 
*Make a copy of this shortcut and rename it to "Code::Blocks Lite" (for example). You should now have two shortcuts to Code::Blocks on your desktop.
 
*Right-click on the "Code::Blocks Lite" shortcut and choose "Properties". In the "Target" box, append the following magic words:
 
*<code>--personality="Lite"</code>
 
 
 
:'''''Tip''''': ''if you want to see a list of all defined personalities and select which one to use, replace the above with the following'':
 
:<tt>--personality=ask</tt>
 
 
 
This will cause Code::Blocks to use the "Lite" personality when it starts-up.
 
"But we haven't defined "Lite" anywhere yet!", I hear you cry out. Fear not! Code::Blocks is smart enough to create a new personality for you, if the one you entered does not exist.
 
 
 
After you 've done the above changes to the "Lite" shortcut and saved it, launch Code::Blocks.
 
Although you may see no changes, Code::Blocks will be operating under the personality "Lite". This means, effectively, that any personalities-aware configuration changes you make will be done on the "Lite" personality.
 
 
 
To see this in action, let's return to our example scenario and turn the "Lite" personality into really light ;)
 
 
 
*Go to "Plugins->Manage plugins" and disable (uncheck) all plugins except the compiler.
 
*Now hide the "Manager" (Shift-F2) and "Messages" (F2) panes (in the "View" menu).
 
*Exit Code::Blocks.
 
*Launch Code::Blocks again, by clicking on the "Lite" shortcut. Everything should be as configured: no manager panes showing and just one plugin loaded. Congratulations!
 
 
 
But an astute reader shouts: "Hey, Code::Blocks always remembered my changes and started like it was last closed. What's the difference? Are you kidding us?"
 
Here's where the power of personalities comes in :)
 
 
 
*Close Code::Blocks.
 
*Now launch Code::Blocks by clicking on the standard shortcut (no "--personality" command-line option). Tadaa! Code::Blocks in its full capacity!
 
 
 
 
 
As an overview, to define and use a new personality you just have to launch Code::Blocks with the command-line option "<tt>--personality=<name></tt>", where <tt><name></tt> is the personality's name or "<tt>ask</tt>" if you want to be asked which personality to use (of the existing ones). After that, Code::Blocks will work under the selected personality for this session.
 
 
 
== Fixing internal errors ==
 
 
 
If Code::Blocks crashes for some reason, it will often then give weird "Internal Error" messages.
 
 
 
I've found that they can usually be solved by deleting the Code::Blocks configuration files.  On linux, these are usually in a .CodeBlocks or .Code\:\:Blocks\ v1.0 folder in your home directory, so they can be cleared with
 
$ rm -R ~/.Code*
 
The Code Completion plugin used to cause these problems alot, but it's much more stable now.
 
 
 
== Running under colinux ==
 
 
 
Setting up a dual-boot system is easy to do these days, but switching to linux requires a reboot.  What colinux does is let you run your linux distribution under windows.  They also have the option of downloading a debian or gentoo filesystem instead and using that basic linux system (it's missing lots of packages though, but they do support apt-get/emerge).  This is a walkthrough for setting up colinux to work with an existing linux distribution on another hard drive partition, since it's the more complicated (and useful) of the two options.
 
 
 
- download colinux
 
[http://www.colinux.org/snapshots/stable-coLinux-20050524.exe]
 
That's the 5/24/05 snapshot under Development Snapshots from the homepage.  It's stable as far as I can tell and they've fixed a couple major bugs since stable.
 
 
 
- run the installer
 
check everything except uncheck "Root Filesystem image Download" <br>
 
install to c:\coLinux and not c:\Program Files\coLinux, since /dev paths are relative to the installation directory <br>
 
don't bother downloading and installing WinPCAP (the included TAP driver works fine) <br>
 
hit "continue anyway" for the tap driver installation <br>
 
goto Network Connections under control panel and right click on the newly installed LAN connection (TAP-Win32 Adapter V8 (colinux)).  You may want to set configure->advanced->media status to "always connected".  Set the ip (tcp/ip properties) to a new ip address on your lan.  E.g. my hardware firewall my internet address 68.x.x.x.  Then one computer gets 192.168.1.2 and the other one (wireless connection) gets 192.168.1.3.  They both set the gateway field to 192.168.1.1 (configured in the hardware firewall settings).  So I set the TAP adapter ip to 192.168.1.4, it's gatway to 192.168.1.1 and the dns servers to those given to me by my isp (68.x.x.x).  Now select both your network connection and the TAP lan connection (ctrl-click) and then right click on one of them and select Bridge Connections.  Now right-click the Network Bridge and set the tcp/ip address to the same one your internet connection uses (192.168.1.3 here).  Also put in the dns servers and gateway.  You may need to right-click the Network Bridge and click Disable followed by Enable to get the connection working.  What happens is that your windows internet connection is still the same ip (192.168.1.3) but from within colinux, your TAP eth0 connection will use the new ip given to the TAP connection (192.168.1.4).  So colinux looks like a new box on your LAN. <br>
 
 
 
- create a configuration script
 
first you need to find out which partitions your linux distribution uses as seen by windows.  download either Dmdiag.exe from Microsoft or WinObj.zip from Sysinternals. <br>
 
[http://download.microsoft.com/download/win2000platform/WebPacks/1.00.0.1/NT5/EN-US/Dmdiag.exe]
 
[http://www.sysinternals.com/Files/WinObj.zip]
 
 
 
usage: <br>
 
dmdiag > out.txt <br>
 
winobj - <br>
 
check \GLOBAL?? for the name of your windows partitions (C:, D:).  I have \Device\HarddiskVolume1 and \Device\HarddiskVolume2 for C: and D:.  The next partition is probably the linux one.  Goto \Device\Harddisk0 to see all the partitions on the disk. <br>
 
 
 
now create a batch script (c:\coLinux\colinux.bat) to launch colinux: <br>
 
colinux-daemon.exe -t nt mem=256 kernel=vmlinux hda6=\Device\Harddisk0\Partition3 hda7=\Device\Harddisk0\Partition4 root=/dev/hda6 eth0=tuntap cofs0=c:\coLinux 3 <br>
 
 
 
This means use the standard NT console (better because you can cut&paste using the mouse), give 256mb of ram to colinux, specifies the name of the kernel, the linux partitiions, virtual ethernet adapter, and a shared directory which can be used to copy files between the colinux and windows systems. <br>
 
 
 
My linux root (/) partition is /dev/hda6 and swap partition is /dev/hda7.  These correspond to \Device\Harddisk0\Partition3 and \Device\Harddisk0\Partition4 under windows (note that windows doesn't reserve a partition name for the extended partition -- my linux partitions are logical and not primary partitions).  The root is given to be /dev/hda6, and you can just put tuntap for eth0, which will find the TAP connection we setup.  cofs0 will be the device name of the shared folder to use to transfer files to/from windows.  The 3 on the end is passed to the kernel as a kernel parameter.  It means enter runlevel 3 (init 3).  I need to do this since my default runlevel on boot is 5 which starts KDE, but this will crash colinux since it doesn't support X under colinux. <br>
 
 
 
<nowiki>#</nowiki>!/bin\sh<br>
 
<nowiki>#</nowiki>/usr\bin\colinuxnet.sh<br>
 
ifconfig eth0 192.168.1.4 && route add default gw 192.168.1.1 <br>
 
ifconfig eth0 192.168.1.4 && route add default gw 192.168.1.1 <br>
 
 
 
<nowiki>#</nowiki>!/bin\sh <br>
 
<nowiki>#</nowiki>/usr\bin\off.sh <br>
 
shutdown -h now <br>
 
 
 
<nowiki>#</nowiki>/etc/colinuxdisplay <br>
 
export DISPLAY=192.168.1.3:0.0 <br>
 
 
 
be sure to make the shell scripts executable: chmod a+x /usr/bin/colinux.net /usr/bin/off.sh
 
Note that shutdown -h now is the proper way to stop colinux (don't just click the console X button).  The 192.168.1.3 address is the address of my ethernet connection under windows.  0.0 specifies the first X display. <br>
 
 
 
Modify /etc/fstab to mount the cofs0 windows directory: <br>
 
<nowiki>#</nowiki>/etc/fstab <br>
 
... <br>
 
cofs0 /mnt/cofs cofs noauto,users,defaults 0 0 <br>
 
 
 
Notice there is no /dev prefix.  This won't automount and will be mountable by normal users (and not fsck checked). <br>
 
Create /mnt/cofs: <br>
 
mkdir /mnt/cofs <br>
 
chmod 777 /mnt/cofs (or chown username:users /mnt/cofs) <br>
 
To mount: <br>
 
mount /mnt/cofs <br>
 
 
 
You can copy both to and from c:\coLinux now. <br>
 
 
 
- setup Xming
 
[http://www.freedesktop.org/~ago/Xming/Xming-20050705-setup.exe]
 
Run the installer and don't bother to configure xlaunch.  It just writes out a config file for later use but we'll just pass everything on the commandline anyway. <br>
 
 
 
create some batch files to run X: <br>
 
rem c:\coLinux\runx.bat <br>
 
@echo off <br>
 
SET DISPLAY=127.0.0.1:0.0 <br>
 
SET REMOTE_HOST=192.168.1.4 <br>
 
SET LOCAL_HOST=192.168.1.3 <br>
 
start C:\Progra~1\Xming\Xming.exe -query %REMOTE_HOST% -nodecoration -lesspointer -from %LOCAL_HOST% -clipboard <br>
 
 
 
rem c:\coLinux\runx_multiwindow.bat <br>
 
@echo off <br>
 
SET DISPLAY=127.0.0.1:0.0 <br>
 
SET REMOTE_HOST=192.168.1.4 <br>
 
SET LOCAL_HOST=192.168.1.3 <br>
 
start C:\Progra~1\Xming\Xming.exe -nodecoration -lesspointer -from %LOCAL_HOST% -clipboard -multiwindow -ac <br>
 
 
 
Remote host is the colinux host and local host is the windows host.  You may need to forward TCP port 6000 on your firewall to allow colinux to communicate over TCP with the Xming server.  The first batch script is for use with XDMCP ([http://freedesktop.org/wiki/Xming]).  This will allow KDE to run under Xming.  Details: <br>
 
vi /opt/kde/share/config/kdm/Xaccess <br>
 
  *
 
This will allow access from all hosts <br>
 
vi /opt/kde/share/config/kdm/kdmrc <br>
 
  [Xdmcp] Enable=true
 
Enables XDMCP <br>
 
vi /usr/X11/xdm/Xservers <br>
 
  #:0 local /usr/X11R6/bin/X
 
Comment out that line so that the linux X doesn't start by default. <br>
 
vi /usr/X11/xdm/Xaccess <br>
 
  *
 
Not sure if that's really needed.  Same idea as the kdm/Xaccess though.  I think this is similar to doing xhost +. <br>
 
Note that everything still starts up and runs normally if I reboot into linux through grub/lilo.  These changes didn't prevent KDE or X from starting up. <br>
 
 
 
The second batch file (multiwindow) is used for when you don't want a full KDE on windows, but just want the linux consoles (alt-f4 to get multiple consoles does work) and a couple graphical linux applications to run under Xming.  The -ac flag disables access control (needed since we are not using XDMCP and otherwise you get errors involving mit cookies or access denied).  To test this mode: <br>
 
run colinux.bat <br>
 
run runx_multiwindow.bat <br>
 
under linux: <br>
 
. /etc/colinuxdisplay (or source /etc/colinuxdisplay) <br>
 
try: ddd (assuming it's installed on your linux distro). <br>
 
 
 
That should be all there is to it to get codeblocks running under colinux (after compiling codeblocks under linux of course). <br>
 
 
 
=== Compiling from source ===
 
 
 
The reason to want to do this is if you want to use a different kernel than the one provided by the colinux installer (currently 2.6.11).  If you want to compile your own modules or add something to the kernel then this might be the way to go.  If you just try to compile a new kernel and then run it under the existing colinux binaries you will get an ABI mismatch unless you compiled with their version of gcc they used (3.3.x) to cross compile the colinux binaries, so it's probably best to just setup your own cross compiler under linux and recompile the source.  Note that colinux runs in kernel mode, but does not allow linux to do direct hardware access.  It writes a layer and then hands hardware requests to windows.  So no sound output is supported (yet) and X doesn't run under linux (yet - but you can use xmingw as described above).  It's best not to modify the kernel settings from what the colinux .config file provides too much.  You will need a working linux installation and an internet connection to compile from source. <br>
 
 
 
- grab the source
 
[http://www.colinux.org/snapshots/stable-colinux-20050524.tar.gz]
 
 
 
- switch to linux
 
I actually recompiled everything from within colinux which works fine.  You could also reboot into linux. <br>
 
 
 
- extract the source and compile
 
I used /usr/src as the base directory.  You can use /home/username if desired. <br>
 
cd /usr/src; tar xfz stable-colinux-20050524.tar.gz
 
cd stable-colinux-20050524
 
 
 
Your linux distribution needs a couple of things to be able to setup the cross compiler and compile the daemons.  I needed to grab and install: <br>
 
unix2dos-2.2.src.tar.gz
 
 
 
The configure script will let you know about any other missing dependencies (Everything else was present here: LFS & BLFS installation).  Make sure you have wget installed since all needed mingw packages are fetched with it. <br>
 
 
 
Edit bin/build-common.sh <br>
 
      GCC_VERSION="3.4.4"
 
      GCC_RELEASE="$GCC_VERSION-20050522-1" 
 
      GCC_PATCH="gcc-core-$GCC_RELEASE-src-fix1.patch"
 
      MXML_URL=http://ftp.easysw.com/pub/mxml/1.3
 
 
 
Needed patch: <br>
 
<nowiki>#########</nowiki>begin gcc-core-3.4.4-20050522-1-src-fix1.patch<nowiki>##########</nowiki>
 
<pre>
 
diff -urN gcc-3.4.4-20050522-1.old/gcc/crtstuff.c gcc-3.4.4-20050522-1/gcc/crtstuff.c
 
--- gcc-3.4.4-20050522-1.old/gcc/crtstuff.c 2005-08-18 15:46:45.000000000 -0400
 
+++ gcc-3.4.4-20050522-1/gcc/crtstuff.c 2005-08-18 15:53:00.000000000 -0400
 
@@ -602,7 +602,8 @@
 
#if defined (USE_EH_FRAME_REGISTRY) \
 
    && !__USING_SJLJ_EXCEPTIONS__
 
static int __EH_FRAME_END__[]
 
-    __attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME),
 
+/*    __attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME), */
 
+    __attribute__ ((unused, section(EH_FRAME_SECTION_NAME),
 
    aligned(4)))
 
      = { 0 };
 
static void __reg_frame_ctor (void) __attribute__ ((constructor));
 
</pre>
 
<nowiki>#########</nowiki>end gcc-core-3.4.4-20050522-1-src-fix1.patch<nowiki>#########</nowiki> <br>
 
Save the above (between the <nowiki>###</nowiki> marks) to gcc-core-3.4.4-20050522-1-src-fix1.patch <br>
 
mkdir /usr/src/download (mkdir /home/username/download if using home directory)
 
mv gcc-core-3.4.4-20050522-1-src-fix1.patch /usr/src/download
 
 
 
The patch is needed for gcc 3.4.4 to compile as a cross compiler using sjlj exceptions (dwarf exceptions don't work well under windows it seems).  Otherwise you get errors about the mode(SI) statement. <br>
 
 
 
Compile: <br>
 
./configure
 
make
 
make # I got md5sum creation errors, but things resumed ok -- just type make again...
 
make install
 
 
 
This will download and install a mingw cross compiler under linux.  It will then proceed to compile the windows colinux daemons and finally the colinux kernel.  The kernel source will be in a subdirectory of the directory you are compiling from (/usr/src/linux-2.6.11-co or something).  You can later recompile the colinux kernel by switching to this directory and doing: <br>
 
make menuconfig # set kernel options...don't change too much or it may not work with colinux
 
make vmlinux
 
make modules modules_install # installed to /lib/linux-2.6.11-co i believe
 
 
 
Then just move the /usr/src/linux-2.6.11-co/vmlinux kernel image to c:\coLinux (backup the old one in case).  Fyi, the kernel patch they are using is under stable-colinux-20050524/patch/linux and the kernel .config file is stable-colinux-20050524/config/linux-config <br>
 
(tar xfz linux-2.6.11-12.tar.gz; cd linux-2.6.11-12; patch -p1 -i  <br> stable-colinux-20050524/patch/linux; cp stable-colinux-20050524/config/linux-config .config) <br>
 
to start from fresh kernel.org sources.  note that only up to 2.6.11-X is working.  A patch is available on colinux.org for 2.6.12 but I haven't tried it. <br>
 
 
 
Btw the make install above just installs to a subdirectory (dist/).  It won't touch /usr or /usr/local.  Once everything completes you can just tar the dist directory and copy to your windows directory: <br>
 
tar cfz dist.tar.gz dist
 
mount /mnt/cofs
 
mv dist.tar.gz /mnt/cofs
 
Winrar supports extracting from .tar.gz and .tar.bz2 archives (7zip does too I believe).
 
That's all that should be required to build colinux from source and compile custom colinux kernels.
 
Make sure you use the same gcc major version (gcc 3.4.x here) to compile both the daemons and kernel (the automatic kernel build run by the colinux install scripts does this by default). <br>
 

Revision as of 18:49, 9 April 2006