Galib

Hello everybody, thanks in advance. I'm novice with galib (genetic algorithms)
http://lancet.mit.edu/ga/
and I have several problems for example when I try to compile the 16 example
http://lancet.mit.edu/galib-2.4/examples/README.html
I have an erropr message:

ex16.C:12:10: fatal error: iostream.h: No existe el archivo o el directorio
#include <iostream.h>

if I remove the extension .h things dont change to better

ex16.C:13:10: fatal error: fstream.h: No existe el archivo o el directorio
#include <fstream.h>

if I remove egain the extension I get a lot of errors:

ex16.C:34:10: error: ‘ostream’ does not name a type; did you mean ‘strcat’?
friend ostream & operator<<(ostream & os, const Point & p){
^~~~~~~
strcat
ex16.C:53:16: error: variable or field ‘WriteNode’ declared void
void WriteNode(ostream & os, GANode<Point> * n);
^~~~~~~
ex16.C:53:16: error: ‘ostream’ was not declared in this scope

And besides I don't know how I must compile galib, with more options, I'm only writing g++ ex16.C

Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* ----------------------------------------------------------------------------
  ex16.C
  mbwall 5may95
  Copyright (c) 1995-1996  Massachusetts Institute of Technology

 DESCRIPTION:
   Illustration of how to use a non-trivial object in the nodes of a tree
genome.  This example uses points in the nodes.
---------------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <ga/ga.h>

............
Last edited on
What compiler are you using?

Looks like that file was written around 1996. Library headers like <iostream.h> are pre-standard C++ (before 1998). If you're using even a relatively recent compiler, you should use:

1
2
3
4
5
#include <cstdio> // standard header (originally in C as <stdio.h>)
#include <cstdlib> // standard header (originally in C as <stdlib.h>)
#include <iostream> // standard header (new to C++)
#include <fstream> // standard header (new to C++)
#include <ga/ga.h> // custom header, presumably provided by the link you posted 
Last edited on
I have now problems with ostream
the error message is:
ex16.C:34:10: error: ‘ostream’ does not name a type; did you mean ‘strcat’?
friend ostream & operator<<(ostream & os, const Point & p){


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <ga/ga.h>



// This is the object that we're going to put in the nodes.  Each point has 
// three coordinates: x,y,z.
class Point {
public:
  Point(float x, float y, float z) { _x = x; _y = y; _z = z; }
  Point(const Point & p) { _x = p._x; _y = p._y; _z = p._z; }
  Point & operator=(const Point & p) { _x=p._x;_y=p._y;_z=p._z; return *this; }
  ~Point() {}

  float x() const { return _x; }
  float y() const { return _y; }
  float z() const { return _z; }
  float x(float val) { return _x=val; }
  float y(float val) { return _y=val; }
  float z(float val) { return _z=val; }

  friend ostream & operator<<(ostream & os, const Point & p){
    os << "(" << p._x << ", " << p._y << ", " << p._z << ")";
    return os;
  }
You need to add a
using namespace std;
when going from old C++ to modern C++.
And now the last step, I don't know how to compile the galib.h
it throws an error
ex16.C:241:1: error: specializing member ‘GATreeGenome<Point>::write’ requires ‘template<>’ syntax
GATreeGenome<Point>::write(ostream & os) const {

it doesn't work with the option -lga
any sugestion?
Sounds like the code has severe rot from being pre-standard. No one has maintained it for modern use :(
Your current error is a compiler error, not a linker error.

Try changing the write function to this:
1
2
3
4
5
6
template <>
int GATreeGenome<Point>::write(ostream & os) const {
  os << "      node     parent      child       next       prev\n";
  WriteNode(os, (GANode<Point> *)rt);
  return os.fail() ? 1 : 0;
}


Not exactly sure if that will just magically make it worth, though.
Last edited on
Thank you, I found a new release in github
Topic archived. No new replies allowed.