Tips'n'Tricks

From Code::Blocks
Revision as of 16:32, 9 April 2006 by Sethjackson (talk | contribs) (Started merging Running under colinux)

Personalities

In Code::Blocks context, personalities are different sets of settings each tailored for a different workflow. Let me explain.

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:
  • --personality="Lite"
Tip: if you want to see a list of all defined personalities and select which one to use, replace the above with the following:
--personality=ask

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 "--personality=<name>", where <name> is the personality's name or "ask" 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 [1] 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"
install to c:\coLinux and not c:\Program Files\coLinux, since /dev paths are relative to the installation directory
don't bother downloading and installing WinPCAP (the included TAP driver works fine)
hit "continue anyway" for the tap driver installation
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.

- 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.
[2] [3]

usage:
dmdiag > out.txt
winobj -
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.

now create a batch script (c:\coLinux\colinux.bat) to launch colinux:
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

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.

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.