System environment

CentOS Linux release 7.6.1810 (Core)
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
Python-3.7.2
uuid-devel.x86_64 1.6.2-26.el7

Scene

Description

Compile install Python 3.7.2 on Centos7 with error blow

building '_uuid' extension
gcc -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -I./Include -I/home/tt/py37/include -I. -I/usr/local/include -I/home/tt/Python-3.7.2/Include -I/home/tt/Python-3.7.2 -c /home/tt/Python-3.7.2/Modules/_uuidmodule.c -o build/temp.linux-x86_64-3.7/home/tt/Python-3.7.2/Modules/_uuidmodule.o
In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:8:0:
/usr/include/uuid.h:94:24: error: conflicting types for ‘uuid_t’
 typedef struct uuid_st uuid_t;
                        ^
In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:5:0:
/usr/include/uuid/uuid.h:44:23: note: previous declaration of ‘uuid_t’ was here
 typedef unsigned char uuid_t[16];
                       ^
In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:8:0:
/usr/include/uuid.h:107:22: error: conflicting types for ‘uuid_compare’
 extern uuid_rc_t     uuid_compare  (const uuid_t  *_uuid, const uuid_t *_uuid2, int *_result);
                      ^
In file included from /home/tt/Python-3.7.2/Modules/_uuidmodule.c:5:0:
/usr/include/uuid/uuid.h:73:5: note: previous declaration of ‘uuid_compare’ was here
 int uuid_compare(const uuid_t uu1, const uuid_t uu2);
     ^
/home/tt/Python-3.7.2/Modules/_uuidmodule.c: In function ‘py_uuid_generate_time_safe’:
/home/tt/Python-3.7.2/Modules/_uuidmodule.c:15:12: error: storage size of ‘uuid’ isn’t known
     uuid_t uuid;
            ^
/home/tt/Python-3.7.2/Modules/_uuidmodule.c:15:12: warning: unused variable ‘uuid’ [-Wunused-variable]
/home/tt/Python-3.7.2/Modules/_uuidmodule.c:35:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd                
time                                                           


Failed to build these modules:
_uuid

Analyse

According error message, compiler read two different head file uuid.h, but variable uuid_t uuid_compare in both files have different type, causes (conflicting types) and compile failed.

Enter /usr/include, there are two head file uuid.h uuid/uuid.h. Just remove one to fix this.

  • /usr/include/uuid.h provided by uuid-devel
  • /usr/include/uuid/uuid.h provided by libuuid-devel

Resolve

Change source code in Modules/_uuidmodule.c

vi Modules/_uuidmodule.c

Delete line 6 and change line 7 as blow

#elif defined(HAVE_UUID_H)

or patch this file

--- Modules/_uuidmodule.c.orignal       2019-01-11 15:38:46.995000000 -0500
+++ Modules/_uuidmodule.c       2019-01-11 15:39:04.470000000 -0500
@@ -3,8 +3,7 @@
 #include "Python.h"
 #ifdef HAVE_UUID_UUID_H
 #include <uuid/uuid.h>
-#endif
-#ifdef HAVE_UUID_H
+#elif defined(HAVE_UUID_H)
 #include <uuid.h>
 #endif

Download uuidmodule.patch to Python source code root path and execute

patch -p0 < uuidmodule.patch

All done!