compiling problems

S

Sheldon

Good day Everyone,

I am a still very new at learning C and I have thrown myself in the
deep end. I started with a simple program and kept widening the scope.
This has taught me many things about C and some, I must admit, have not
really sunk in yet. Still, I push on. Now I am taken a library of C
programs that were designed to read HDF files. I work on a Unix server
and in Mandrake10. The program below is most likely broken but I cannot
solve any problem unitl I get pass my current problem in compiling. All
the codes that I need: *.c and *.h are located in directory given in
the compilation command:

cc -g msgpps_functions.c -I/data/proj/safworks/MSG_PPS_COMP/c_codes

And I get the following oputput that baffles me:

/home/tmp/ccAn0IYi.o(.text+0x67f): In function `readHDF':
/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:197:
undefined reference to `initHlHdf'
/home/tmp/ccAn0IYi.o(.text+0x694):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:201:
undefined reference to `readHL_NodeList'
/home/tmp/ccAn0IYi.o(.text+0x6cc):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:207:
undefined reference to `selectNode'
/home/tmp/ccAn0IYi.o(.text+0x6fc):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:212:
undefined reference to `fetchMarkedNodes'
/home/tmp/ccAn0IYi.o(.text+0x70d):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:214:
undefined reference to `getNode'
/home/tmp/ccAn0IYi.o(.text+0x87b):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:243:
undefined reference to `freeHL_NodeList'
collect2: ld returned 1 exit status

Now, I have included the code but not the dependencies -- thought that
that would be too much. I would really like to know why this
compilation problem arose. All of the functions mentioned above are
declared in one or another of the dependencies in the path given and
the #include files.

Appreciate the help,

Sheldon

**********************************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <read_vhlhdf.h>
#include <read_hlhdf.h>
#include <hlhdf.h>
#include <sys/types.h>
#include <dirent.h>
#include <vhlhdf.h>

#define ROW 1215
#define COL 1215
#define Auxdatadir "/data/proj/safworks/sheldon/MSG_PPS_COMP/data/aux/"
#define Region "ibla_57n20e"
#define Date 200512

static int inithdf = 1; // Är 1 om initHlHdf ej har anropats, 0
annars. This routine must be run
int readHDF(float** , char *hdfname, char *fieldname);

// Variable Declaration
char Filename[] =
"/data/proj/safworks/sheldon/MSG_PPS_COMP/data/aux/test_array.dat";
char Reprodir[100];
char Physdata[100];
//*********************************************************************************************************
struct hdfstruct {
float** latitude;
float** longitude;
float** landuse;
float** fractofland;
float** sunangle;
float** viewingangle;
};

int main(void) {

struct hdfstruct hdfdata;
FILE *fp = NULL;
double** array;
int i, j, num, stat;
int dataprecision = 4;
unsigned char** tmp;
double count;
char* strp;
char Latfile[150];
char Lonfile[150];
char hdfname[] =
"/data/proj/safworks/pps_v11/import/AUX_data/remapped/physiography.ibla_35n00e.hdf";
char latfile[150];
// Putting the file strings together for lat and long files
strcpy(Latfile,Auxdatadir);
strcat(Latfile,Region);
strcat(Latfile,"_lat.data");
strcpy(Lonfile,Auxdatadir);
strcat(Lonfile,Region);
strcat(Lonfile,"_lon.data");
strcpy(latfile,Auxdatadir);
strcat(latfile,Region);
strcat(latfile,"_latlon.h5");

printf("\n%s\n\n", Latfile);
printf("%s\n\n", Lonfile);

// allocate memory with error checking for lon and lat files
hdfdata.latitude = calloc(ROW,sizeof(float *));
hdfdata.longitude = calloc(ROW,sizeof(float *));
hdfdata.landuse = calloc(ROW,sizeof(float *));
hdfdata.fractofland = calloc(ROW,sizeof(float *));
hdfdata.sunangle = calloc(ROW,sizeof(float *));
hdfdata.viewingangle = calloc(ROW,sizeof(float *));

if(hdfdata.latitude == NULL ||
hdfdata.longitude == NULL ||
hdfdata.landuse == NULL ||
hdfdata.fractofland == NULL ||
hdfdata.sunangle == NULL ||
hdfdata.viewingangle == NULL) { // Memory for the ROWS
fprintf(stderr, "Failed to allocate memory");
return EXIT_FAILURE;
}
for (i = 0; i < ROW; i++) {
hdfdata.latitude = calloc(COL,sizeof(float));
hdfdata.longitude = calloc(COL,sizeof(float));
hdfdata.landuse = calloc(COL,sizeof(float));
hdfdata.fractofland = calloc(COL,sizeof(float));
hdfdata.sunangle = calloc(COL,sizeof(float));
hdfdata.viewingangle = calloc(COL,sizeof(float));
if(hdfdata.latitude == NULL ||
hdfdata.longitude == NULL ||
hdfdata.landuse == NULL ||
hdfdata.fractofland == NULL ||
hdfdata.sunangle == NULL ||
hdfdata.viewingangle == NULL) { // Memory for the COLS
fprintf(stderr, "Failed to allocate memory");
return EXIT_FAILURE;
}
}
// Reading the hdf data into the arrays
stat = readHDF(hdfdata.latitude,latfile,"/LAT");
if (stat == 0) {
fprintf(stderr, "Failed reading latitude hdf");
return EXIT_FAILURE;
}

if((tmp=calloc(ROW,sizeof(float *))) == NULL) { // Memory for the
ROWS
fprintf(stderr, "Failed to allocate memory");
return EXIT_FAILURE;
}

for (i = 0; i < ROW; i++) {
if((tmp=calloc(COL,sizeof(float))) == NULL) { // Memory for the
COLS
fprintf(stderr, "Failed to allocate memory");
return EXIT_FAILURE;
}
}

// Opening and reading lon and lat files
printf("Opening lat file: %s\n",Latfile);
if ((fp = fopen(Latfile, "rb")) == NULL) {
fprintf(stderr, "Error opening file %s in read mode.\n", Latfile);
fclose(fp);
goto fail;
}
else
printf("File opened successfully.\n\n");

printf("Reading said file.\n\n");
if (ROW*COL*4 != fread(tmp, sizeof(unsigned char), ROW*COL*4, fp)) {
fprintf(stderr, "Error reading file: %s\n", Latfile);
fclose(fp);
goto fail;
}
else {
printf("File read successfully.\n\n");
fclose(fp);
}

// allocate memory with error checking test array
if((array=calloc(ROW,sizeof(double *))) == NULL) { // Memory for the
ROWS
fprintf(stderr, "Failed to allocate memory");
return EXIT_FAILURE;
}

for (i = 0; i < ROW; i++) {
if((array=calloc(COL,sizeof(double))) == NULL) { // Memory for
the COLS
fprintf(stderr, "Failed to allocate memory");
return EXIT_FAILURE;
}
}

// display read array for debuging
printf("Printing array\n");
for (i = 0; i < 5; i++) {
printf("latitudes[%d,%d] = \t%f\n", i,j, hdfdata.latitude[i,j]);
}

fail:
if(array) {
for (i = 0; i < ROW; i++) {
free(array);
}
free(array);
}
return EXIT_FAILURE;
}

int readHDF(float **arp, char *hdfname, char *fieldname) {

HL_NodeList *nodelist = NULL; // These are take from read_vlhdf.h
where some explanation is given
HL_Node *cloudproduct; // These are pointers to structures
HL_Node *dataset;
HL_CompoundTypeAttribute *attr; // pointer to structure
int i, xsize, ysize;
int dataprecision = sizeof(float);

if (inithdf) {
initHlHdf();
inithdf = 0;
}

nodelist = readHL_NodeList(hdfname);
if (!nodelist) {
fprintf(stderr, "Error reading hdf-file: %s\n", hdfname);
goto error;
}

if (!selectNode(nodelist, fieldname)) {
fprintf(stderr, "Dataset in %s was not found in %s.\n",fieldname,
hdfname);
goto error;
}

fetchMarkedNodes(nodelist); // gets the data from selected dataset

cloudproduct = getNode(nodelist, fieldname);

if (!cloudproduct) {
fprintf(stderr, "Error reading data from %s\n", hdfname);
goto error;
}
for (i = 0; i < cloudproduct->compoundDescription->nAttrs; i++) {
attr = cloudproduct->compoundDescription->attrs;
if(0 == strcmp(attr->attrname, "xsize")) {
xsize = *((int *)&cloudproduct->data[attr->offset]);
} else if (0 == strcmp(attr->attrname,"ysize")) { // checking to
see if there is such an attribute
ysize = *((int *)&cloudproduct->data[attr->offset]); // casting
from binary to int
}
}

if (xsize != COL || ysize != ROW) {
if (xsize <= 0 || ysize <= 0) {
fprintf(stderr, "Error: hdf-file has undefined size.\n");
goto error;
} else {
fprintf(stderr,
"Warning: hdf-file has unexpected size: %d×%d\n",
xsize, ysize);
}
}

memcpy(arp, cloudproduct->data, ROW * COL * dataprecision); // This
converts the data from binary to float

error: {
if (nodelist) freeHL_NodeList(nodelist);
if (arp) free(arp);
return (0);
}
return (1);
}
 
E

Eric Sosman

Sheldon said:
Good day Everyone,

I am a still very new at learning C and I have thrown myself in the
deep end. I started with a simple program and kept widening the scope.
This has taught me many things about C and some, I must admit, have not
really sunk in yet. Still, I push on. Now I am taken a library of C
programs that were designed to read HDF files. I work on a Unix server
and in Mandrake10. The program below is most likely broken but I cannot
solve any problem unitl I get pass my current problem in compiling. All
the codes that I need: *.c and *.h are located in directory given in
the compilation command:

cc -g msgpps_functions.c -I/data/proj/safworks/MSG_PPS_COMP/c_codes

And I get the following oputput that baffles me:

/home/tmp/ccAn0IYi.o(.text+0x67f): In function `readHDF':
/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:197:
undefined reference to `initHlHdf'
/home/tmp/ccAn0IYi.o(.text+0x694):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:201:
undefined reference to `readHL_NodeList'
/home/tmp/ccAn0IYi.o(.text+0x6cc):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:207:
undefined reference to `selectNode'
/home/tmp/ccAn0IYi.o(.text+0x6fc):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:212:
undefined reference to `fetchMarkedNodes'
/home/tmp/ccAn0IYi.o(.text+0x70d):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:214:
undefined reference to `getNode'
/home/tmp/ccAn0IYi.o(.text+0x87b):/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:243:
undefined reference to `freeHL_NodeList'
collect2: ld returned 1 exit status

Now, I have included the code but not the dependencies -- thought that
that would be too much. I would really like to know why this
compilation problem arose. All of the functions mentioned above are
declared in one or another of the dependencies in the path given and
the #include files.
[...]

The #include files contain declarations of the functions
you're trying to use, but almost certainly don't contain the
actual "meat" of those functions. The actual implementations
of the functions are probably found in a library that is part
of this HDF package you've acquired. The declarations in the
#include files describe selectNode() et al. so that you can
compile the various modules of your program, but when you link
the compiled modules together you must tell the linker where
it can find those external functions. You probably need to add
something to the compiler's command line to inform it where the
function bodies can be found; it might be as simple as "-lhdf"
or it might be more involved. Check the documentation for the
HDF package and for your compiler.

It's really the same with the standard C library functions:
If you look inside the <stdio.h> file you will find descriptions
of printf() and fclose() and so on, but not the actual bodies of
those functions. They come from "elsewhere," but since these
are "standard" functions intended to be available to all C
programs, the C compiler and linker already know where to look
for them and don't need to be told. Your HDF package is an add-
on of some kind, and the compiler needs to be told about it.
 
B

Bill Pursell

Sheldon said:
Good day Everyone,

I am a still very new at learning C and I have thrown myself in the
deep end. I started with a simple program and kept widening the scope.
This has taught me many things about C and some, I must admit, have not
really sunk in yet. Still, I push on. Now I am taken a library of C
programs that were designed to read HDF files. I work on a Unix server
and in Mandrake10. The program below is most likely broken but I cannot
solve any problem unitl I get pass my current problem in compiling. All
the codes that I need: *.c and *.h are located in directory given in
the compilation command:

cc -g msgpps_functions.c -I/data/proj/safworks/MSG_PPS_COMP/c_codes

And I get the following oputput that baffles me:

/home/tmp/ccAn0IYi.o(.text+0x67f): In function `readHDF':
/data/proj/safworks/MSG_PPS_COMP/c_codes/msgpps_functions.c:197:
undefined reference to `initHlHdf'
collect2: ld returned 1 exit status

Now, I have included the code but not the dependencies -- thought that
that would be too much. I would really like to know why this
compilation problem arose. All of the functions mentioned above are
declared in one or another of the dependencies in the path given and
the #include files.

Your compilation succeeded. Look at the error message closely, and
you'll see that the error is with ld. So your code compiled okay, but
the link step failed. If you have code for all of the functions, say
in
a file named foo.c, then you can probably build an executable
by simply addind foo.c as an argument to the compile line. That
is less appropriate than building libfoo.a and using "-lfoo" to
tell the linker about the other functions.

Including a declaration in a header file allowed your compilation
to succeed. Now you just to tell the linker where to find the
code.
 
C

CBFalconer

Sheldon said:
I am a still very new at learning C and I have thrown myself in
the deep end. I started with a simple program and kept widening
the scope. This has taught me many things about C and some, I must
admit, have not really sunk in yet. Still, I push on. Now I am
taken a library of C programs that were designed to read HDF files.
I work on a Unix server and in Mandrake10. The program below is
most likely broken but I cannot solve any problem unitl I get pass
my current problem in compiling. All the codes that I need: *.c
and *.h are located in directory given in the compilation command:

cc -g msgpps_functions.c -I/data/proj/safworks/MSG_PPS_COMP/c_codes
.... snip ...

Now, I have included the code but not the dependencies -- thought
that that would be too much. I would really like to know why this
compilation problem arose. All of the functions mentioned above
are declared in one or another of the dependencies in the path
given and the #include files.

*****************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

To start with, all the following #includes are non-standard and
unknown to us. We deal only with standard C here.
#include <read_vhlhdf.h>
#include <read_hlhdf.h>
#include <hlhdf.h>
#include <sys/types.h>
#include <dirent.h>
#include <vhlhdf.h>

#define ROW 1215
#define COL 1215
#define Auxdatadir "/data/proj/safworks/sheldon/MSG_PPS_COMP/data/aux/"
#define Region "ibla_57n20e"
#define Date 200512

static int inithdf = 1; // Är 1 om initHlHdf ej har anropats, 0
annars. This routine must be run

This illustrates why you should not use // comments in any code
posted to the newsgroup. First, it wraps, and becomes invalid
source. Second, it is not even a legal comment in the most
portable C systems, such as those that adhere to the C90 standard.

Just use proper /* .... */ comments.
int readHDF(float** , char *hdfname, char *fieldname);

// Variable Declaration
char Filename[] =
"/data/proj/safworks/sheldon/MSG_PPS_COMP/data/aux/test_array.dat";
char Reprodir[100];
char Physdata[100];
//*********************************************************************************************************

Also, to avoid line wrap in usenet, limit your line length to 72
chars. 65 is better.
struct hdfstruct {
float** latitude;
float** longitude;
float** landuse;
float** fractofland;
float** sunangle;
float** viewingangle;
};

int main(void) {
.... snip code ...

I suggest you follow the above suggestions and repost. In general
you should avoid creating routines that are too long. Break your
system down into simpler functions that do simple things, and
return information.

When you have something that can be compiled with:

gcc -W -Wall -ansi -pedantic

you are most of the way there. Read the links below.

--
Some informative links:
< <http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
 
S

Sheldon

Bill Pursell skrev:
Your compilation succeeded. Look at the error message closely, and
you'll see that the error is with ld. So your code compiled okay, but
the link step failed. If you have code for all of the functions, say
in
a file named foo.c, then you can probably build an executable
by simply addind foo.c as an argument to the compile line. That
is less appropriate than building libfoo.a and using "-lfoo" to
tell the linker about the other functions.

Including a declaration in a header file allowed your compilation
to succeed. Now you just to tell the linker where to find the
code.

Thanks Guys,

Now I have a direction, at least.
I have to look at the Makefile and see if I can figure out how to use
it.
Unfortunately, the documentation is very poor and almost non-existent.

/Sheldon
 
S

Sheldon

CBFalconer skrev:
Sheldon said:
I am a still very new at learning C and I have thrown myself in
the deep end. I started with a simple program and kept widening
the scope. This has taught me many things about C and some, I must
admit, have not really sunk in yet. Still, I push on. Now I am
taken a library of C programs that were designed to read HDF files.
I work on a Unix server and in Mandrake10. The program below is
most likely broken but I cannot solve any problem unitl I get pass
my current problem in compiling. All the codes that I need: *.c
and *.h are located in directory given in the compilation command:

cc -g msgpps_functions.c -I/data/proj/safworks/MSG_PPS_COMP/c_codes
... snip ...

Now, I have included the code but not the dependencies -- thought
that that would be too much. I would really like to know why this
compilation problem arose. All of the functions mentioned above
are declared in one or another of the dependencies in the path
given and the #include files.

*****************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

To start with, all the following #includes are non-standard and
unknown to us. We deal only with standard C here.
#include <read_vhlhdf.h>
#include <read_hlhdf.h>
#include <hlhdf.h>
#include <sys/types.h>
#include <dirent.h>
#include <vhlhdf.h>

#define ROW 1215
#define COL 1215
#define Auxdatadir "/data/proj/safworks/sheldon/MSG_PPS_COMP/data/aux/"
#define Region "ibla_57n20e"
#define Date 200512

static int inithdf = 1; // Är 1 om initHlHdf ej har anropats, 0
annars. This routine must be run

This illustrates why you should not use // comments in any code
posted to the newsgroup. First, it wraps, and becomes invalid
source. Second, it is not even a legal comment in the most
portable C systems, such as those that adhere to the C90 standard.

Just use proper /* .... */ comments.
int readHDF(float** , char *hdfname, char *fieldname);

// Variable Declaration
char Filename[] =
"/data/proj/safworks/sheldon/MSG_PPS_COMP/data/aux/test_array.dat";
char Reprodir[100];
char Physdata[100];
//*********************************************************************************************************

Also, to avoid line wrap in usenet, limit your line length to 72
chars. 65 is better.
struct hdfstruct {
float** latitude;
float** longitude;
float** landuse;
float** fractofland;
float** sunangle;
float** viewingangle;
};

int main(void) {
... snip code ...

I suggest you follow the above suggestions and repost. In general
you should avoid creating routines that are too long. Break your
system down into simpler functions that do simple things, and
return information.

When you have something that can be compiled with:

gcc -W -Wall -ansi -pedantic

you are most of the way there. Read the links below.

--
Some informative links:
<<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>

Thanks! Your advice is really helpful. I need to find out from where
some of the dependent files are located before I can continue with
this. Will "clean up" my code.

/Sheldon
 
K

Kenny McCormack

CBFalconer said:
To start with, all the following #includes are non-standard and
unknown to us. We deal only with standard C here.

The really funny part is that, in any other newsgroup, if people posted
responses that said "I don't understand; I have no idea what you're
talking about; I can't help you.", it would be considered the ultimate
in ridiculous and people would, quite rightly, wonder what the poster
was smoking.

Yet, here, for some reason, it is not only acceptable, but common.
gcc -W -Wall -ansi -pedantic

The usual crippleware options.
 
S

Sheldon

Kenny McCormack skrev:
The really funny part is that, in any other newsgroup, if people posted
responses that said "I don't understand; I have no idea what you're
talking about; I can't help you.", it would be considered the ultimate
in ridiculous and people would, quite rightly, wonder what the poster
was smoking.

Yet, here, for some reason, it is not only acceptable, but common.


The usual crippleware options.

I put together a make file and found out where some of my dependent
files are placed. after some work, it worked smoothly.
Still - and this might sound really silly but here goes - what does the
options -W and -Wall mean?
I looked these up but it does not seem to be a part of cc. Is unigue to
gcc?
 
K

Keith Thompson

Sheldon said:
[...]

I put together a make file and found out where some of my dependent
files are placed. after some work, it worked smoothly.
Still - and this might sound really silly but here goes - what does the
options -W and -Wall mean?
I looked these up but it does not seem to be a part of cc. Is unigue to
gcc?

"cc" is a common name for C compilers in general, particularly on
Unix-like systems. We can't guess which compiler you're referring to.
On some systems, "cc" is an alias for "gcc".

Yes, all the options "-W", "-Wall", "-ansi", and "-pedantic" are
specific to gcc. Some compilers may have options with the same name;
they're likely to mean the same thing *if* they're copied from gcc,
otherwise they could have some different meaning.

<OT>
In gcc, "-W" and "-Wall" enable certain sets of warning messages,
"-ansi" tells it to conform to the C90 standard, and "-pedantic" tells
it to be more diligent about reporting certain errors. See the gcc
documentation for details (you should be able to find it on the web).
</OT>
 
R

Richard Heathfield

Keith Thompson said:

<OT>
In gcc, "-W" and "-Wall" enable certain sets of warning messages,
"-ansi" tells it to conform to the C90 standard, and "-pedantic" tells
it to be more diligent about reporting certain errors. See the gcc
documentation for details (you should be able to find it on the web).

The traditional (but non-canonical) interpretations are:

-W : give me all the warnings please
-Wall : no, ALL the warnings please
-ansi : no really, I honestly want ALL the warnings
-pedantic: yeah, AND the rest
-Wformat-nonliteral -Wcast-align -Wpointer-arith -Wbad-function-cast
-Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Winline
-Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 : look, I really mean it, okay?

Um, quite so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top