Compile for JNI in windows 7

2019-08-09 01:40发布

问题:

I am trying to compile an open source project called jbliss as a DLL under windows 7, so that I can use it with JNI in Java. Everything works fine in Linux using the makefile already provided in the package.

My first search pointed me to cygwin, and then I followed several suggestions, like this one, which basically tells me to use:

gcc-3 -D __int64="long long" -mno-cygwin -Wl,--add-stdcall-alias 
  -I"<JAVA_HOME>\include" -I"<JAVA_HOME>\include\win32" -shared -o jbliss.dll *.cc

This brings me mainly to the following error:

bliss-0.50/timer.cc:2:23: sys/times.h: No such file or directory

I googled this error, and found this post, which suggests to use -I /usr/include/. But that will cause more errors than it solves:

In file included from /usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/bits/stl_algobase.h:67,
                 from /usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/bits/stl_tree.h:66,
                 from /usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/set:66,
                 from bliss-0.50/graph.cc:4:
/usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/cstdlib:181: error: `::strtold' has not been declared
/usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/cstdlib:200: error: `__gnu_cxx::strtold' has not been declared

So I am sitting now puzzled and hoping for an answer, which options of gcc to use to get it right. I have just downloaded cygwin and I would say I have the lastest version.

Thanks in advance.


Extra local information:

$ which gcc
/usr/bin/gcc

$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/WATCOM/BINNT:/cygdrive/c/WATCOM/BINW:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/QuickTime Alternative/QTSystem:/cygdrive/c/Program Files/TortoiseSVN/bin:/cygdrive/c/Program Files/MATLAB/R2011b/runtime/win64:/cygdrive/c/Program Files/MATLAB/R2011b/bin:/cygdrive/c/Program Files (x86)/OpenSSH/bin:/cygdrive/c/Program Files/MiKTeX 2.9/miktex/bin/x64:/cygdrive/c/Program Files (x86)/Graphviz 2.28/bin

回答1:

Googling further shows me the fact that indeed sys/times.h is not (and apparently is not supposed to be) available on mingw. The include files under sys/times.h are said to be platform dependent and therefore not supported on windows.

The solution is to remove any call to sys/times.h (or any platform dependent library) as far as possible. Removing these include files (and of course adding proper options to the compiler) leads to a successful build.