Hi People

I'm a newbie in c, I learn in c++, but I don`t really know to much. A friend make a code in c, working in a linux pc. And works perfect.

I normally work in Micorsoft Visual Studio, but this c code, seems not to work well (88 errors). So I start using DevCpp and looks that the c code runs, but there still are too much errors (31). Why the different compilers show different number of errors. The code employ a lot of gsl libraries (GNU Scientific Library).

You have any idea what ould be happening.

Thanx in advance for your time

Paulville


This are the kind of error that appears

In function `web_calc':
92: parse error before `double'
96: `y' undeclared (first use in this function)
96: (Each undeclared identifier is reported only once
96: for each function it appears in.)
100: parse error before `)'
103: `params' undeclared (first use in this function)
115: parse error before `const'
126: `t' undeclared (first use in this function)
135: `tend' undeclared (first use in this function)
146: parse error before `int'
147: `status' undeclared (first use in this function)
187: `s' undeclared (first use in this function)
188: `c' undeclared (first use in this function)
189: `e' undeclared (first use in this function)
In function `dynamics':
227: parse error before `ydot_vec'
245: `EAgsl' undeclared (first use in this function)
245: `yjgsl' undeclared (first use in this function)
245: `tvec' undeclared (first use in this function)
247: `Hmat' undeclared (first use in this function)
251: `Gmat' undeclared (first use in this function)
262: `Tmat' undeclared (first use in this function)
268: parse error before `*'
273: `Bp' undeclared (first use in this function)
277: `ratio' undeclared (first use in this function)
282: `death' undeclared (first use in this function)
291: `ydotgsl' undeclared (first use in this function)
295: parse error before `double'
311: `growth' undeclared (first use in this function)
312: `index1' undeclared (first use in this function)
313: `index2' undeclared (first use in this function)
315: `oldtemp' undeclared (first use in this function)

Pasting the first 100 lines (so we see everything upto the first error line number, and a bit beyond) would be helpful.

Ok Salem I'll do it. I will edit it, but like the line with errors appear in here, I don't change it.

#include <stdio.h>
#include <math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_rng.h>                     // random number generator
#include <gsl/gsl_odeiv.h>                       // ODE-solving procedures 
#include <gsl/gsl_errno.h>                       // errorhandler
#include <gsl/gsl_blas.h>                        // linear algebra with vecors and matrices

// global variables:
double alpha=0.1;                           // mortality rate
double beta=1;                              // interspecific concurrence
double lambda=0.5;                      // biologic efficiency
double K1=1;                                // carrying capacity of resources
double aleph=1;                         // half saturation density (scaling parameter for volumes)
double beth=1;                              //  handling time
double delta1=20;                           // growth rate of resources
double z=0.5;                               // ration of sizes between two size classes
double Imax=10;                         // maximum ingestion rate
double T=1;                                 // metabolic requirements (maintenace costs)
int GC=0;

double *web_calc(int S, int B, const gsl_rng_type *T, gsl_rng *r, FILE *populdata, FILE *inputdata);
int dynamics(double t, const double y[], double ydot[], void *params);
int Delta(int i, int j);
int Theta(double g);

//*******************************************************************
// Main Part
//*******************************************************************
int main(void)
{
    FILE *populdata;                    // Hier werden die Populationen reingeschrieben
    FILE *inputdata;                    // File with input parameters/ abundances
    int B=1;                                // Anzahl der unabhaengigen externen Ressourcen
    int S=4;                                // Anzahl der Spezies im Netz (ohne Ressourcen)

    const gsl_rng_type *T;          // ****
    gsl_rng *r;                         // Initialisierung des Zufallszahlengenerators
    gsl_rng_env_setup();            // ****
    T=gsl_rng_default;              // default random number generator (so called mt19937)
    gsl_rng_default_seed=4395;      // Startwert fuer den RNG
    r=gsl_rng_alloc(T);

    populdata=fopen("ssp-N.out","w");
    inputdata=fopen("data.input","r");

    web_calc(S,B,T,r,populdata,inputdata);

    fclose(populdata);
    fclose(inputdata);  

    gsl_rng_free(r);

    return(0);
}

//****************************************************************************
// Produce network structure and calculate the population sizes
//**************************************************************************** 
double *web_calc(int S, int B, const gsl_rng_type *T, gsl_rng *r, FILE *populdata, FILE *inputdata)
{
    int i,j,k;
    int L=2,flag,xflag;                                     // Kontrollvariablen

    double *test=(double *)calloc(2*B+2*(S+L),sizeof(double));

    gsl_matrix *Ap=gsl_matrix_calloc (B+S,B+S);
    gsl_matrix *A=gsl_matrix_calloc (B+S,B+S);

// determine feeding relationships
    gsl_matrix_set(Ap,1,0,1);
    gsl_matrix_set(Ap,2,0,1);
    gsl_matrix_set(Ap,2,1,1);
    gsl_matrix_set(Ap,3,0,1);
    gsl_matrix_set(Ap,3,2,1);
    gsl_matrix_set(Ap,4,0,1);
    gsl_matrix_set(Ap,4,3,1);

    gsl_matrix_set(A,1,0,1);

    gsl_matrix_set(A,2,0,0.7);

    gsl_matrix_set(A,2,1,0.3);

    gsl_matrix_set(A,3,0,0.7);

    gsl_matrix_set(A,3,2,0.3);
    gsl_matrix_set(A,4,0,0.7);
    gsl_matrix_set(A,4,3,0.3);

    double *y = (double *) calloc(B+S,sizeof(double));          // populations
    double *params=(double *) calloc(2+(B+S)*(B+S),sizeof(double));

    for(i=0;i<=B-1;i++)
        y[i]=1;

    for(i=B;i<=B+S-1;i++)
//      y[i]=gsl_rng_uniform_pos(r)*1/(double)S;
        y[i]=1/(double)S);
//      fscanf(inputdata,"%lf \n",&y[i]);

The code simulates a trophic network based on the size of the individuals. At the beggining we ceate some matrix that indicate who eats who, and there preference for each other.

In function `web_calc':        /* in the function web_calc you have the following errors */
92: parse error before `double'
96: `y' undeclared (first use in this function) /* y is a variable not declared before use */
96: (Each undeclared identifier is reported only once
96: for each function it appears in.)
100: parse error before `)'       /* Probably error because the lack of variable y */
103: `params' undeclared (first use in this function) /* variable params is not declared */
115: parse error before `const'
126: `t' undeclared (first use in this function) /* var t is not declared before use */
135: `tend' undeclared (first use in this function) /* var tend is not declared */
146: parse error before `int'
147: `status' undeclared (first use in this function) /* var status is not declared */
187: `s' undeclared (first use in this function)      /* var s is not found before use */
188: `c' undeclared (first use in this function)     /* variable c is not declared */
189: `e' undeclared (first use in this function)     /* variable e is not declared */
In function `dynamics':    /* in function dynamics you have the following errors */
227: parse error before `ydot_vec'    /* error due because of missing undeclared variables */
245: `EAgsl' undeclared (first use in this function) /* EAgsl is not declared */
245: `yjgsl' undeclared (first use in this function) /* yjgsl is missing */
245: `tvec' undeclared (first use in this function) /* tvec is not declared */
247: `Hmat' undeclared (first use in this function) /* Hmat is not declared */
251: `Gmat' undeclared (first use in this function) /* Gmat is not declared */
262: `Tmat' undeclared (first use in this function) /* Tmat is missing */
268: parse error before `*'
273: `Bp' undeclared (first use in this function)   /* Bp not found before using */
277: `ratio' undeclared (first use in this function) /* ratio missing */
282: `death' undeclared (first use in this function) /* death is not found.  "I wish it were true" */
291: `ydotgsl' undeclared (first use in this function) /* ydotgsl not there */
295: parse error before `double'
311: `growth' undeclared (first use in this function) /* growth variable is gone fishing */
312: `index1' undeclared (first use in this function) /* index1 is not declared */
313: `index2' undeclared (first use in this function) /* index2 gone with buddy index1 */
315: `oldtemp' undeclared (first use in this function) /* oldtemp got tire of being old and die */

Basically your compiler is complainig that is missing a lot of variables. Are you sure you are including every Header file necesary for the code to compile. A header file might have what web_calc and dynamics functions are.

Yes, I have included all the headers!!

math.h
stdio.h
and all the gsl libraries

And like I tell you the same folder runs well in linux!! And the compiler never complains about a missing header. It always does

Yes, I have included all the headers!!

math.h
stdio.h
and all the gsl libraries

And like I tell you the same folder runs well in linux!! And the compiler never complains about a missing header. It always does

I see that you post some code portion while I was replaying.
Try to locate every variable or function that the compile doesn't see. And find out why it doesn't see it.

Ok!

I´m going to do that. But someone knows why it could be running well in Linux and but in Windows, that is something normal, do you recommends me to make a partition in my hard disk, linux:windows? Or what!??

Ok!

I´m going to do that. But someone knows why it could be running well in Linux and but in Windows

These header files are not part of the Standard C Library:
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_rng.h> // random number generator
#include <gsl/gsl_odeiv.h> // ODE-solving procedures
#include <gsl/gsl_errno.h> // errorhandler
#include <gsl/gsl_blas.h> // linear algebra with vecors and matrices

Those are part of the GNU Scientific Library. No in your Windows compiler by default.

These header files are not part of the Standard C Library:
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_rng.h> // random number generator
#include <gsl/gsl_odeiv.h> // ODE-solving procedures
#include <gsl/gsl_errno.h> // errorhandler
#include <gsl/gsl_blas.h> // linear algebra with vecors and matrices

Those are part of the GNU Scientific Library. No in your Windows compiler by default.

I know. I lalready copy the GSL library in the default folder of my Windows compiler

I know. I lalready copy the GSL library in the default folder of my Windows compiler

I was trying to point to some possible cause why it worked in Linux but not in Windows.
Just because you have installed a port of those libraries to Windows is not garantie that the implementation of the code is the same. If there were Standard C Libraries then you'll know that the implementation of the code would have a greater chance of running in both
platforms without any major change.

You might be better off trying to compile it as a C++ program rather than a C program.

Your friend has obviously made use of a few compiler extensions which GCC supports, but which few other C compilers do, in particular:

gsl_matrix_set(A,4,3,0.3);

double *y = (double *) calloc(B+S,sizeof(double)); // populations

Standard C does NOT support mixed declarations and statements. For that you need
- a C++ compiler
- Some non-standard extension in your C compiler
- A C99 (the new C standard) compiler.

Oh, and please use [code]
[/code] tags when you post code (see intro threads).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.