You are currently only viewing entries by the user Carl Turner.

To view the other authors active here, click here, or to go back to view all items, click here.

Wednesday, 29 August 2007

Canon 99 Fix

A short description of a simple fix for "Err 99" # Permalink C Comment

Just a quick note to observe the simple solution to the "Err 99" message occasionally obtained with numerous Canon digital cameras - whilst this is not necessarily the cause, frequently, the problem is that the gold contacts are dirty. Solution? Easy: erase them. With a standard pencil eraser. At your own risk!

Other techniques which can work (i.e. try at your own peril) include:

  1. Re-inserting the CF card
  2. Re-inserting the battery pack
  3. Re-aligning the shutter curtain (lift mirror and brush lightly into place)
  4. Being careful about switching the camera off before changing lenses etc.
  5. Letting battery go flat whilst exposed (?!)

Worked for me!

(Source: richardnotes.org)

Posted by carl at 04:00

Tuesday, 10 July 2007

Installing GMP on Windows

A guide to installing GMP and GMPXX on Windows # Permalink

What is GMP?

The GNU Multi-Precision library, or GMP, is an essential component of the programmer who works with mathematics on a regular basis. The problem is, C and C++ only come with data types with fixed sizes (int, long, double, etc.), which severely limits the size of number which can be kept in memory.

The GMP library allows you to store arbitrary precision numbers (both integers and floats) with ease - indeed, with the C++ extension, GMPXX, allows you to use these data types in pretty much exactly the same way as you use, say long.

What is this guide for?

If you're working on Windows (instead of Ubuntu :)), and using Dev-C++ (a fantastic open source C/C++ compiler available under the GPL, which makes it free), then this guide should be straight forward, and works just great with these software versions:

WindowsDev-C++MinGWGMP
XP 4.9.9.2 3.4.2 (version of GCC & G++) 4.2.1 (GMPXX)

If there are no errors, then this guide should work straightforwardly. If there are errors, ask about them below. Whenever you want, even if this entry is really old. We'll try, but no guarantees.

The Instructions

Starting Point

You should have Dev-C++ installed. No? Then click here. The assumed installation directory is C:\Dev-Cpp\. Be aware of this when adapting the commands below.

The installation of Dev-C++ should have put "C:\Dev-Cpp\bin" in your PATH environment variable. To check this, go to Start->Run, type "cmd", and press return. Now type "gcc --version". You should get a message like this:

gcc (GCC) 3.4.2 (mingw-special)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you get a message like "'gcc' is not recognized as an internal or external command, operable program or batch file.", and you are sure you have installed Dev-C++ on Windows XP: right click on My Computer and select Properties. Click on the Advanced tab, and then click on the Environment Variables button. Look for "Path" in the bottom white box, scrolling down if necessary. Select it, click on "Edit", and go to the end of the box which appears. Add ";C:\Dev-Cpp\bin", including the semi-colon, and adjusting the "C:\Dev-Cpp" bit to whatever directory you installed Dev-C++ into.

The Preparation

  1. Go to the GMP download page. Download the archive of the latest release, a ".tar.bz2" or ".tar.gz" file - which one is irrelevant.
  2. Extract this archive to a folder like "c:\c++\GMP" or something - try to avoid spaces and capital letters. To do this, you need a good archive program - if you haven't got one that can read the file (i.e. you double-click on it and it says "Windows cannot open this file"), download and install 7-Zip (from here).
  3. Check that you have a folder like "C:\c++\GMP\GMP-4.2.1", or equivalent. This folder should contain several source files and folders.
  4. Assuming you have MinGW installed (it comes with Dev-C++), you only now need MSYS to run the "configure" script. To install this
    1. Go to the SourceForge MinGW homepage.
    2. Click on "Download MinGW - Minimalist GNU for Windows" - the big green button!
    3. Look through the "Latest File Releases" section until you see "MSYS Base System". Click on the text saying "MSYS Base System" - not the "Download" link!
    4. Find the first "Current Release" in the list in the big table, ignoring "Technology Previews", by preference. (NB: You can close any "Technology Preview" sections by clicking on the '-' symbol to the left of the heading.)
    5. Click the '+' symbol by the Current Release, which is "Current Release: msys-1.0.10" at the moment.
    6. Click on "MSYS-1.0.10.exe" (or whatever the latest version is - what is important is the ".exe" extension).
  5. Run this file - the default options should be fine.
  6. When it finishes the installation, a black prompt window appears. Confirm that you do want to normalize, and that you have a MinGW installation (type 'y' and press return), and then type in the folder where you have Dev-C++ installed, using forward slashes and lowercase: for me, that is "c:/dev-cpp". Press return.
  7. Go to "C:\Dev-Cpp\bin" (or equivalent) and make a copy of "mingw32-make.exe". Rename this copy "make.exe". This is because the MSYS installation removes "make.exe" without the prefix, causing Dev-C++ to become confused when trying to compile using a makefile.

You are now ready to compile! :D

Compilation & Installation

  1. Open the MSYS prompt (by default, there is a link in the Start Menu - Start->MinGW->MSYS->msys).
  2. Update: "cd" to the directory with your GMP files using a command like "cd /c/c++/GMP/GMP-4.2.1" (yes, of course, without the quotes, as always!) - be sure to adjust "/c/..." to your own directory - this one is equivalent to C:\c++\GMP\GMP-4.2.1. Press return.
  3. Update fix: You must fix an error which currently exists in the Makefiles. You must do one of the following:
    1. Before running ./configure (step 4), go to C:\c++\GMP\GMP-4.2.1\mpn\Makeasm.am and go to the last line of the file. If you find --m4="$(M4)" in the middle of it, change it to --m4=$(M4). That is, remove the double quote marks,
    2. After running ./configure (step 4), go to C:\c++\Includes\GMP\GMP-4.2.1\mpn\Makefile and also C:\c++\Includes\GMP\GMP-4.2.1\tests\Makefile and make the same replacements described just above, although not quite at the last line. Change --m4="$(M4)" to --m4=$(M4).
  4. Type in "./configure --prefix=/c/dev-cpp --enable-cxx" (yes, no quotes, and change the path as in 2. above) - and press return. Let it run - it is analyzing your system, and building the Makefiles necessary.
  5. Providing there are no errors (if there are, ask someone about them, or try to use your common sense to fix them - most errors are misspelt or incorrectly written directory names) type in "make" and press return. Let this run also - it's now compiling and linking all the code, which may take quite a while. The process compiles each source file in each category (integers, floats, etc. - as in the folder structure), producing .o and .lo files, and then links them each folder together into individual .la files.
  6. When this had finished, in my paranoia, I also ran "make check", which compiles various tests and runs them using your new (static) library. They all passed first time :P. It is recommended that you run "make check" though, since, as the GMP developers say, GMP tends to explore interesting corners of compilers, and many have fallen foul of compiler errors.
  7. Update: type "make install" and press return.
  8. (Update: you should check to ensure the ".a" libraries have been installed to your Dev-C++ directory, as in "C:\Dev-Cpp\lib". If they haven't, look for a ".libs" folder in the directory you extracted everything to.)

Now you should be ready to use the static library!

Using the Library

  1. Now, open Dev-C++, and create a new C++ project (a Console Application).
  2. Type in this code into "main.cpp" and save it:
    	#include <iostream>
    #include <gmpxx.h>
    using namespace std;
    int main (void) {
    mpz_class a, b, c;
    a = 1234;
    b = "-5678";
    c = a+b;
    cout << "sum is " << c << "\n";
    cout << "absolute value is " << abs(c) << "\n";
    cin >> a;
    return 0;
    }
  3. Go to Project->Project Options->Parameters->Linker, click "Add Library or Object", and navigate to "C:\Dev-Cpp\lib". Select the "libgmpxx.a" file, and click "Open". A new entry has appeared. Do the same, but selecting "libgmp.a". The order is important!
  4. Click OK, and compile!

A Brief Explanation

MSYS is necessary to run the "configure" shell script, and to provide the ideal environment for building. It is easier to use than Cygwin for this purpose, and quicker to install.

The "--enable-cxx" flag for the "configure" script is to allow the linking of the "libgmpxx" library, and to cause the copying of "gmpxx.h" to the installation directory.

When using GMPXX in C++, the following course of action is required:

  1. #include <gmpxx.h>
  2. libgmpxx.a
  3. libgmp.a

For the C version, it's:

  1. #include <GMP.h>
  2. libgmp.a

The C++ version overloads the operators (+, -, /, *, =, ...) to make using the library as easy as using built in operators, as the above example demonstrates. The data types in the C++ wrapper as as follows:

mpz_class: Integers, or whole numbers

mpf_class: Floats, or decimal numbers

mpq_class: Rational numbers, or fractions

Enjoy!

Useful? Problems?

Please leave a comment (it's really easy) if this was useful, if you had problems, or especially if you have something to add!

Recent Fix No. 1:

If you get an error like

m4: gcc: No such file or directory
../mpn/m4-ccas: -c: command not found
c:\dev-cpp\bin\make.exe[2]: *** [add_n.lo] Error 1
c:\dev-cpp\bin\make.exe[2]: Leaving directory `c:/c++/GMP/GMP-4.2.3/mpn\'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `c:/c++/GMP/GMP-4.2.3\'
c:\dev-cpp\bin\make.exe: *** [all] Error 2

then go to Step 3 under Compilation & Installation above.

(See this forum thread for information.)

Recent Fix No. 2

If you're getting errors like these:

../fib_table.h:4: error: parse error before "data"
../gmp-impl.h:2547:64: operator '&&' has no right operand

Check the definition of things like GMP_LIMB_BITS in gmp.h - if they're blank, give them a nice value, such as 32 (no guarantees.) Also, read the comments below.

Posted by carl at 04:00

Filed under: Computing

Wednesday, 30 May 2007

Hacking APT

Workaround for the Advanced Packaging Tool # Permalink

OK. Here's the solution to a really annoying problem relating to the Debian APT tool - that package that just won't uninstall for love nor money. I eventually solved it with a little bit of thinking... when I was thinking in the right way about it!

The scenario

Firstly, you get a fairly standard error message, e.g. referring to a non-existent file (typically the init.d file). Then, it triggers the subprocess pre-removal script returned error exit status 1 error. Thus, you get the wonderful E: Sub-process /usr/bin/dpkg returned an error code (1) to top it off. My problem, as the example above suggests, was that I accidentally deleted the init.d script.

What is happening is that the Debian package manager (dkpg) is running the "pre-removal script" found in the /var/lib/dkpg/info/ folder. This will be named [package].prerm. Typically, this is a brief script which manages the stopping of processes, chmod instructions, and deletes/renames certain package files. By all means, have a look in the file.

The solution

To resolve this problem (at your own risk), simply edit the /var/lib/dkpg/info/[package].prerm file, removing troublesome lines, or even, if necessary, simply emptying (but not deleting) the whole file. This allows the process to continue, and the files to be removed.

Having allowed the package to be removed, you may have problems with re-installation - so even if you do not plan on doing so, you may be well advised to tidy up the files - this is simply done by renaming (rather than deleting, for safety) the remaining [package]. files in the /var/lib/dkpg/info/ folder, to, for example, [package].postrm.old. The files likely to be left behind are the .postrm (post-removal script) and the .list (file list) files. These can safely be renamed, since any re-installation will simply replace them with fresh files.

A footnote

If you want a motto, try "everything Linux does makes sense". The script files are easily reachable to ensure you can fix any little bugs you find or create.

And something else I learned recently relating to APT - if you want to search repositories from the command-line, try "apt-cache search ...".

Posted by carl at 04:00

Filed under: Computing

Tuesday, 29 May 2007

Traffic

a new design # Permalink C Comment

I've put together a new design, and started adjusting the Increase/Decrease font size options, which currently do not work on the published site.

Just so's you know, the way I've chosen to do this is to adjust the font-size CSS attribute of the body element. So long as all internal font-sizes are then specified as percentages, this single adjustment can alter all the necessary formatting options.

Unfortunately, since I uploaded the site only half-way through the process, several items/modules are somehow broken. My Expression CMS currently generates "/journal/" pages which are not valid, since there's an issue with an anchor, which I wasn't really thinking about when I typed up. My local copy's fixed this and most other issues... I just haven't actually uploaded it yet :/

Ciao!

Posted by carl at 04:00

Filed under: Style

Wednesday, 16 May 2007

Nacho's Online

nacho done got himself a website! # Permalink C Comment

No, it's not an advertisement!

Go see Nacho at rag-n-bone.co.uk now!

We're helping each other out now and then, having recently finished school together; I'm the programmer, he's the design dude. Although his site's entirely his work, and my site's entirely mine, advice is exchanged now and again.

Posted by carl at 04:00

Journal by Carl Turner

All entries by user Carl Turner

Simple diagrams for LaTeX with Inkscape • 1.7.2013 Yesterday I discovered how to make nice, simple, elegant diagrams for fairly painless inclusion… [read more - comment]No Data Connection (Android) • 4.6.2013 Just spent an age dealing with a phone (Samsung Galaxy S2, I9100, on the UK network 3) running a… [read more - comment]Android/BusyBox Segmentation Faults • 30.9.2012 Just had a terrifying moment when, after attempting to install BusyBox on an Android device,… [read more - comment]Temporarily Redefining In-built Mathematica Functions • 16.7.2012 Suppose a package you're using is, say, zealously Simplifying lots of Mathematica expressions… [read more - comment]Nuclear Power • 24.7.2011 I've never known the answers to the big questions about energy. I do know that with … [read more - comment]
top / xhtml / css
© Carl Turner 2008-2017
design & engine by suchideas / hosted by xenSmart