Version 3 (modified by Chuck, 10 years ago)



Here are some problems people run into when getting started with Cobra and their solution.

Errors about "float"

Symptoms include error messages you weren't expecting about method calls and "float" arguments:, 1.0)   # error: Cannot convert...

Cobra supports fractional values with the types:

  • float32
  • float64
  • float (=float64)
  • decimal (the default)

One of these types has to be the default type for values such as "1.0" and "x/y". Cobra uses "decimal" because it is more accurate with respect to the base-10 numbers people normally work with (e.g., 10%, 1.6). However, some libraries--especially for graphics and games--expect binary floating point numbers. If your application is oriented towards such numbers you can change the default number type by placing this in your code:

@number float64

Or passing it at the command line:

cobra -number:float64 ...

You can also choose "float32".

If you only need the occasional float, you can use suffixes like "_f64" and "_f32" (or "_d" for decimal):, 1.0_f32)

64-bit vs. 32-bit Clash

Symptoms include a "BadImageFormatException". You might be running on a 64-bit operating system, but trying to use a DLL/library that is 32-bit native. In other words, you're using a C or C++ library built for 32-bit on a 64-bit system.

The solution is to build against the "x86" platform, instead of "x64" or "Any". Note that "Any" is the default, and will run in whatever is native to the machine such as 32-bit or 64-bit. You can target "x86" at the command line:

cobra -sharp-args:"/platform:x86" ...

or with a directive in a source file:

@args -sharp-args:"/platform:x86"

Also note that you can "cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727" and then enter "ldr64 setwow" to force .NET programs to run as 32-bit. You can enter "ldr64 set64" to switch back.

System.IO.FileNotFoundException: Could not load file or assembly 'Cobra.Lang …

When you run Cobra like so:

\PATH\TO\Cobra-VERSION\Source\Snapshot> cobra "\PATH\TO\my-first-program.cobra"

You get:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Cobra.Lang ...

You haven't installed Cobra. The "Snapshot" directory in only suitable for compiling the compiler and isn't otherwise directly used. Run "install-from-workspace" from the "Source" parent directory. After that, you can be in any directory, and typically will not be in the Cobra directories unless you are hacking on the compiler or in the "HowTo?" or "Samples" (or maybe "Tests").

\PATH\TO\Cobra-VERSION\Source> install-from-workspace