cglm icon indicating copy to clipboard operation
cglm copied to clipboard

Compiling on the Raspberry PI

Open acoto87 opened this issue 6 years ago • 3 comments

Hi there,

I was trying to compile cglm on my Raspberry PI, and after installing autotools and libtool I proceed to make.

When I make the project it throw at first the following error:

src/../include/cglm/mat4.h:173:48: error: unknown type name ‘size_t’
 glm_mat4_identity_array(mat4 * __restrict mat, size_t count) {
                                                ^~~~~~

I failed to find where do the compiler was trying to grab the header file with that definition (size_t is defined in multiple standard headers) and since I see that common.h is only including:

#include <stdint.h>
#include <math.h>
#include <float.h>

in neither of those files has the declaration for size_t in this platform. So, another header where that type is declared is in stddef.h so I include it, and the error is gone. Specifically, this file was included: /usr/lib/gcc/arm-linux-gnueabihf/6/include/stddef.h.

So, have you think about this issue, that maybe in other platforms other headers need to be included to compile the project?

After that when I do make I got the following warnings (there are similar others):

In file included from src/../include/cglm/cglm.h:19:0,
                 from src/quat.c:8:
src/quat.c: In function ‘glmc_quat_rotatev’:
src/../include/cglm/quat.h:749:3: warning: ‘*((void *)&p+12)’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   glm_vec3_scale(v2, 2.0f * s, v2);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/../include/cglm/quat.h:736:25: note: ‘*((void *)&p+12)’ was declared here
   CGLM_ALIGN(16) versor p;
                         ^

the *((void *)&p+12) comes from the s = glm_quat_real(p); line in the glm_quat_rotatev function that was inlined by the compiler. So, have you see these kind of warnings?

I'm missing something and need to do something else to compile without warnings/errors?

My compiler version:

gcc (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Let me know if you need me to make more tests.

acoto87 avatar Mar 28 '19 01:03 acoto87

Since we did not include headers which include stddef.h, we should include stddef.h directly in common.h. You are welcome to create a PR for this, otherwise I can add it later.

I do not get any warnings. I saw -Wmaybe-uninitialized flag in your compiler warnings, I'll test build after add -Wmaybe-uninitialized flag asap.

recp avatar Mar 28 '19 07:03 recp

You are welcome to create a PR for this, otherwise I can add it later.

Sure, I can make a PR for this. But I'm wondering, from which header are you getting the size_t definition?

acoto87 avatar Mar 28 '19 15:03 acoto87

stddef.h should comes from a header, on the other hand cglm/io.h includes both #include <stdio.h> and #include <stdlib.h> headers and both these headers include stddef.h header, maybe it comes from these headers. But the weird thing is that I removed io.h and it compiled successfully. Maybe it comes from SIMD headers. Or compiler may included stddef.h implicitly I'm not sure yet.

We must include stddef.h in common.h header to make it more robust.


I got no warnings:

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
  CC       src/euler.lo
  CC       src/affine.lo
  CC       src/io.lo
  CC       src/quat.lo
  CC       src/cam.lo
  CC       src/vec3.lo
  CC       src/vec4.lo
  CC       src/mat3.lo
  CC       src/mat4.lo
  CC       src/plane.lo
  CC       src/frustum.lo
  CC       src/box.lo
  CC       src/project.lo
  CC       src/sphere.lo
  CC       src/ease.lo
  CC       src/curve.lo
  CC       src/bezier.lo
  CCLD     libcglm.la
sh ./post-build.sh

also it seems -Wmaybe-uninitialized is not defined for clang, I'll try it on GCC/Linux later.

recp avatar Mar 28 '19 20:03 recp