lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2013年03月19日

cygwin上编译protobuf遇到No suitable threading library available的解决办法

Filed under: Android — 标签:, , , , — lizongbo @ 09:46

打算在Android的ndk中使用protobuf,参考了网上的说明,结果在cygwin下编译protobuf遇到”No suitable threading library available.”

以下是运行make时的错误信息:

/bin/sh ../libtool –tag=CXX –mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -MT common.lo -MD -MP -MF .deps/common.Tpo -c -o common.lo `test -f ‘google/protobuf/stubs/common.cc’ || echo ‘./’`google/protobuf/stubs/common.cc
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -MT common.lo -MD -MP -MF .deps/common.Tpo -c google/protobuf/stubs/common.cc -DDLL_EXPORT -DPIC -o .libs/common.o
google/protobuf/stubs/common.cc:48:2: error: #error “No suitable threading library available.”
Makefile:1184: recipe for target `common.lo’ failed
make[2]: *** [common.lo] Error 1
make[2]: 离开目录“/cygdrive/d/cpplibs/protobuf-2.5.0/src”
Makefile:568: recipe for target `all-recursive’ failed
make[1]: *** [all-recursive] Error 1
make[1]: 离开目录“/cygdrive/d/cpplibs/protobuf-2.5.0”
Makefile:477: recipe for target `all’ failed
make: *** [all] Error 2

编译的步骤其实非常简单:

网上下载最新的protobuf文件:

http://protobuf.googlecode.com/files/protobuf-2.5.0.zip
来源:http://code.google.com/p/protobuf/

解压到:D:\cpplibs得到:D:\cpplibs\protobuf-2.5.0

然后cygwin下依次运行以下命令:

 

lizongbo@PC_LI ~
$ cd /cygdrive/d/cpplibs/protobuf-2.5.0/
lizongbo@PC_LI /cygdrive/d/cpplibs/protobuf-2.5.0
$ ./configure

lizongbo@PC_LI /cygdrive/d/cpplibs/protobuf-2.5.0
$ make

lizongbo@PC_LI /cygdrive/d/cpplibs/protobuf-2.5.0
$ make check

lizongbo@PC_LI /cygdrive/d/cpplibs/protobuf-2.5.0
$ make install

正常情况下就编译ok了,结果我运行make的是提示如下出错信息:

/bin/sh ../libtool –tag=CXX –mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -MT common.lo -MD -MP -MF .deps/common.Tpo -c -o common.lo `test -f ‘google/protobuf/stubs/common.cc’ || echo ‘./’`google/protobuf/stubs/common.cc
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -MT common.lo -MD -MP -MF .deps/common.Tpo -c google/protobuf/stubs/common.cc -DDLL_EXPORT -DPIC -o .libs/common.o
google/protobuf/stubs/common.cc:48:2: error: #error “No suitable threading library available.”
Makefile:1184: recipe for target `common.lo’ failed
make[2]: *** [common.lo] Error 1
make[2]: 离开目录“/cygdrive/d/cpplibs/protobuf-2.5.0/src”
Makefile:568: recipe for target `all-recursive’ failed
make[1]: *** [all-recursive] Error 1
make[1]: 离开目录“/cygdrive/d/cpplibs/protobuf-2.5.0”
Makefile:477: recipe for target `all’ failed
make: *** [all] Error 2

 

在网上找遍了资料也没找到解决办法,然后查看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

也是是非win32平台且找不到pthread的情况下才出这个问题。

查看运行configure的记录则是:

checking for library containing zlibVersion… -lz
checking for the pthreads library -lpthreads… no
checking whether pthreads work without any flags… no
checking whether pthreads work with -Kthread… no
checking whether pthreads work with -kthread… no
checking for the pthreads library -llthread… no
checking whether pthreads work with -pthread… no
checking whether pthreads work with -pthreads… no
checking whether pthreads work with -mthreads… no
checking for the pthreads library -lpthread… no
checking whether pthreads work with –thread-safe… no
checking whether pthreads work with -mt… no
checking for pthread-config… no

但网上有人说了cygwin是自带pthread库的(

Pthread is included in Cygwin.  参考:http://stackoverflow.com/questions/2087435/some-issues-about-cygwinlinux-in-windows-socket-thread-other-programming-and  )

尝试各种方法之后仍然失败。

晚上在家里用电脑再按上述步骤操作,发现编译ok了。

再次尝试后总结出了原因,是因为我在环境变量里Path中增加了MinGW的bin目录,

在安装cygwin之前刚好先安装了minGW,且配置了以下环境变量:
MINGW_HOME=C:\MinGW
LIBRARY_PATH = %MINGW_HOME%\lib
C_INCLUDE_PATH = %MINGW_HOME%\include
在PATH变量的最后增加 ;%MINGW_HOME%\bin

于是把上面几个环境变量去掉,重新进入cygwin,终于编译ok了。

正常编译情况下运行configure的记录则是:

checking for the pthreads library -lpthreads… no
checking whether pthreads work without any flags… yes
checking for joinable pthread attribute… PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads… no
checking whether to check for GCC pthread/shared inconsistencies… no
checking whether what we have so far is sufficient with -nostdlib… no
checking whether -lpthread saves the day… no
configure: WARNING: Impossible to determine how to use pthreads with shared libr
aries and -nostdlib

 

 

 

D:\cpplibs\protobuf-2.5.0\src\.libs下顺利得到了libprotobuf.a,libprotobuf-lite.a,libprotoc.a等文件。

D:\cygwin\usr\local\include则是protobuf的相应头文件。

 

 

2013年02月22日

Exception in thread “LWJGL Application” com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: OpenGL is not supported by the video driver.的解决办法

Filed under: Android,Java — 标签:, , , — lizongbo @ 11:25

按照网上的教程,下载最新的libgdx库,

解压:libgdx-nightly-latest.zip.然后运行里面的工程生成工具。

D:\Java\libgdx-nightly-latest>java -jar gdx-setup-ui.jar

导入生成的工程,结果运行出错:

Exception in thread “LWJGL Application” com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: OpenGL is not supported by the video driver.
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: OpenGL is not supported by the video driver.
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.createDisplayPixelFormat(LwjglGraphics.java:219)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:181)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:122)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: org.lwjgl.LWJGLException: Pixel format not accelerated
at org.lwjgl.opengl.WindowsPeerInfo.nChoosePixelFormat(Native Method)
at org.lwjgl.opengl.WindowsPeerInfo.choosePixelFormat(WindowsPeerInfo.java:52)
at org.lwjgl.opengl.WindowsDisplay.createWindow(WindowsDisplay.java:229)
at org.lwjgl.opengl.Display.createWindow(Display.java:303)
at org.lwjgl.opengl.Display.create(Display.java:845)
at org.lwjgl.opengl.Display.create(Display.java:754)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.createDisplayPixelFormat(LwjglGraphics.java:216)
… 3 more

遇到这个错误,解决办法很简单,到nvidia官方网站下载对应的opengl驱动即可:

https://developer.nvidia.com/opengl-driver

http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/opengl/4.3/306.63_desktop_win8_winvista_win7_64bit_international.exe

网上相关文章和讨论只说了显卡在十年前就支持Opengl了,却没提示用户该检查一下是否安装了显卡的OpenGL驱动。

参考:  http://code.google.com/p/libgdx/issues/detail?id=882

http://stackoverflow.com/questions/10972688/libgdx-exception-in-thread-lwjgl-application

http://code.google.com/p/libgdx/wiki/ProjectSetup

最新的非稳定包的下载地址:

http://libgdx.badlogicgames.com/nightlies/libgdx-nightly-latest.zip

 

 

2012年01月31日

Android4.0系统浏览器支持window.performance API了

Filed under: Android,JavaScript,Web,前端开发 — 标签:, , — lizongbo @ 22:25

Android4.0系统浏览器支持window.performance API了

window.performance API是HTML5规范的一部分,
window.performance规范的官方文档在:
https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html
目前还是草稿阶段,中文介绍可以参考:
http://www.cnblogs.com/_franky/archive/2011/11/07/2238980.html
webkit的测试用例和属性列表可以参考:
http://svn.webkit.org/repository/webkit/trunk/LayoutTests/fast//dom/Window/window-properties-performance.html
http://svn.webkit.org/repository/webkit/trunk/LayoutTests/fast//dom/Window/window-properties-performance-expected.txt

Android4.0系统自带的浏览器实现了这一规范,并且还扩展实现window.performance.memory。

通过JavaScript实际测试结果如下:
window.performance.memory=[object MemoryInfo]
window.performance.timing=[object PerformanceTiming]
window.performance.navigation=[object PerformanceNavigation]
window.performance.timing.connectStart=1328016452403
window.performance.timing.responseStart=1328016452403
window.performance.timing.domLoading=1328016453857
window.performance.timing.connectEnd=1328016452403
window.performance.timing.domInteractive=0
window.performance.timing.fetchStart=1328016452403
window.performance.timing.secureConnectionStart=0
window.performance.timing.domainLookupStart=1328016452403
window.performance.timing.responseEnd=0
window.performance.timing.requestStart=1328016452403
window.performance.timing.loadEventEnd=0
window.performance.timing.domComplete=0
window.performance.timing.redirectStart=0
window.performance.timing.unloadEventEnd=1328016453646
window.performance.timing.domContentLoadedEventStart=0
window.performance.timing.domContentLoadedEventEnd=0
window.performance.timing.domainLookupEnd=1328016452403
window.performance.timing.navigationStart=1328016452402
window.performance.timing.unloadEventStart=1328016453646
window.performance.timing.loadEventStart=0
window.performance.timing.redirectEnd=0
window.performance.navigation.redirectCount=0
window.performance.navigation.type=1
window.performance.navigation.TYPE_NAVIGATE=0
window.performance.navigation.TYPE_RELOAD=1
window.performance.navigation.TYPE_BACK_FORWARD=2
window.performance.navigation.TYPE_RESERVED=255
window.performance.memory.totalJSHeapSize=0
window.performance.memory.usedJSHeapSize=0
window.performance.memory.jsHeapSizeLimit=0

PS:Android从2.1版本还扩展实现了navigator.connection:
通过JavaScript测试结果如下:
navigator.connection.type=4
navigator.connection.UNKNOWN=0
navigator.connection.ETHERNET=1
navigator.connection.WIFI=2
navigator.connection.CELL_2G=3
navigator.connection.CELL_3G=4

 

Older Posts »

Powered by WordPress