YafaRay / libYafaRay

libYafaRay is a free open-source montecarlo raytracing engine released under the LGPL 2.1 license. Raytracing is a rendering technique for generating realistic images by tracing the path of light through a 3D scene.
http://www.yafaray.org
61 stars 8 forks source link

make error: ‘size_t’ does not name a type #10

Closed sylsau closed 2 years ago

sylsau commented 2 years ago

Hello !

Thank you for the amazing work you do!

I ran into some error while compiling on Linux.

$ cmake CMakeLists.txt
# goes fine
$ make
[  1%] Building CXX object src/CMakeFiles/libyafaray4.dir/color/color_layers.cc.o
In file included from /home/user/Downloads/YafaRay/libYafaRay/include/common/layers.h:25,
                 from /home/user/Downloads/YafaRay/libYafaRay/include/color/color_layers.h:24,
                 from /home/user/Downloads/YafaRay/libYafaRay/src/color/color_layers.cc:19:
/home/user/Downloads/YafaRay/libYafaRay/include/common/collection.h:34:17: error: ‘size_t’ does not name a type
   34 |                 size_t size() const { return items_.size(); }
      |                 ^~~~~~
/home/user/Downloads/YafaRay/libYafaRay/include/common/collection.h:27:1: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
   26 | #include <map>
  +++ |+#include <cstddef>
   27 | 
make[2]: *** [src/CMakeFiles/libyafaray4.dir/build.make:244: src/CMakeFiles/libyafaray4.dir/color/color_layers.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:694: src/CMakeFiles/libyafaray4.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Here are my installed packages :

$ pacman -Q | grep "gcc\|opencv\|zlib\|freetype\|tiff\|jpeg\|libpng\|ilmbase\|openexr"
freetype2 2.11.1-1
gcc 11.2.0-4
gcc-libs 11.2.0-4
gcc-objc 11.2.0-4
jpegoptim 1.4.6-2
lib32-freetype2 2.11.1-1
lib32-gcc-libs 11.2.0-4
lib32-libjpeg-turbo 2.1.3-1
lib32-libpng 1.6.37-3
lib32-libpng12 1.2.59-2
lib32-libtiff 4.3.0-1
lib32-zlib 1.2.11-3
libjpeg-turbo 2.1.3-1
libpng 1.6.37-3
libpng12 1.2.59-2
libtiff 4.3.0-1
opencv 4.5.5-3
openexr 3.1.4-1
openjpeg 1.5.2-3
openjpeg2 2.4.0-1
zlib 1:1.2.11-5

Hopefully I was able to solve the problem following the compiler's advice.

I am opening this issue in case someone else gets the same problem.

sylsau commented 2 years ago

I simply added this include line to include/common/yafaray_common.h :

#include <cstddef>

As such :

#ifndef YAFARAY_COMMON_H
#define YAFARAY_COMMON_H

#define BEGIN_YAFARAY namespace yafaray {
#define END_YAFARAY }

#include <cstddef>

static constexpr float min_raydist_global = 0.00005f;
static constexpr float shadow_bias_global = 0.0005f;

#endif // YAFARAY_COMMON_H

It then proceeded to compile without any issue.

It's probably not the "safest" way to include another header but I do not know how cmake works so that's what I did. Hope it helps someone.

Thank you.

DavidBluecame commented 2 years ago

Hello.

Thank you very much for your bug report, all the information provided and the suggested solution. I've added a commit including cstddef in the common header as you suggested.

This seems to be a new behavior in gcc-11, as you said it's perhaps overkill to add that header to the common YafaRay header but considering size_t is such a widespread data type, I think it's reasonable for now.

Thanks again for your input!

By the way, keep in mind that the v4 C API is still subject to major changes I plan to do soon, that's one of the reasons why v4 is still considered unstable/experimental at the moment.