PDA

View Full Version : Make file problem - cannot convert float to float*




smurray444
Feb 26, 2009, 06:12 AM
Dear all,

I'm struggling with a make file error which is as follows:

g++ -I/sw/include -I/LPX/utils -c -o lpjio.o lpjio.cpp
lpjio.cpp: In function ‘int outannual_(int*, int*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, float*)’:
lpjio.cpp:1168: error: cannot convert ‘float’ to ‘float*’ for argument ‘2’ to ‘void handle_output_record(std::string, float*)’
lpjio.cpp:1178: error: cannot convert ‘float**’ to ‘float*’ for argument ‘2’ to ‘void handle_output_record(std::string, float*)’
make: *** [lpjio.o] Error 1


The code that it refers to (as far as I can tell) is as follows:

extern "C" int outannual_(int *year, int *present,
float *nind,
float *lm_ind, float *rm_ind,
float *sm_ind, float *hm_ind,
float *fpc_grid,
float *anpp, float *acflux_estab,
float *litter_ag, float *litter_bg,
float *cpool_fast, float *cpool_slow,
float *arh, float *afire_frac, float *acflux_fire,
float *mcflux_fire,
float *arunoff, float *sla, float *mpar,
float *mapar, float *xmphen, float *anpp_add,
float *mnpp, float *mrunoff, float *aaet,
float *mrh, float *mnpp_add, float *maet,
float *xmgpp, float *mtemp_soil, float *xmcica,
float *xmlresp, float *xmsresp, float *xmrresp,
float *xmgresp, float *xmaresp,
float *mauw1, float *mauw2,
float *maep, float *aaep,
float *mpet_grid, float *apet_grid,
float *mintc, float *aintc,
float *xmeangc, float *xmgp,
float *num_fire, float *annum_fire,
float *area_burnt, float *an_areafires,
float *mfdi, float *an_fdi, float *an_fseason,
float *acflux_trace, float *xmcflux_trace,
float *m_fc_crown, float *an_fc_crown,
float *m_i_surface, float *an_i_surface,
float *gdd, float *height, float *mgpp,
float *wu, float *wl, float *dphen)
#else
extern "C" int outannual_(int *year, int *present,
float *nind,
float *lm_ind, float *rm_ind,
float *sm_ind, float *hm_ind,
float *vegc, float *fpc_grid,
float *anpp, float *acflux_estab,
float *litter_ag, float *litter_bg,
float *cpool_fast, float *cpool_slow,
float *arh, float *afire_frac, float *acflux_fire,
float *arunoff, float *sla, float *mpar,
float *mapar, float *xmphen, float *anpp_add,
float *mnpp, float *mrunoff, float *aaet,
float *mrh, float *mnpp_add, float *maet,
float *xmgpp, float *mtemp_soil, float *xmcica,
float *xmlresp, float *xmsresp, float *xmrresp,
float *xmgresp, float *xmaresp,
float *mw1, float *mw2,
float *maep, float *aaep,
float *mintc, float *aintc,
float *gdd, float *height, float *mgpp,
float *wu, float *wl, float *dphen,
float *lresp, float *sresp, float *rresp,
float *gresp,
float *mpet, float *arunoff_drain,
float *arunoff_surf, float *mrunoff_drain,
float *mrunoff_surf, float *apet, float *mprecip,
float *aprec, float *lai_ind, float *total_anpp)



And the handle_output_record (in the same file, lpjio.cpp) that it mentions is as follows:

handle_output_record("nind", nind);
handle_output_record("lm_ind", lm_ind);
handle_output_record("rm_ind", sm_ind);
handle_output_record("sm_ind", hm_ind);
handle_output_record("hm_ind", rm_ind);
handle_output_record("vegc", vegc);
handle_output_record("fpc_grid", fpc_grid);
handle_output_record("anpp", anpp);
handle_output_record("acflux_estab", acflux_estab);
handle_output_record("litter_ag", litter_ag);
handle_output_record("litter_bg", litter_bg);
handle_output_record("cpool_fast", cpool_fast);
handle_output_record("cpool_slow", cpool_slow);
handle_output_record("arh", arh);
handle_output_record("afire_frac", afire_frac);
handle_output_record("acflux_fire", acflux_fire);
#ifdef KIRSTEN_LPJ
handle_output_record("mcflux_fire", mcflux_fire);
#endif
handle_output_record("arunoff", arunoff);
handle_output_record("sla", sla);
handle_output_record("mpar", mpar);
handle_output_record("mapar", mapar);
handle_output_record("xmphen", xmphen);
handle_output_record("anpp_add", anpp_add);
handle_output_record("mnpp", mnpp);
handle_output_record("mrunoff", mrunoff);
handle_output_record("aaet", aaet);
handle_output_record("mrh", mrh);
handle_output_record("mnpp_add", mnpp_add);
handle_output_record("maet", maet);
handle_output_record("xmgpp", xmgpp);
handle_output_record("mtemp_soil", mtemp_soil);
handle_output_record("xmcica", xmcica);
handle_output_record("xmlresp", xmlresp);
handle_output_record("xmsresp", xmsresp);
handle_output_record("xmrresp", xmrresp);
handle_output_record("xmgresp", xmgresp);
handle_output_record("xmaresp", xmaresp);
#ifdef KIRSTEN_LPJ
handle_output_record("mauw1", mauw1);
handle_output_record("mauw2", mauw2);
#else
handle_output_record("mw1", mw1);
handle_output_record("mw2", mw2);
#endif
handle_output_record("maep", maep);
handle_output_record("aaep", aaep);
#ifdef KIRSTEN_LPJ
handle_output_record("mpet_grid", mpet_grid);
handle_output_record("apet_grid", apet_grid);
#endif
handle_output_record("mintc", mintc);
handle_output_record("aintc", aintc);
#ifdef KIRSTEN_LPJ
handle_output_record("xmeangc", xmeangc);
handle_output_record("xmgp", xmgp);
handle_output_record("num_fire", num_fire);
handle_output_record("annum_fire", annum_fire);
handle_output_record("area_burnt", area_burnt);
handle_output_record("an_areafires", an_areafires);
handle_output_record("mfdi", mfdi);
handle_output_record("an_fdi", an_fdi);
handle_output_record("an_fseason", an_fseason);
handle_output_record("acflux_trace", acflux_trace);
handle_output_record("xmcflux_trace", xmcflux_trace);
handle_output_record("m_fc_crown", m_fc_crown);
handle_output_record("an_fc_crown", an_fc_crown);
handle_output_record("m_i_surface", m_i_surface);
handle_output_record("an_i_surface", an_i_surface);
#endif
handle_output_record("gdd", gdd);
handle_output_record("height", height);
handle_output_record("mgpp", mgpp);
handle_output_record("wu", wu);
handle_output_record("wl", wl);
handle_output_record("dphen", dphen);
handle_output_record("lresp", lresp);
handle_output_record("sresp", sresp);
handle_output_record("rresp", rresp);
handle_output_record("gresp", gresp);
handle_output_record("fbare", fbare);
handle_output_record("mpet", mpet);
handle_output_record("arunoff_drain", arunoff_drain);
handle_output_record("arunoff_surf", arunoff_surf);
handle_output_record("mrunoff_drain", mrunoff_drain);
handle_output_record("mrunoff_surf", mrunoff_surf);
handle_output_record("apet", apet);
handle_output_record("mprecip", mprecip);
handle_output_record("aprec", aprec);
handle_output_record("lai_ind", lai_ind);
handle_output_record("total_anpp", &total_anpp);



Am I overlooking something simple?! Or is this likely to be a complex task to solve?

Either way, I'd be grateful for any help or advice offered. Any further details required, please let me know and I'll try my best to provide them.

Many thanks,

Steve



pstoehr
Feb 26, 2009, 06:59 AM
Hi Steve,

maybe the missing ";" after the definitions of outannual_ cause the error.

Best regards
Peter

smurray444
Feb 26, 2009, 07:57 AM
Thanks Peter,

That seems to have solved that one. What I did was to insert a ';' at the very end of the definitions like so:

float *gresp,
float *mpet, float *arunoff_drain,
float *arunoff_surf, float *mrunoff_drain,
float *mrunoff_surf, float *apet, float *mprecip, float *aprec, float *lai_ind, float *total_anpp);
#endif
{


However, I now receive the following message instead, when I try to make:

g++ -I/sw/include -I/LPX/utils -c -o lpjio.o lpjio.cpp
lpjio.cpp:1069: error: expected unqualified-id before ‘{’ token
make: *** [lpjio.o] Error 1

I believe the '{' may be referring to the one shown in the code example above. It denotes the start of a new 'if' command.

It may already be somewhat obvious that I'm far from a competent C++ coder (!), but again, any pointers which might help eliminate this error would be most welcome.

Thanks again for any help.

Steve

bbarnhart
Feb 26, 2009, 08:18 AM
Is the pre-processor really necessary? The #if ... #else ... #endif stuff? You also might consider putting all those parameters into a struct or class and passing a pointer or reference to the struct or class instead. It might create more typing but it would be more simpler to understand.

smurray444
Feb 26, 2009, 08:29 AM
If I was capable (or even aware!) of such an approach, then maybe I'd consider it - but I'm really nowhere near up to that standard! This code wasn't written by me; I'm merely changing the variables in it to get a model to hopefully output the data I require.

Again, if anyone has any solutions to the 'expected unqualified-id before ‘{’ token' error, then I'd be very glad to hear them.

Many thanks again,

Steve

iSee
Feb 26, 2009, 08:57 AM
Yikes, that code is pretty whacky.
As a general tip as you learn C++, try not to pick up any programming tips from that code.

I'm guessing that you need to take the ; back out.
(The original snippet made it looks like a function declaration which should be terminated with a semicolon as pstoehr suggested.

But the later snippet make me think it is a function definition so you don't want the semicolon there.

That brings us back to the original problem.
The orininal error mentions calls to handle_output_record(...) at lines 1168 and 1178. Which calls are those? That's where to start looking for the problem.

At line 1168, the compiler is expecting a pointer to float -- that is float* in C++ terms -- for the second parameter. But a float is being passed. That might be easy to fix. If the line was handle_output_record("abc", someFloatVar); you can change it to handle_output_record("abc", &someFloatVar); to convert the second parameter from a float to a pointer to float. Though, while that might make the compiler error go away, I have no way of telling if that is the right thing to do in terms of making your program function correctly.

Similarily, at line 1178, again the compiler is expecting a pointer to float as the second parameter to handle_output_record(...). But it is getting a pointer to a pointer to float -- float** in C++ syntax. If the code looke like this: handle_output_record("abc", somePointerToPointerToFloatVar); you should be able to this: handle_output_record("abc", *somePointerToPointerToFloatVar); to get it to compiler. Again, though, that may not make the program function as intended.

smurray444
Feb 26, 2009, 09:29 AM
Thanks iSee - that seems to have worked! Thanks also for the clear instructions.


Having got past this problem, I'm now faced with what looks like something completely different. Feel free to let me know if I should really start a new post for what's coming up.

When I attempt to make, I get this...

gly-pc69:trunk Steve$ make
g++ -I/sw/include -I/LPX/utils -c -o lpjio.o lpjio.cpp
g++ -I/sw/include -fbounds-check -L/sw/lib -L/usr/local/lib/gcc/i686-apple-darwin8.8.1/3.4.0 -o lpj-gerten lpjmain2.o lpjio.o /LPX/utils/Array.o -lnetcdf_c++ -lnetcdf -lstdc++ -lfrtbegin -lg2c
Undefined symbols:
"__gfortran_transfer_integer", referenced from:
_MAIN__ in lpjmain2.o
_MAIN__ in lpjmain2.o
"__gfortran_stop_string", referenced from:
_soilparameters_ in lpjmain2.o
"__gfortran_transfer_character", referenced from:
_MAIN__ in lpjmain2.o
_MAIN__ in lpjmain2.o
"__gfortran_st_write_done", referenced from:
_MAIN__ in lpjmain2.o
"__gfortran_set_options", referenced from:
_MAIN__ in lpjmain2.o
"__gfortran_runtime_error_at", referenced from:
_MAIN__ in lpjmain2.o
_MAIN__ in lpjmain2.o
_MAIN__ in lpjmain2.o
_MAIN__ in lpjmain2.o
_MAIN__ in lpjmain2.o

...which continues, listing this and many of the subroutines (in place of 'MAIN' numerous times), until it gets to...

_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
_establishment_ in lpjmain2.o
"__gfortran_st_write", referenced from:
_MAIN__ in lpjmain2.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [lpj-gerten] Error 1


Again, this is well beyond me! I'm guessing that undefined symbols would imply that something hasn't been declared, but as it appears to be referring to subroutines (as opposed to undefined variables), I'm struggling to see how I'd overcome this.

As I said at the start of this message, please feel free to let me know if I should start a new thread for this, as I guess it's now gone beyond the scope of the thread title.

Any suggestions as to how I might overcome these errors will again be greatly appreciated.

Thanks again,

Steve

gnasher729
Feb 26, 2009, 09:43 AM
Go to line 1168 in your source code. Check the call there. Especially check the second argument. The compiler tells you that the second argument in that function call should be of type float*, but it is actually of type float. Find out why and fix it.

Go to line 1178 in your source code. Check the call there. Especially check the second argument. The compiler tells you that the second argument in that function call should be of type float*, but it is actually of type float**. Find out why and fix it.

Your second problem looks like you are using a tool that converts fortran into C and requires a library that contains all these functions that are missing.

smurray444
Feb 26, 2009, 10:00 AM
Thanks - I managed to fix the problem of the float conversions using the tips previously suggested (and yours looks like it would also have worked).

With regard to your thought of a missing library, do you have any ideas what might be missing, or what I could install to counter this problem?

If it's of any use, I'm using netcdf, gfortran as my Fortran compiler and gcc as my C compiler.

Thanks again,

Steve

lee1210
Feb 26, 2009, 10:22 AM
It looks like perhaps when you are compiling with the C++ compiler, but calling into fortran, you are not linking in the gfortran libraries. I haven't used gfortran, so i'm not sure what it's libraries are called, etc.

-Lee

smurray444
Feb 26, 2009, 10:33 AM
Do you suggest therefore that I should try reinstalling my C++ compiler?

Just to clarify though, I'm not compiling the code directly with the C++ compiler, I'm merely typing 'make', I guess this might cause the compiler to become active though...

Any suggestions on how to proceed would be most welcome!

Thanks again,

Steve

iSee
Feb 26, 2009, 11:37 AM
Do you suggest therefore that I should try reinstalling my C++ compiler?

Just to clarify though, I'm not compiling the code directly with the C++ compiler, I'm merely typing 'make', I guess this might cause the compiler to become active though...

Any suggestions on how to proceed would be most welcome!

Thanks again,

Steve

I think the fundemental problem here is that there are errors in the C++ souce code and the make file for this project and that you are in the position of trying to debug them even though you don't know much about C++ programming. You can probably keep fixing the error messages and problems that arise for a long time and still not end up with a program that will work as intended.

I wonder if there is a way you can avoid trying to debug this project? Unless you just want the challenge, it seems futile to me for you to debug this project.

For example, did this project compile correctly in the past? If so, can you identify what has changed since then and undo that?

For example, are you sure you're starting with the latest-and-greatest, known good source code for this project? Maybe it used to be compiled in a different environment (different version of the tools, or libraries, etc.) Maybe you can get your hands on the last computer used to successfully compile the project and try it there.