ntamas / plfit

Fitting power-law distributions to empirical data, according to the method of Clauset, Shalizi and Newman
GNU General Public License v2.0
48 stars 17 forks source link

include problem in headers #39

Closed Apteryks closed 2 years ago

Apteryks commented 2 years ago

Hello!

Attempting to build igraph with the latest released plfit; I noticed the following problem:

/gnu/store/k0f3gjpbqc59cvqlnhbyviq0zxl6q8m7-plfit-0.9.2/include/plfit/plfit.h:25:10: fatal error: plfit_mt.h: No such file or directory
   25 | #include <plfit_mt.h>
      |          ^~~~~~~~~~~~
compilation terminated.

I've patched igraph CMake to support using plfit from the system by making use of the pkg-config file shipped by plfit. This config file defines the include directory via:

$ pkg-config --cflags-only-I /gnu/store/2g4fi4v0fkfzlifrmljcazhsbqgq5fkl-profile/lib/pkgconfig/libplfit.pc
-I/gnu/store/k0f3gjpbqc59cvqlnhbyviq0zxl6q8m7-plfit-0.9.2/include

It should be augmented to look into the 'plfit' subdirectory (i.e.: /gnu/store/k0f3gjpbqc59cvqlnhbyviq0zxl6q8m7-plfit-0.9.2/include/plfit) or alternatively the headers need to refer to this subdirectory explicitly.

Does it make sense?

Thanks!

Apteryks commented 2 years ago

So, one solution that would allow (pkg-config) users to either prefix their includes with plfit/ or without would be this:

modified   libplfit.pc.in
@@ -9,4 +9,4 @@ Version: @PROJECT_VERSION@
 URL: @PROJECT_HOMEPAGE_URL@
 Libs: -L${libdir} -lplfit
 Libs.private: @PKGCONFIG_LIBS_PRIVATE@
-Cflags: -I${includedir}
+Cflags: -I${includedir} -I${includedir}/plfit
Apteryks commented 2 years ago

Hmm, the above didn't work for some reason. But I found a better fix: the plfit_ #include directives should be double quoted instead of between < >s so that the compiler looks them in the same directory they're in (see: https://stackoverflow.com/questions/3162030/difference-between-angle-bracket-and-double-quotes-while-including-heade).

After patching locally, the headers look like:

$ grep -rin '#include' /gnu/store/wy5lbq7m6pcyy3c91ihj5grqx4cphw38-plfit-0.9.2

/gnu/store/wy5lbq7m6pcyy3c91ihj5grqx4cphw38-plfit-0.9.2/include/plfit/plfit.h:24:#include <stdlib.h>
/gnu/store/wy5lbq7m6pcyy3c91ihj5grqx4cphw38-plfit-0.9.2/include/plfit/plfit.h:25:#include "plfit_mt.h"
/gnu/store/wy5lbq7m6pcyy3c91ihj5grqx4cphw38-plfit-0.9.2/include/plfit/plfit.h:26:#include "plfit_version.h"
/gnu/store/wy5lbq7m6pcyy3c91ihj5grqx4cphw38-plfit-0.9.2/include/plfit/plfit_sampling.h:23:#include <stdlib.h>
/gnu/store/wy5lbq7m6pcyy3c91ihj5grqx4cphw38-plfit-0.9.2/include/plfit/plfit_sampling.h:24:#include "plfit_mt.h"

And the problem is gone (GCC 10.3.0).

ntamas commented 2 years ago

Ah yes, this is a bit of a mess now. plfit used to put all its header files in /usr/include until recently, and it looks like things broke when I switched that to /usr/include/plfit instead. I've committed a patch that I think should work but I haven't had time to test it. If you test it, let me know, otherwise I'll test it in a few days and tag it as 0.9.3.

ntamas commented 2 years ago

Fixed in 0.9.3