1

I have a makefile for use with some programs using the zkcm-library, including the following object line:

zkcm_c.o: zkcm_c.cpp zkcm_c.h config.h
     g++ -c zkcm_c.cpp -lgmp -lgmpxx -lmpfr

The compiler complains that there is an "undefined reference to '_imp_mpfr__inits2' " and the same for every use of mpfr-functions. The strange thing is, there are other objects in the makefile that uses mpfr-functions with no problem, e.g. the main program (first line):

SpMC: SpMC.cpp MCutility.h HPutility.h wfs.h MC_funcs.h $(ZKCMOBJECTS)  $(ZKCMHFILES)
     g++ SpMC.cpp -lgmp -lmpfr -lmpc -o SpMC $(ZKCMOBJECTS)

In both cases I have #include<mpfr.h> in the source and as you see link to it using -lmpfr. Any ideas why this works for SpMC.cpp but not zkcm_c.cpp?

whoan
  • 8,143
  • 4
  • 39
  • 48
jorgen
  • 3,425
  • 4
  • 31
  • 53
  • 1
    Seems that somehow mfpr functions got declared as `__declspec(dllimport)` in this particular case. `__imp_` stuff is in the import libraries. – Anton Kovalenko Jan 26 '13 at 17:33
  • 1
    I'd recommend to find `mpfr_inits` prototype in preprocessed output (`g++ -E SpMC.cpp`) and see whether it has __declspec. (I've looked into the header, it relies on `__GMP_DECLSPEC` which depends on `__GMP_LIBGMP_DLL` -- somehow it got defined.) – Anton Kovalenko Jan 26 '13 at 18:21
  • Thanks for helping out! But I'm still confused.. Do you mean you looked into zkcm_c.h or mpfr.h? In the former I can't find anything like this; in the latter there is " #if defined(__MPFR_WITHIN_MPFR) && __GMP_LIBGMP_DLL # define __MPFR_DECLSPEC __GMP_DECLSPEC_EXPORT #else # define __MPFR_DECLSPEC __GMP_DECLSPEC #endif" should I change this somehow? It works with the other programs.. – jorgen Jan 26 '13 at 18:48
  • I meant `mpfr.h`. No idea what exactly you shoud change yet, but start with `g++ -E` output. Find mpfr_inits declaration. Does it have `__declspec`? – Anton Kovalenko Jan 26 '13 at 18:50
  • Using g++ -E I get a file SpMC containing "__attribute__((__dllimport__)) void mpfr_inits (mpfr_ptr, ...) __attribute__ ((sentinel));" there is no declspec. But SpMC.cpp is the file that is working, should I try the same with the problem file zkcm.c_cpp maybe? – jorgen Jan 26 '13 at 18:56
  • Yeah, that's it. hm.. Try commenting out two lines starting with `# define __MPFR_DECLSPEC` in `mpfr.h`. – Anton Kovalenko Jan 26 '13 at 19:01
  • Hm, interesting. If I remove the line # define __MPFR_DECLSPEC __GMP_DECLSPEC_EXPORT I still get the errors I've described, if I remove # define __MPFR_DECLSPEC __GMP_DECLSPEC (or both lines) I don't get the mentioned errors but a bunch of new ones in mpfr.h and other files where I've used the mpfr library – jorgen Jan 26 '13 at 19:08

0 Answers0