cocos2d-x, protobuf, no config.h, #error "No suitable threading library available."

前端之家收集整理的这篇文章主要介绍了cocos2d-x, protobuf, no config.h, #error "No suitable threading library available."前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在用cocos2d-x3.2 + protobuf编译Android项目的时候,protobuf出现了两个问题:

1. 首先是config.h找不到,查阅自后说是通过命令或工具生成的,里面的内容根据不同平台是不一样的(引用一些用到的库,例如hash_map,hash_set等,和部分宏定义),那么就要在自己手动生成,或者自己创建一个空的config,自己把一些引用到的库加进去,为了能快速编译通过,我就自己创建了一个config.h,没有引用任何库。

  1. #ifndef _LINUX_CONFIG_H
  2. #define _LINUX_CONFIG_H
  3.  
  4. #endif

然后找不到config.h的问题解决了。

2.然后是error "No suitable threading library available."

定位到common.cc文件

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN // We only need minimal includes
#include <windows.h>
#define snprintf _snprintf // see comment in strutil.cc
#elif defined(HAVE_PTHREAD)
#include <pthread.h>
#else
#error "No suitable threading library available."
#endif

发现是找不到HAVE_PTHREAD宏定义,导致没有引用pthread库,直接用#include <pthread.h>替换#error "No suitable threading library available."这句代码,又会导致其他文件找不到;那么可能其它地方也引用了HAVE_PTHREAD宏,那这个宏是protobuf库根据不同平台定义的呢,还是该我们自己加呢,如果是自己加又应该加在哪里呢?

联想到config文件找不到的问题,猜到可能是config文件中缺少一些代码,看来不能用空的config,那么就直接在config.h中加上#define HAVE_PTHREAD即可。

  1. #ifndef _LINUX_CONFIG_H
  2. #define _LINUX_CONFIG_H
  3.  
  4. #define HAVE_PTHREAD
  5.  
  6. #endif

之后编译通过。。。

如果是有完美强迫症的、或者要求高效率(使用hash_map/unordered_map等),那么就在linux上用configure生成一个config.h吧,下面附上一个完整生成的:

  1. /* config.h. Generated from config.h.in by configure. */
  2. /* config.h.in. Generated from configure.ac by autoheader. */
  3.  
  4. /* the name of <hash_map> */
  5. #define HASH_MAP_CLASS hash_map
  6.  
  7. /* the location of <unordered_map> or <hash_map> */
  8. #define HASH_MAP_H <ext/hash_map>
  9.  
  10. /* the namespace of hash_map/hash_set */
  11. #define HASH_NAMESPACE std::tr1
  12.  
  13. /* the name of <hash_set> */
  14. #define HASH_SET_CLASS hash_set
  15.  
  16. /* the location of <unordered_set> or <hash_set> */
  17. #define HASH_SET_H <ext/hash_set>
  18.  
  19. /* Define to 1 if you have the <dlfcn.h> header file. */
  20. #define HAVE_DLFCN_H 1
  21.  
  22. /* Define to 1 if you have the <fcntl.h> header file. */
  23. #define HAVE_FCNTL_H 1
  24.  
  25. /* Define to 1 if you have the `ftruncate' function. */
  26. #define HAVE_FTRUNCATE 1
  27.  
  28. /* define if the compiler has hash_map */
  29. #define HAVE_HASH_MAP 1
  30.  
  31. /* define if the compiler has hash_set */
  32. #define HAVE_HASH_SET 1
  33.  
  34. /* Define to 1 if you have the <inttypes.h> header file. */
  35. #define HAVE_INTTYPES_H 1
  36.  
  37. /* Define to 1 if you have the <limits.h> header file. */
  38. #define HAVE_LIMITS_H 1
  39.  
  40. /* Define to 1 if you have the <memory.h> header file. */
  41. #define HAVE_MEMORY_H 1
  42.  
  43. /* Define to 1 if you have the `memset' function. */
  44. #define HAVE_MEMSET 1
  45.  
  46. /* Define to 1 if you have the `mkdir' function. */
  47. #define HAVE_MKDIR 1
  48.  
  49. /* Define if you have POSIX threads libraries and header files. */
  50. #define HAVE_PTHREAD 1
  51.  
  52. /* Define to 1 if you have the <stdint.h> header file. */
  53. #define HAVE_STDINT_H 1
  54.  
  55. /* Define to 1 if you have the <stdlib.h> header file. */
  56. #define HAVE_STDLIB_H 1
  57.  
  58. /* Define to 1 if you have the `strchr' function. */
  59. #define HAVE_STRCHR 1
  60.  
  61. /* Define to 1 if you have the `strerror' function. */
  62. #define HAVE_STRERROR 1
  63.  
  64. /* Define to 1 if you have the <strings.h> header file. */
  65. #define HAVE_STRINGS_H 1
  66.  
  67. /* Define to 1 if you have the <string.h> header file. */
  68. #define HAVE_STRING_H 1
  69.  
  70. /* Define to 1 if you have the `strtol' function. */
  71. #define HAVE_STRTOL 1
  72.  
  73. /* Define to 1 if you have the <sys/stat.h> header file. */
  74. #define HAVE_SYS_STAT_H 1
  75.  
  76. /* Define to 1 if you have the <sys/types.h> header file. */
  77. #define HAVE_SYS_TYPES_H 1
  78.  
  79. /* Define to 1 if you have the <unistd.h> header file. */
  80. #define HAVE_UNISTD_H 1
  81.  
  82. /* Enable classes using zlib compression. */
  83. /* #undef HAVE_ZLIB */
  84.  
  85. /* Define to the sub-directory in which libtool stores uninstalled libraries.
  86. */
  87. #define LT_OBJDIR ".libs/"
  88.  
  89. /* Name of package */
  90. #define PACKAGE "protobuf"
  91.  
  92. /* Define to the address where bug reports for this package should be sent. */
  93. #define PACKAGE_BUGREPORT "protobuf@googlegroups.com"
  94.  
  95. /* Define to the full name of this package. */
  96. #define PACKAGE_NAME "Protocol Buffers"
  97.  
  98. /* Define to the full name and version of this package. */
  99. #define PACKAGE_STRING "Protocol Buffers 2.5.0"
  100.  
  101. /* Define to the one symbol short name of this package. */
  102. #define PACKAGE_TARNAME "protobuf"
  103.  
  104. /* Define to the home page for this package. */
  105. #define PACKAGE_URL ""
  106.  
  107. /* Define to the version of this package. */
  108. #define PACKAGE_VERSION "2.5.0"
  109.  
  110. /* Define to necessary symbol if this constant uses a non-standard name on
  111. your system. */
  112. /* #undef PTHREAD_CREATE_JOINABLE */
  113.  
  114. /* Define to 1 if you have the ANSI C header files. */
  115. #define STDC_HEADERS 1
  116.  
  117. /* Enable extensions on AIX 3,Interix. */
  118. #ifndef _ALL_SOURCE
  119. # define _ALL_SOURCE 1
  120. #endif
  121. /* Enable GNU extensions on systems that have them. */
  122. #ifndef _GNU_SOURCE
  123. # define _GNU_SOURCE 1
  124. #endif
  125. /* Enable threading extensions on Solaris. */
  126. #ifndef _POSIX_PTHREAD_SEMANTICS
  127. # define _POSIX_PTHREAD_SEMANTICS 1
  128. #endif
  129. /* Enable extensions on HP NonStop. */
  130. #ifndef _TANDEM_SOURCE
  131. # define _TANDEM_SOURCE 1
  132. #endif
  133. /* Enable general extensions on Solaris. */
  134. #ifndef __EXTENSIONS__
  135. # define __EXTENSIONS__ 1
  136. #endif
  137.  
  138.  
  139. /* Version number of package */
  140. #define VERSION "2.5.0"
  141.  
  142. /* Define to 1 if on MINIX. */
  143. /* #undef _MINIX */
  144.  
  145. /* Define to 2 if the system does not provide POSIX.1 features except with
  146. this defined. */
  147. /* #undef _POSIX_1_SOURCE */
  148.  
  149. /* Define to 1 if you need to in order for `stat' and other things to work. */
  150. /* #undef _POSIX_SOURCE */

猜你在找的Cocos2d-x相关文章