Error need help

Dear all

I am receiving the bellow error. Please help me how to over the error.

couliba@linux:~/bin/Ga> make find_rules
cc find_rules.c -o find_rules
In file included from find_rules.c:19:
util.h:15: error: syntax error before '*' token
util.h:15: error: conflicting types for `strerror'
/usr/include/string.h:256: error: previous declaration of `strerror'
util.h:15: warning: data definition has no type or storage class
find_rules.c: In function `main':
find_rules.c:203: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
find_rules.c:248: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
find_rules.c:315: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
make: *** [find_rules] Error 1
couliba@linux:~/bin/Ga>

post here source of find_rules.c plz.

Dear Hitori

This is the code, please help me to do any correction. I will appreciate

/*----------------------------------------------------------------------------

File: find_rules.c
Date: March 7, 1997

Copyright (c) Risto Karjalainen. All rights reserved.

This program finds technical trading rules for a stock index.

----------------------------------------------------------------------------*/

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <float.h>

#include "util.h"
#include "gp.h"
#include "gp_util.h"
#include "find_util.h"
#include "find_functions.h"
#include "find_template.h"

static pop_t population;
static int date[MAX_DATA];
static float price[MAX_DATA];
static float norm_price[MAX_DATA];
static float compounded[MAX_DATA];
static float riskfree[MAX_DATA];
static trade_t trades[MAX_TRADES];

main (argc, argv)
int argc;
char *argv[];
{
int generations;
stat_t statistics;
char data_file[256];
char log_file[256];
char rule_file[256];
FILE *df = NULL;
FILE *lf = NULL;
FILE *rf = NULL;
float cost;
int last_day[MAX_YEARS];
int delay;
int normalize;
int n_stagnated;
int max_stagnated;
int n_clusters;
cluster_t cluster[MAX_GENOMES];
float fitness;
float selection;
float target;
float max_fitness[MAX_TRIALS];
float max_selection[MAX_TRIALS];
float fitness_level[MAX_GENERATIONS];
float selection_level[MAX_GENERATIONS];
int count;
int size;
int n_collection[MAX_TRIALS];
int g_collection[MAX_TRIALS];
int max_rules_per_trial;
cluster_t collection[MAX_TRIALS][MAX_COLLECTION];
genome_t rule[MAX_TRIALS][MAX_COLLECTION];
int order[MAX_GENOMES];
int offspring;
float annual_return;
float cumul_return;
float raw;
float excess;
float range[2];
float best;
float breakpoint;
int n_trades;
int i,j,k;
int first_year;
int n_years;
int trial;
int max_trials;
int verbose;
int t1,t2;
int s1,s2;
int failed;
int dt;
int t;
int g;
long e;
int n;

max_trials = MAX_TRIALS;
max_rules_per_trial = 1;
target = 0.0;
breakpoint = FLT_MAX;
generations = MAX_GENERATIONS/2;
e = seed();
normalize = TRUE;
cost = 0.003;
delay = 0;
verbose = FALSE;
t1 = t2 = s1 = s2 = 0;

strcpy(data_file, "");
strcpy(log_file, "");
strcpy(rule_file, "");

population.size = MAX_GENOMES/4;
population.max_nodes = MAX_NODES;
population.max_depth = MAX_DEPTH;
population.min_depth = MIN_DEPTH;
population.pressure = PRESSURE;
population.prob_mutations = PROB_MUTATIONS;
population.type = Boolean;
population.env = range;

range[0] = 0.0;
range[1] = 2.0;

/----------------------------------------------------------------------------
Parse the command line and check that the parameters are valid.
----------------------------------------------------------------------------
/
if (argc == 1)
{
print_help_message(stderr, argv[0]);
exit(1);
}

if (read_cline(argc, argv, &max_trials, &max_rules_per_trial, &target, &breakpoint,
&generations, &e, data_file, log_file, rule_file, &normalize,
&t1, &t2, &s1, &s2, &cost, &delay, &(population.type), &(population.size),
&(population.max_nodes), &(population.min_depth),
&(population.max_depth), range, &verbose))
{
if (failed = !(1 <= max_trials) && (max_trials <= MAX_TRIALS))
fprintf(stderr, "(%s) Invalid value for the number of trials (%d) -- expected an integer between %d and %d.\n",
argv[0], max_trials, 1, MAX_TRIALS);
else if (failed = !(1 <= max_rules_per_trial) &&
(max_rules_per_trial <= MAX_COLLECTION))
fprintf(stderr, "(%s) Invalid value for the number of rules per trial (%d) -- expected an integer between %d and %d.\n",
argv[0], max_rules_per_trial, 1, MAX_COLLECTION);
else if (failed = !(breakpoint > target))
fprintf(stderr, "(%s) Invalid value for the breakpoint (%f) -- expected a real number greater than %f.\n",
argv[0], breakpoint, target);
else if (failed = !(1 <= generations) && (generations <= MAX_GENERATIONS))
fprintf(stderr, "(%s) Invalid value for the number of generations (%d) -- expected an integer between %d and %d.\n",
argv[0], generations, 1, MAX_GENERATIONS);
else if (failed = !strcmp(data_file, ""))
fprintf(stderr, "(%s) No data file specified.\n", argv[0]);
else if (failed = !(cost >= 0.0))
fprintf(stderr, "(%s) Invalid value for the transaction cost (%f) -- expected a positive real number.\n",
argv[0], cost);
else if (failed = (delay < 0))
fprintf(stderr, "(%s) Invalid value for execution delay (%d) -- expected a positive number.\n",
argv[0], delay);
else if (failed =!(10 <= population.size) &&
(population.size <= MAX_GENOMES))
fprintf(stderr, "(%s) Invalid value for population size (%d) -- expected an integer between %d and %d.\n",
argv[0], population.size, 10, MAX_GENOMES);
else if (failed =!(1 <= population.max_nodes) &&
(population.max_nodes <= MAX_GENOMES))
fprintf(stderr, "(%s) Invalid value for node limit (%d) -- expected an integer between %d and %d.\n",
argv[0], population.max_nodes, 1, MAX_NODES);
else if (failed =!(1 <= population.max_depth) &&
(population.max_depth <= MAX_DEPTH))
fprintf(stderr, "(%s) Invalid value for max tree depth (%d) -- expected an integer between %d and %d.\n",
argv[0], population.max_depth, 1, MAX_DEPTH);
else if (failed =!(1 <= population.min_depth) &&
(population.min_depth <= population.max_depth))
fprintf(stderr, "(%s) Invalid value for min tree depth (%d) -- expected an integer between %d and %d.\n",
argv[0], population.max_depth, 1, population.min_depth);

if \(failed\)
  exit\(1\);

}
else
{
printf("(%s) Parsing command line failed.\n", argv[0]);
exit(1);
}

max_stagnated = (generations+1)/2;

/----------------------------------------------------------------------------
Define the function templates which determine the type of nodes that
can be part of the trees created during the evolution.
----------------------------------------------------------------------------
/
define_type(Boolean, type_label[Boolean]);
define_type(Real, type_label[Real]);
define_type(Variable, type_label[Variable]);

for (i = 0; i < sizeof(template)/sizeof(template_t); i++)
define_function(template[i]);

define_tree(population.max_nodes, sizeof(data_t));

/----------------------------------------------------------------------------
Read in the data.
----------------------------------------------------------------------------
/
if (!(df = fopen(data_file, "r")))
{
fprintf(stderr, "(%s) Cannot open %s: %s\n", argv[0], data_file, strerror(errno));
exit(1);
}

if (!init_data(df, &first_year, &n_years))
exit(1);

printf("Data in file '%s' spans years %d-%d.\n\n", data_file, first_year, first_year+n_years-1);

if (n_years < 2)
{
fprintf(stderr, "(%s) Not enough data: At least %d years needed.\n", argv[0], 2);
exit(1);
}

read_data(df, first_year, n_years, date, price, compounded, riskfree, last_day);

normalize_price(price, norm_price, NORMALIZED, TRADING_YEAR, last_day[n_years-1]+1);

fclose(df);

/----------------------------------------------------------------------------
Check that the training and selection periods are valid.
----------------------------------------------------------------------------
/
if (failed = !((first_year+1 <= t1) && (t1 <= first_year+n_years-1) &&
(t1 <= t2) && (t2 <= first_year+n_years-1)))
fprintf(stderr, "(%s) Invalid training period (%d-%d) -- a range within %d-%d expected.\n", argv[0], t1, t2, first_year+1, first_year+n_years-1);
else if (failed = !((first_year+1 <= s1) && (s1 <= first_year+n_years-1) &&
(s1 <= s2) && (s2 <= first_year+n_years-1)))
fprintf(stderr, "(%s) Invalid selection period (%d-%d) -- a range within %d-%d expected.\n", argv[0], s1, s2, first_year+1, first_year+n_years-1);

if (failed)
exit(1);

t1 -= first_year;
t2 -= first_year;
s1 -= first_year;
s2 -= first_year;

/----------------------------------------------------------------------------
Open a log file and print out the parameters.
----------------------------------------------------------------------------
/
if (!strcmp(log_file, ""))
lf = NULL;
else if (!(lf = fopen(log_file, "w")))
fprintf(stderr, "(%s) Cannot open %s: %s\n", argv[0], log_file, strerror(errno));
else
{
fprintf(lf, "\nProgram: %s (%s)\n\n", __FILE__, __DATE__);
fprintf(lf, "Number of trials = %d\n", max_trials);
fprintf(lf, "Number of rules/trial = %d\n", max_rules_per_trial);
fprintf(lf, "Target fitness = %.4f\n", target);
fprintf(lf, "Breakpoint fitness = %.4f\n", breakpoint);
fprintf(lf, "Maximum number of generations/trial = %d\n", generations);
fprintf(lf, "Population size = %d\n", population.size);
fprintf(lf, "Max number of nodes = %d\n", population.max_nodes);
fprintf(lf, "Max tree depth = %d\n", population.max_depth);
fprintf(lf, "Min tree depth = %d\n", population.min_depth);
fprintf(lf, "Selection pressure = %.2f\n", population.pressure);
fprintf(lf, "Mutation probability = %.3f\n", population.prob_mutations);
fprintf(lf, "Population type: %s\n", type_label[population.type]);
fprintf(lf, "Seed for random number generator = %d\n", e);
fprintf(lf, "Data file = '%s'\n", data_file);
fprintf(lf, "Log file = '%s'\n", log_file);
fprintf(lf, "Rule file = '%s'\n", rule_file);
fprintf(lf, "Data are %s normalized.\n", normalize ? "" : "not ");
fprintf(lf, "One-way transaction cost = %.3f\n", cost);
fprintf(lf, "Range for random numbers = (%.3f,%.3f)\n", range[0], range[1]);
fprintf(lf, "First training year = %d\n", first_year+t1);
fprintf(lf, "Last training year = %d\n", first_year+t2);
fprintf(lf, "First selection year = %d\n", first_year+s1);
fprintf(lf, "Last selection year = %d\n", first_year+s2);
fprintf(lf, "Execution delay = %d\n", delay);
fprintf(lf, "\n");
fflush(lf);
}

/----------------------------------------------------------------------------
Print the compounded returns for holding the index.
----------------------------------------------------------------------------
/
printf("Annual and cumulative compounded returns:\n");

for (t = t1-1; t < t2; t++)
{
annual_return = compounded_return(compounded, t+1, t+1, last_day, cost);
cumul_return = compounded_return(compounded, t1, t+1, last_day, cost);

 printf\(" Year %d:\\t%\+.4f\\t\\t%\+.4f\\n", first_year\+t\+1, annual_return, cumul_return\);
\}

printf("\n");

/----------------------------------------------------------------------------
Allocate memory for the trading rules.
----------------------------------------------------------------------------
/
for (i = 0; i < max_trials; i++)
for (j = 0; j < max_rules_per_trial; j++)
{
rule[i][j].chromosome = new_tree(sizeof(data_t));
collection[i][j].genome = &(rule[i][j]);
}

/----------------------------------------------------------------------------
Open a text file to hold the saved rules. If none specified, use stdout.
----------------------------------------------------------------------------
/
if (!strcmp(rule_file, ""))
{
rf = stdout;
fprintf(stderr, "(%s) Rules will be printed on stdout (use option -r to specify a rule file).\n", argv[0]);
}
else if (!(rf = fopen(rule_file, "w")))
{
fprintf(stderr, "(%s) Cannot open %s: %s\n", argv[0], rule_file, strerror(errno));
exit(1);
}

/----------------------------------------------------------------------------
Loop over the trials.
----------------------------------------------------------------------------
/
for (trial = 0; trial < max_trials; trial++)
{
printf("Trial %d starts...\n\n", trial+1);
if (lf) fprintf(lf, "Trial %d starts...\n\n", trial+1);

 max_fitness[trial] = max_selection[trial] = -FLT_MAX;

 n_collection[trial] = 0;
 n_stagnated = 0;

/----------------------------------------------------------------------------
Create the initial population.
----------------------------------------------------------------------------
/
create_population(&population, statistics);

/----------------------------------------------------------------------------
Evolve new generations. At each generation, evaluate each new trading
rule, with the fitness equal to the average annualized excess return.
----------------------------------------------------------------------------
/
for (g = 0; g < generations; g++)
{
for (i = 0; i < population.size; i++)
{
offspring = (g == 0) ? i : create_offspring(&population, statistics);

         eval_genome\(normalize ? norm_price : price, compounded, t1, t2,
		 last_day, delay, &\(population.genome[offspring]\),
		 &n_trades, trades\);

         raw = compute_return\(compounded, riskfree, t1, t2, last_day,
			  n_trades, trades, cost\);

         excess = raw - compounded_return\(compounded, t1, t2, last_day, cost\);

         population.genome[offspring].fitness = excess/\(t2-t1\+1\);
        \}

/----------------------------------------------------------------------------
Compute statistics about the evolution.
----------------------------------------------------------------------------
/
compute_statistics(&population, statistics);

/----------------------------------------------------------------------------
Cluster the population, grouping together rules with identical fitness.
----------------------------------------------------------------------------
/
n_clusters = cluster_population(&population, cluster);

     printf\("Generation %d \(%d clusters, average fitness = %.4f\)\\n\\n",
            g, n_clusters, statistics[g].avg_fitness\);
     if \(lf\) fprintf\(lf, "Generation %d \(%d clusters, average fitness = %.4f\)\\n\\n",
		 g, n_clusters, statistics[g].avg_fitness\);

     n_stagnated\+\+;

/----------------------------------------------------------------------------
Break if fitness in the training period is too high.
----------------------------------------------------------------------------
/
if (statistics[g].avg_fitness > breakpoint)
{
printf("Population fitness exceeded the breakpoint (%.4f)\n\n", breakpoint);
if (lf) fprintf(lf, "Population fitness exceeded the breakpoint (%.4f)\n\n", breakpoint);

         break;
        \}
     else if \(statistics[g].avg_fitness &gt; target\)
        \{
         count = 0;
         fitness_level[g] = selection_level[g] = 0.0;

/----------------------------------------------------------------------------
Evaluate the rules in the selection period.
----------------------------------------------------------------------------
/
for (i = 0; i < n_clusters; i++)
{
if (cluster[i].genome->fitness < target)
continue;

             eval_genome\(normalize ? norm_price : price, compounded,
		     s1, s2, last_day, delay, cluster[i].genome,
		     &n_trades, trades\);

             raw = compute_return\(compounded, riskfree, s1, s2,
			      last_day, n_trades, trades, cost\);

             excess = raw - compounded_return\(compounded, s1, s2, last_day, cost\);

             selection = excess/\(s2-s1\+1\);

             if \(verbose\)
                \{
                 printf\("\\tCluster %d \(%d rules\): fitness = %.4f, selection = %.4f \(%d trades\)\\n",
		    i\+1, cluster[i].size, cluster[i].genome-&gt;fitness,
		    selection, n_trades/\(s2-s1\+1\)\);
                 if \(lf\) fprintf\(lf, "\\tCluster %d \(%d rules\): fitness = %.4f, selection = %.4f \(%d trades\)\\n",
			     i\+1, cluster[i].size, cluster[i].genome-&gt;fitness,
			     selection, n_trades/\(s2-s1\+1\)\);
                \}

/----------------------------------------------------------------------------
Save a rule if it improves the excess returns in the selection period.
----------------------------------------------------------------------------
/
if ((count < max_rules_per_trial) && (selection > max_selection[trial]))
{
max_fitness[trial] = cluster[i].genome->fitness;
max_selection[trial] = selection;

                 fitness_level[g] \+= cluster[i].genome-&gt;fitness;
                 selection_level[g] \+= selection;

                 if \(n_stagnated &gt; 0\)
                    \{
                     n_stagnated = 0;

                     g_collection[trial] = g;
                     n_collection[trial] = 0;
                    \}

                 collection[trial][n_collection[trial]].size = cluster[i].size;
                 copy_genome\(*\(cluster[i].genome\), collection[trial][n_collection[trial]].genome\);

                 n_collection[trial]\+\+;
                \}

             count\+\+;
            \}

         if \(n_collection[trial] &gt; 0\)
            \{
             fitness_level[g] /= n_collection[trial];
             selection_level[g] /= n_collection[trial];
            \}

         if \(verbose\)
            \{
             printf\("\\n"\);
             if \(lf\) fprintf\(lf, "\\n"\);
            \}
        \}

/----------------------------------------------------------------------------
Break if the population remains stagnated for too long.
----------------------------------------------------------------------------
/
if (n_stagnated == 0)
{
printf("\tSaved %d rules: average fitness = %.4f, selection = %.4f\n\n",
n_collection[trial], fitness_level[g], selection_level[g]);
if (lf) fprintf(lf, "\tSaved %d rules: average fitness = %.4f, selection = %.4f\n\n",
n_collection[trial], fitness_level[g], selection_level[g]);
}
else if (n_stagnated == max_stagnated)
{
printf("Population stagnated at generation %d.\n\n", g);
if (lf) fprintf(lf, "Population stagnated at generation %d.\n\n", g);

         break;
        \}
    \}

 if \(max_fitness[trial] &gt; -FLT_MAX\)
    \{
     printf\("Trial %d \(%d rules\): fitness = %.4f, selection = %.4f\\n\\n", trial\+1,
             n_collection[trial], max_fitness[trial], max_selection[trial]\);
     if \(lf\) fprintf\(lf, "Trial %d \(%d rules\): fitness = %.4f, selection = %.4f\\n\\n", trial\+1,
             n_collection[trial], max_fitness[trial], max_selection[trial]\);
    \}
 else
    \{
     printf\("Trial %d \(%d rules\): fitness = -Infinity\\n\\n", trial\+1, n_collection[trial]\);
     if \(lf\) fprintf\(lf, "Trial %d \(%d rules\): fitness = -Infinity\\n\\n", trial\+1, n_collection[trial]\);
    \}

/----------------------------------------------------------------------------
Save the rules in a file and test them after the selection period.
----------------------------------------------------------------------------
/
for (j = 0; j < n_collection[trial]; j++)
{
fprintf(lf ? lf :stdout, "Cluster %d (%d rules):\n", j+1, collection[trial][j].size);

     if \(rf\)
        \{
         save_genome\(rf, collection[trial][j].genome\);
         fprintf\(rf, "\\n"\);
         fflush\(rf\);
        \}

     eval_genome\(normalize ? norm_price : price, compounded, s2\+1, n_years-1,
	     last_day, delay, collection[trial][j].genome, &n_trades, trades\);

     raw = compute_return\(compounded, riskfree, s2\+1, n_years-1, last_day,
		      n_trades, trades, cost\);

     excess = raw - compounded_return\(compounded, s2\+1, n_years-1, last_day, cost\);

     printf\("\\tTest \(cluster %d\) = %.4f \(%d trades/year\)\\n\\n", i\+1, excess/\(n_years-s2-1\), n\_trades/\(n_years-s2-1\)\);
     if \(lf\) fprintf\(lf, "\\tTest \(cluster %d\) = %.4f \(%d trades/year\)\\n\\n", i\+1, excess/\(n_years-s2-1\), n\_trades/\(n_years-s2-1\)\);
    \}

 if \(lf\) fflush\(lf\);

 dispose_population\(&population\);
\}

/----------------------------------------------------------------------------
Report the ranking of trials according to the selection period.
----------------------------------------------------------------------------
/
printf("Trials ranked according to the selection period:\n\n");
if (lf) fprintf(lf, "Trials ranked according to the selection period:\n\n");

order_by_key(order, max_trials, max_selection, descending_order);

for (i = 0; i < max_trials; i++)
{
if (n_collection[order[i]] == 0) break;

 printf\("Trial %d \(%d rules\): fitness = %.4f, selection = %.4f\\n\\n", order[i]\+1,
         n_collection[order[i]], max_fitness[order[i]], max_selection[order[i]]\);
 if \(lf\) fprintf\(lf, "Trial %d \(%d rules\): fitness = %.4f, selection = %.4f\\n\\n", order[i]\+1,
         n_collection[order[i]], max_fitness[order[i]], max_selection[order[i]]\);
\}

if (lf) fclose(lf);
}

It seems that source of the problem is

util.h:15: error: syntax error before '*' token
util.h:15: error: conflicting types for `strerror'

It is possible that due to some mistyping you declare strerror() in util.h

Try to resolve this error first (in util.h:15) then other must (may) disappear
I'll look closer in a day

Dear Hitori

For the (util.h:15: error: syntax error before '*' token) was mispelling and have correct that one and disapeared

for the (util.h:15: error: conflicting types for `strerror') did not disapeared, I am still receiving the error.

Any advice, please

Thank you

post util.h, let's see

Dear Hitori

Here is the util.h as well. Thank you very much

/*------------------------------------------------------------------------------

File: util.h
Date: January 26, 1992

Copyright (c) Risto Karjalainen. All rights reserved.

Utility functions of general use.

------------------------------------------------------------------------------*/

#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))

extern char *strerror(int errno);

/*------------------------------------------------------------------------------
'get_boolean' prints 'prompt' and reads a character from stdin. 'answers'
contains the valid character set. If the entered character equals 'affirm',
'def' is returned.
------------------------------------------------------------------------------
/

extern int get_boolean(char *prompt, char *answers, int def, char affirm);

/*------------------------------------------------------------------------------
'get_int' prints 'prompt' and reads an integer from stdin. The entered
integer must be in the range 'min' .. 'max'. If none is entered, 'def'
is returned, instead.
------------------------------------------------------------------------------
/

extern int get_int(char *prompt, int imin, int imax, int def);

/*------------------------------------------------------------------------------
'get_float' prints 'prompt' and reads a floating point number from stdin.
The entered number must be in the range 'min' .. 'max'. If none is entered,
'def' is returned, instead.
------------------------------------------------------------------------------
/

extern float get_float(char *prompt, float fmin, float fmax, float def);

/*------------------------------------------------------------------------------
'get_string' prints 'prompt' and reads a character string from stdin,
stored in 'string'. If a string is entered, TRUE is returned. If not, but
the default string ('def') is non-NULL, the default string is copied to
'string' and TRUE is returned. If no string is entered and 'def' equals
NULL, FALSE is returned.
------------------------------------------------------------------------------
/

extern int get_string(char *prompt, char *def, char *string);

/------------------------------------------------------------------------------
'seed' initializes the random number generator. This should be called once
in the beginning of the application program. The initial seed is returned.
------------------------------------------------------------------------------
/

extern long seed(void);

/------------------------------------------------------------------------------
'irandom' returns an integer random number, uniformly distributed in the
given range (including the endpoints). Order of arguments is irrelevant.
------------------------------------------------------------------------------
/

extern int irandom(int a, int b);

/------------------------------------------------------------------------------
'frandom' returns a floating point random number, uniformly distributed in
the given range (including the endpoints). Order of arguments is irrelevant.
------------------------------------------------------------------------------
/

extern float frandom(float a, float b);

/------------------------------------------------------------------------------
'flip' returns either 0 or 1, each with probability 1/2.
------------------------------------------------------------------------------
/

extern int flip(void);

/*------------------------------------------------------------------------------
'parse_arg' searches the command line for a given argument. If found,
TRUE is returned, 'value' is set to point to the next argument, and
'argc' is decremented by one.
------------------------------------------------------------------------------
/

extern int parse_args(int *argc, char *argv[], char *name, char **value);

Comment out this line:

extern char *strerror(int errno);

strerror is defined in string.h so your declaration is redundant. I'm guessing it must have been needed on some other system that didn't declare it in string.h, so if you want to be really thorough, you could do something like:

// Near top util.h
#include <string.h>

// Lower down
#ifndef strerror
extern char *strerror(int errno);
#endif/*strerror*/

Including string.h more than once shouldn't hurt because it has start and end code like this:

// Start of file
#ifndef __STRING_H__
#define __STRING_H__

// file contents
...

#endif/*__STRING_H__*/

I add these to all my .h files just to be safe.

strerror() is declared in string.h according to ISO
It's strange that this code worked earlier

Dear Corona

If I comment out this what I will get in error

couliba@linux:~/bin/GaSource> make find_rules
cc find_rules.c -o find_rules
/tmp/ccsfOXjS.o(.text+0x72): In function `main':
find_rules.c: undefined reference to `seed'
/tmp/ccsfOXjS.o(.text+0x18e):find_rules.c: undefined reference to `print_help_message'
/tmp/ccsfOXjS.o(.text+0x23d):find_rules.c: undefined reference to `read_cline'
/tmp/ccsfOXjS.o(.text+0x679):find_rules.c: undefined reference to `define_type'
/tmp/ccsfOXjS.o(.text+0x68c):find_rules.c: undefined reference to `define_type'
/tmp/ccsfOXjS.o(.text+0x69f):find_rules.c: undefined reference to `define_type'
/tmp/ccsfOXjS.o(.text+0x6e5):find_rules.c: undefined reference to `define_function'
/tmp/ccsfOXjS.o(.text+0x702):find_rules.c: undefined reference to `define_tree'
/tmp/ccsfOXjS.o(.text+0x789):find_rules.c: undefined reference to `init_data'
/tmp/ccsfOXjS.o(.text+0x821):find_rules.c: undefined reference to `read_data'
/tmp/ccsfOXjS.o(.text+0x850):find_rules.c: undefined reference to `normalize_price'
/tmp/ccsfOXjS.o(.text+0xe30):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0xe61):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0xf30):find_rules.c: undefined reference to `new_tree'
/tmp/ccsfOXjS.o(.text+0x10fa):find_rules.c: undefined reference to `create_population'
/tmp/ccsfOXjS.o(.text+0x1151):find_rules.c: undefined reference to `create_offspring'
/tmp/ccsfOXjS.o(.text+0x11da):find_rules.c: undefined reference to `eval_genome'
/tmp/ccsfOXjS.o(.text+0x1210):find_rules.c: undefined reference to `compute_return'
/tmp/ccsfOXjS.o(.text+0x123f):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0x12a1):find_rules.c: undefined reference to `compute_statistics'
/tmp/ccsfOXjS.o(.text+0x12b8):find_rules.c: undefined reference to `cluster_population'
/tmp/ccsfOXjS.o(.text+0x14cf):find_rules.c: undefined reference to `eval_genome'
/tmp/ccsfOXjS.o(.text+0x1505):find_rules.c: undefined reference to `compute_return'
/tmp/ccsfOXjS.o(.text+0x1534):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0x17ce):find_rules.c: undefined reference to `copy_genome'
/tmp/ccsfOXjS.o(.text+0x1b79):find_rules.c: undefined reference to `save_genome'
/tmp/ccsfOXjS.o(.text+0x1c24):find_rules.c: undefined reference to `eval_genome'
/tmp/ccsfOXjS.o(.text+0x1c5e):find_rules.c: undefined reference to `compute_return'
/tmp/ccsfOXjS.o(.text+0x1c91):find_rules.c: undefined reference to `compounded_return'
/tmp/ccsfOXjS.o(.text+0x1d9f):find_rules.c: undefined reference to `dispose_population'
/tmp/ccsfOXjS.o(.text+0x1de3):find_rules.c: undefined reference to `descending_order'
/tmp/ccsfOXjS.o(.text+0x1dfc):find_rules.c: undefined reference to `order_by_key'
/tmp/ccsfOXjS.o(.data+0x50): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x54): undefined reference to `eval_if_then'
/tmp/ccsfOXjS.o(.data+0xa0): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0xa4): undefined reference to `eval_if_then_else'
/tmp/ccsfOXjS.o(.data+0xf0): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0xf4): undefined reference to `eval_and'
/tmp/ccsfOXjS.o(.data+0x140): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x144): undefined reference to `eval_or'
/tmp/ccsfOXjS.o(.data+0x190): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x194): undefined reference to `eval_not'
/tmp/ccsfOXjS.o(.data+0x1e0): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x1e4): undefined reference to `eval_greater'
/tmp/ccsfOXjS.o(.data+0x230): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x234): undefined reference to `eval_less'
/tmp/ccsfOXjS.o(.data+0x278): undefined reference to `init_boolean'
/tmp/ccsfOXjS.o(.data+0x27c): undefined reference to `read_boolean'
/tmp/ccsfOXjS.o(.data+0x280): undefined reference to `print_boolean'
/tmp/ccsfOXjS.o(.data+0x2d4): undefined reference to `eval_flip'
/tmp/ccsfOXjS.o(.data+0x320): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x324): undefined reference to `eval_plus'
/tmp/ccsfOXjS.o(.data+0x370): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x374): undefined reference to `eval_minus'
/tmp/ccsfOXjS.o(.data+0x3c0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x3c4): undefined reference to `eval_multiply'
/tmp/ccsfOXjS.o(.data+0x410): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x414): undefined reference to `eval_divide'
/tmp/ccsfOXjS.o(.data+0x460): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x464): undefined reference to `eval_negation'
/tmp/ccsfOXjS.o(.data+0x4b0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x4b4): undefined reference to `eval_norm'
/tmp/ccsfOXjS.o(.data+0x500): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x504): undefined reference to `eval_average'
/tmp/ccsfOXjS.o(.data+0x550): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x554): undefined reference to `eval_maximum'
/tmp/ccsfOXjS.o(.data+0x5a0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x5a4): undefined reference to `eval_minimum'
/tmp/ccsfOXjS.o(.data+0x5f0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x5f4): undefined reference to `eval_slope'
/tmp/ccsfOXjS.o(.data+0x640): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x644): undefined reference to `eval_volatility'
/tmp/ccsfOXjS.o(.data+0x690): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x694): undefined reference to `eval_lag'
/tmp/ccsfOXjS.o(.data+0x6e0): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x6e4): undefined reference to `eval_data'
/tmp/ccsfOXjS.o(.data+0x728): undefined reference to `init_real'
/tmp/ccsfOXjS.o(.data+0x72c): undefined reference to `read_real'
/tmp/ccsfOXjS.o(.data+0x730): undefined reference to `print_real'
/tmp/ccsfOXjS.o(.data+0x784): undefined reference to `eval_price'
/tmp/ccsfOXjS.o(.data+0x7d4): undefined reference to `eval_compounded'
collect2: ld returned 1 exit status
make: *** [find_rules] Error 1

and If add the code as the below

/*------------------------------------------------------------------------------

File: util.h
Date: January 26, 1992

Copyright (c) Risto Karjalainen. All rights reserved.

Utility functions of general use.

------------------------------------------------------------------------------*/
#inlcude <string.h>

#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#ifndef strerror
extern char *strerror(int errno);
#endif

/*------------------------------------------------------------------------------
'get_boolean' prints 'prompt' and reads a character from stdin. 'answers'
contains the valid character set. If the entered character equals 'affirm',
'def' is returned.
------------------------------------------------------------------------------
/

extern int get_boolean(char *prompt, char *answers, int def, char affirm);

/*------------------------------------------------------------------------------
'get_int' prints '*prompt' and reads an integer from stdin. The entered
integer must be in the range 'min' .. 'max'. If none is entered, 'def'
is returned, instead.
*/

I will receive this error

ouliba@linux:~/bin/GaSource> make find_rules
cc find_rules.c -o find_rules
In file included from find_rules.c:19:
util.h:17: error: conflicting types for `strerror'
/usr/include/string.h:256: error: previous declaration of `strerror'
find_rules.c: In function `main':
find_rules.c:203: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
find_rules.c:248: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
find_rules.c:315: warning: passing arg 1 of `strerror' makes pointer from integer without a cast
make: *** [find_rules] Error 1
couliba@linux:~/bin/GaSource>

Any more advise, I appreciate so much

That error is what Corona is trying to help you with - you have strerror declared in util.h. Put the #ifndef and #define statement he gave you around the place where you encounter the error in util.h.

To find where strerror is doubly defined try this:

gcc -E find_rules.c | grep 'strerror'

You will see something like "extern char *strerror" appearing twice. It should show up only once.

Those errors are exactly what it says they are. It cannot find those functions. You probably need to compile another file to get them. Not all C files are standalone. The general sequence is:

cc -c file1.c -o file1.o
cc -c file2.c -o file2.o
...
cc -c file5.c -o file5.o
cc file1.o file2.o file3.o file4.o file5.o -o program

In a makefile you might have something like:

OBJS=file1.o file2.o file3.o file4.o file5.o

program:$(OBJS)
        $(CC) $(OBJS) $(LDFLAGS) -o $@

It should already understand how to convert .c to .o, so you just tell it how to convert those .o's to one executable. LDFLAGS is an optional variable that might comtain library flags.

And please, for the love of yog, put your code in code-tags!!

Your advice may be a solution to my problem, but I am not sure if I understand what you want me to do. Can you please put in away I can understand.

As you said. it can not find those function. that is right but how do I make it to find those function.

Thank you very much

This might best be shown by example.

In a directory by itself, create this file:

// main.c
#include <stdio.h>

int main(int argc, char *argv[])
{
  int n;
  fprintf(stderr,"main(%d,[",argc);
  for(n=0; n<argc; n++)
    fprintf(stderr," '%s'",argv[n]);
  fprintf(stderr," ]);\n");
  return(0);
}

Then compile and run it like this:

# gcc main.c -o main
# ./main
main(1,[ './main' ]);
#

That works, but what you might not realize is that gcc is actually doing two steps, not one -- compilation, then linking. The compilation stage converts C code into assembly language, the linking stage ties everything together into an executable. Let's break it into two steps:

# gcc -c main.c -o main.o
# gcc main.o -o main
# ./main
main(1,[ './main' ]);
#

That's what gcc is ACTUALLY doing... converts the C file into an object file(.o), then links the object file into an executable.

Now let's try and use a function from another .c file. First, create this file:

// library.c
#include <stdio.h>

int library_function(int c)
{
  fprintf(stderr,"library_function(%d)\n",c);
  return(c-3);
}

Then, modify main.c to use it like this:

#include <stdio.h>

extern int library_function(int c);

int main(int argc, char *argv[])
{
  int n;
  fprintf(stderr,"main(%d,[",argc);
  for(n=0; n<argc; n++)
    fprintf(stderr," '%s'",argv[n]);
  fprintf(stderr," ]);\n");

  printf("library_function(%d) returns %d\n",32,library_function(32));

  return(0);
}

Finally, let's see what happens when we try and compile it, then link it:

# gcc -c main.c -o main.o
# gcc main.o -o main
main.o: In function `main':
main.c:(.text+0x86): undefined reference to `library_function'
collect2: ld returned 1 exit status
#

It doesn't work. It compiles it fine since there's no syntax errors in the program, but the function it wants is not in main.o! To get that function, we'll need to give it library.o too.

# gcc -c main.c -o main.o
# gcc -c library.c -o library.o
# gcc main.o library.o -o main
# ./main
main(1,[ './main' ]);
library_function(32)
library_function(32) returns 29
#

It works!

Now, if you want your makefile to do that, you need to tell it that the output file needs main.o and library.o. Here's a simple makefile:

main:main.o library.o
        $(CC) main.o library.o $(LDFLAGS) -o $@
clean:
        rm -f main main.o library.o

With that makefile in the main directory, let's try it:

# make clean
rm -f main main.o library.o
# make main
cc    -c -o main.o main.c
cc    -c -o library.o library.c
cc main.o library.o  -o main
# ./main
main(1,[ './main' ]);
library_function(32)
library_function(32) returns 29
#

It works!

So there you go. You'll need to find the .c file that these missing functions reside in, convert it to an object, then link it into your executable.

Dear Corona

I have to call you my coach. Thank you very much for taking your time to put all this line and explain for me. I learn a lot from explaination.

Here is what I found by following your instruction,

I ran the first program using gcc and it work, and second program with function and using gcc and it work.

Then when it came to makefile one. I have receive the below error

couliba@linux:~/main> make clean
rm -f main main.o library_function.o
couliba@linux:~/main> make main
cc -c -o main.o main.c
make: *** No rule to make target `library_function.o', needed by `main'. Stop.
couliba@linux:~/main>

Do not u think, the problem is my lunix installation. Because this is my notebook I just recently install lunix.

Any help is appreciated

Simply the wrong filename. It goes by file extension, it does not know how to make a library_function.o when there's no library_function.c . Change library_function.c and library_function.o to library.c and library.o respectively and it should work.

Come to think of it, that was a mistake in my example wasn't it? Oops. Fixed.

Dear Corona

Thank you very, I did the changes and it work for the simple.

but

I applied to my code and I still receive the smilar erorr but not as much as earlier. I have created object files for all my C files. You may need view the below tag.

Any help is very much appreciated.

Thank you dear

Don't call people 'dear' unless you're married to them. :stuck_out_tongue:

Your makefile is wrong. It's compiling all the C files together instead of all the objects. Which, while it will work, is awkward and hard to debug, avoids all the advantages of using a makefile in the first place, and does all the work twice.

Instead of

cc file.c file2.c file3.c ... -o exec

it should do

cc file.o file2.o file3.o ... -o exec

Some of those missing functions are functions you still haven't compiled, but a few are from the C math library. At the top of your makefile, add the line:

LDFLAGS=-lm

That will tell it to link in the math library.

If you're still missing functions, you're missing a file. Maybye whoever gave you the code didn't give you all of it.

:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:
Coach
Thank you very much the code is working very well now. You make it successful. I appreciate so much all your efort and sharing of knowledge.

Acctually all files are completed. I have test the codes in my friend's notebook last three month ago before I bought my notebook and it work without any problem. However, when I bought my own notebook and install linux then all this problem start to come out. By the way my friend is using suse 10 and I am using suse 9.3. I am not sure if that can make any different.

I have one concern to ask you. After add -lm to the makefile, there was only one warning appeared saying this:

/tmp/ccYaBtHR.o (.text+0X33): In function 'get_boolean':
util.c:warning: the 'gets' function is dangerouns and should not be used.
To avoid this warning what I do, I went to util.c file and comment out gets(line); then the program work very well. Any idea why this warning. Is possible to run the program without commenting out this line?

Again thank you very much

Without seeing util.c I can't know what it's using gets for. gets reads a string from standard input, storing it as a character array terminated by a NULL character.

The problem with gets is that it takes an unlimited amount of input. It does not know how much space is available in the buffer. For instance:

#include <stdio.h>
int main()
{
  char buf[16];
  gets(buf);
  printf("You typed %s\n",buf);
  return(0);
}

If I typed "486193474587130958712057190856714890651618476" and hit enter, it would dump that entire string into that buffer of 16 bytes, which obviously isn't large enough to hold it. The remainder of it would get crammed into whatever bytes of memory trail after the buffer, which may be unused, or used for other variables, or part of the call stack, etc. When overflows like this happen they can be VERY hard to debug since by nature buffer overflows overwrite memory they're not supposed to. It's also a security risk -- if someone knows there's a buffer they can overflow, they can write to variables after it in memory, setting them to whatever values they want!

This is much safer:

#include <stdio.h>

int main()
{
  char buf[16];
  fgets(buf,16,stdin);
  printf("You typed %s\n",buf);
  return(0);
}

This will not overflow the buffer, it will only read a maximum of 15 bytes.