
在用cocos2d-x3.2 + protobuf编译AndroID项目的时候,protobuf出现了两个问题:
1. 首先是config.h找不到,查阅自后说是通过命令或工具生成的,里面的内容根据不同平台是不一样的(引用一些用到的库,例如hash_map,hash_set等,和部分宏定义),那么就要在自己手动生成,或者自己创建一个空的config,自己把一些引用到的库加进去,为了能快速编译通过,我就自己创建了一个config.h,没有引用任何库。
#ifndef _liNUX_CONfig_H#define _liNUX_CONfig_H#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即可。
#ifndef _liNUX_CONfig_H#define _liNUX_CONfig_H#define HAVE_PTHREAD#endif
之后编译通过。。。
如果是有完美强迫症的、或者要求高效率(使用hash_map/unordered_map等),那么就在linux上用configure生成一个config.h吧,下面附上一个完整生成的:
/* config.h. Generated from config.h.in by configure. *//* config.h.in. Generated from configure.ac by autoheader. *//* the name of <hash_map> */#define HASH_MAP_CLASS hash_map/* the location of <unordered_map> or <hash_map> */#define HASH_MAP_H <ext/hash_map>/* the namespace of hash_map/hash_set */#define HASH_nameSPACE std::tr1/* the name of <hash_set> */#define HASH_SET_CLASS hash_set/* the location of <unordered_set> or <hash_set> */#define HASH_SET_H <ext/hash_set>/* define to 1 if you have the <dlfcn.h> header file. */#define HAVE_DLFCN_H 1/* define to 1 if you have the <fcntl.h> header file. */#define HAVE_FCNTL_H 1/* define to 1 if you have the `ftruncate' function. */#define HAVE_FTruncATE 1/* define if the compiler has hash_map */#define HAVE_HASH_MAP 1/* define if the compiler has hash_set */#define HAVE_HASH_SET 1/* define to 1 if you have the <inttypes.h> header file. */#define HAVE_INTTYPES_H 1/* define to 1 if you have the <limits.h> header file. */#define HAVE_liMITS_H 1/* define to 1 if you have the <memory.h> header file. */#define HAVE_MEMORY_H 1/* define to 1 if you have the `memset' function. */#define HAVE_MEMSET 1/* define to 1 if you have the `mkdir' function. */#define HAVE_MKDIR 1/* define if you have POSIX threads librarIEs and header files. */#define HAVE_PTHREAD 1/* define to 1 if you have the <stdint.h> header file. */#define HAVE_STDINT_H 1/* define to 1 if you have the <stdlib.h> header file. */#define HAVE_STDliB_H 1/* define to 1 if you have the `strchr' function. */#define HAVE_STRCHR 1/* define to 1 if you have the `strerror' function. */#define HAVE_STRERROR 1/* define to 1 if you have the <strings.h> header file. */#define HAVE_STRINGS_H 1/* define to 1 if you have the <string.h> header file. */#define HAVE_STRING_H 1/* define to 1 if you have the `strtol' function. */#define HAVE_STRTol 1/* define to 1 if you have the <sys/stat.h> header file. */#define HAVE_SYS_STAT_H 1/* define to 1 if you have the <sys/types.h> header file. */#define HAVE_SYS_TYPES_H 1/* define to 1 if you have the <unistd.h> header file. */#define HAVE_UNISTD_H 1/* Enable classes using zlib compression. *//* #undef HAVE_ZliB *//* define to the sub-directory in which libtool stores uninstalled librarIEs. */#define LT_OBjdiR ".libs/"/* name of package */#define PACKAGE "protobuf"/* define to the address where BUG reports for this package should be sent. */#define PACKAGE_BUGREPORT "protobuf@Googlegroups.com"/* define to the full name of this package. */#define PACKAGE_name "Protocol Buffers"/* define to the full name and version of this package. */#define PACKAGE_STRING "Protocol Buffers 2.5.0"/* define to the one symbol short name of this package. */#define PACKAGE_TARname "protobuf"/* define to the home page for this package. */#define PACKAGE_URL ""/* define to the version of this package. */#define PACKAGE_VERSION "2.5.0"/* define to necessary symbol if this constant uses a non-standard name on your system. *//* #undef PTHREAD_CREATE_JOINABLE *//* define to 1 if you have the ANSI C header files. */#define STDC_headerS 1/* Enable extensions on AIX 3,Interix. */#ifndef _ALL_SOURCE# define _ALL_SOURCE 1#endif/* Enable GNU extensions on systems that have them. */#ifndef _GNU_SOURCE# define _GNU_SOURCE 1#endif/* Enable threading extensions on Solaris. */#ifndef _POSIX_PTHREAD_SEMANTICS# define _POSIX_PTHREAD_SEMANTICS 1#endif/* Enable extensions on HP NonStop. */#ifndef _TANDEM_SOURCE# define _TANDEM_SOURCE 1#endif/* Enable general extensions on Solaris. */#ifndef __EXTENSIONS__# define __EXTENSIONS__ 1#endif/* Version number of package */#define VERSION "2.5.0"/* define to 1 if on MINIX. *//* #undef _MINIX *//* define to 2 if the system does not provIDe POSIX.1 features except with this defined. *//* #undef _POSIX_1_SOURCE *//* define to 1 if you need to in order for `stat' and other things to work. *//* #undef _POSIX_SOURCE */总结
以上是内存溢出为你收集整理的cocos2d-x, protobuf, no config.h, #error "No suitable threading library available."全部内容,希望文章能够帮你解决cocos2d-x, protobuf, no config.h, #error "No suitable threading library available."所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)