Posts Tagged ‘ C

MB-System: progress update

I left off yesterday with some unresolved issues. These issues are still unresolved today, however, I think I’ve narrowed it down to GDAL – surprise, surprise… It seems like my ‘undefined references’ are all related to GDAL functions. Since I know next to nothing about C libraries and header files it’s a bit tough reading through the forums that might otherwise be helpful. I wonder if I messed things up by installing GDAL using Synaptic, and then from source… I noticed that I have gdal-type files replicated in more than one place. Something tells me that can’t be good.

Here are the last few lines where things started to go haywire when running the MB-System sudo make all (it goes on and on and on, this is just a little snippet):

cd utilities; make all
make[2]: Entering directory `/home/michelle/Documents/mbsystem-5.1.2/src/utilities'
cc -g -w -DLINUX -DBYTESWAPPED mbprocess.o ../../lib/libmbio.a ../../lib/libmbproj.a ../../lib/libmbgsf.a ../../lib/libmr1pr.a ../../lib/libsapi.a ../../lib/libmbaux.a \
/home/michelle/Documents/GMT/GMT4.5.2/lib/libgmt.a /home/michelle/Documents/GMT/GMT4.5.2/lib/libpsl.a \
-L/home/michelle/Documents/GMT/netcdf-3.6.3/lib -lm -lnetcdf -L/home/michelle/Documents/GMT/netcdf-3.6.3/lib -lnetcdf -o ../../bin/mbprocess
/home/michelle/Documents/GMT/GMT4.5.2/lib/libgmt.a(gmt_customio.o): In function `ComputeRasterMinMax':
gmt_customio.c:(.text+0x65a7): undefined reference to `GDALGetRasterNoDataValue'
gmt_customio.c:(.text+0x65b5): undefined reference to `GDALGetRasterDataType'

Still working on MB-System

Yeah, I really should’ve realized it was just too easy.  I just tried installing MB-System, and I am getting a ton of errors because my c compiler is not recognizing simple math functions like sin, cos, sqrt, pow, etc.  I’m sure this is a really simple issue, and I’m just clueless about c in general.  But I really don’t know how to fix this.

Googling around, I did find some information – I think I’m missing a ‘-lm’ option somewhere (so that c links to the math library).  I found this conversation on an Ubuntu forum. Someone else was having the same problem, and part of the troubleshooting involved created a simple test program in C that uses some a math function (sin in this case). Here’s the little script that they use to create the test program. It’s called ‘test1.c’.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{
float x,y;
printf("enter the value of x\n");
scanf("%f",&amp;x);
printf("Hello world\n");
y=sin(x);
printf("value of y is %f \n",y);
printf("\nEnd of program\n");
}

Then if I type gcc -o test1 -lm test1.c in the terminal window, it creates a compliled program test1 from the test1.c code. I was then able to run it by type ./test1. Now, this didn’t exactly solve my problem, but it was pretty cool, and it worked. Which is significant in its own right since it is, quite literally, my VERY FIRST C PROGRAM. Ever. Yup, I just skipped right over “Hello, world”.

So, eventually I did manage to get past the above problem. I had a typo in my install_makefiles script, so I had to re-run it:
./install_makefiles
then sudo make all.

I was then able to find and use the appropriate math library. But I was still getting a ton of ‘undefined reference’ errors for a bunch of GDAL files. Not sure how to fix that. I think it’ll have to wait until tomorrow…