How to build libwebp for Java JNI in windows?

604 views
Skip to first unread message

dave.j...@gmail.com

unread,
Aug 18, 2015, 4:57:08 AM8/18/15
to WebP Discussion
Hello,
I've been trying to build libwebp to be used in Java. But currently I don't know the steps to do it properly.
I downloaded the libwebp-0.4.3.tar.gz. In the readme file, it says to run this command:
>nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output

So first I did the command, and it created a folder containing some '.exe', '.obj' and '.lib' files.

The readme also mention SWIG binding for java jni? So I downloaded it too (swigwin-3.0.7). After extracting it, I added them to environment-variable path.
Inside the \swig directory there is another readme that says to run this command:


$ gcc -shared -fPIC -fno-strict-aliasing -O2 \ -I/path/to/your/jdk/includes \ libwebp_java_wrap.c \ -lwebp \ -o libwebp_jni.so

Why is the output 'libwebp_jni.so', shouldn't it be '.dll' for jni? And so I modified that command to :
>gcc -shared -fPIC -fno-strict-aliasing -O2 -I"C:\Program Files\Java\jdk1.7.0_04\include" -I"C:\Program Files\Java\jdk1.7.0_04\include\win32" -I"C:\libwebp-0.4.3\src" -L"C:\libwebp-0.4.3\output\release-static\x86\lib" libwebp_java_wrap.c -lwebp -o libwebp_jni.dll

But I get this error:
C:\libwebp-0.4.3\swig>gcc -shared -fPIC -fno-strict-aliasing -O2 -I"C:\Program Files\Java\jdk1.7.0_04\include" -I"C:\Program Files\Jav\jdk1.7.0_04\include\win32" -I"C:\libwebp-0.4.3\src" -L"C:\libwebp-0.4.3\output\release-static\x86\lib" libwebp_java_wrap.c -lwebp -o libwebp_jni.dll
libwebp_java_wrap.c:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lwebp
collect2: ld returned 1 exit status

What is the correct way to build libwebp in Windows?


Sorry if this is a nooby question.
Thanks in advance!

Pepijn Van Eeckhoudt

unread,
Aug 18, 2015, 7:09:15 AM8/18/15
to webp-d...@webmproject.org
Using https://bitbucket.org/luciad/webp-imageio might be easier. It provides a Java binding and an ImageIO plugin which makes it pretty easy to encode/decode WebP images in JavaSE. 
There are precompiled binaries for libwebp 0.4.2. I haven’t had a chance to build binaries for 0.4.3 yet.

Pepijn

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
To post to this group, send email to webp-d...@webmproject.org.
Visit this group at http://groups.google.com/a/webmproject.org/group/webp-discuss/.
For more options, visit https://groups.google.com/a/webmproject.org/d/optout.

James Zern

unread,
Aug 25, 2015, 11:00:32 PM8/25/15
to WebP Discussion
Hi,


On Tuesday, August 18, 2015 at 1:57:08 AM UTC-7, dave.j...@gmail.com wrote:
Hello,
I've been trying to build libwebp to be used in Java. But currently I don't know the steps to do it properly.
I downloaded the libwebp-0.4.3.tar.gz. In the readme file, it says to run this command:
>nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output

So first I did the command, and it created a folder containing some '.exe', '.obj' and '.lib' files.

The readme also mention SWIG binding for java jni? So I downloaded it too (swigwin-3.0.7). After extracting it, I added them to environment-variable path.
Inside the \swig directory there is another readme that says to run this command:


$ gcc -shared -fPIC -fno-strict-aliasing -O2 \ -I/path/to/your/jdk/includes \ libwebp_java_wrap.c \ -lwebp \ -o libwebp_jni.so

Why is the output 'libwebp_jni.so', shouldn't it be '.dll' for jni?

The README was written with an eye toward linux, I hadn't tried building the jni for windows.
 
And so I modified that command to :
>gcc -shared -fPIC -fno-strict-aliasing -O2 -I"C:\Program Files\Java\jdk1.7.0_04\include" -I"C:\Program Files\Java\jdk1.7.0_04\include\win32" -I"C:\libwebp-0.4.3\src" -L"C:\libwebp-0.4.3\output\release-static\x86\lib" libwebp_java_wrap.c -lwebp -o libwebp_jni.dll

But I get this error:
C:\libwebp-0.4.3\swig>gcc -shared -fPIC -fno-strict-aliasing -O2 -I"C:\Program Files\Java\jdk1.7.0_04\include" -I"C:\Program Files\Jav\jdk1.7.0_04\include\win32" -I"C:\libwebp-0.4.3\src" -L"C:\libwebp-0.4.3\output\release-static\x86\lib" libwebp_java_wrap.c -lwebp -o libwebp_jni.dll
libwebp_java_wrap.c:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lwebp
collect2: ld returned 1 exit status

msvc libs and mingw probably won't mix well. You can probably build the swig jni wrapper (libwebp_java_wrap.c) with cl.exe, let me see if I can get some instructions together.

James Zern

unread,
Aug 25, 2015, 11:58:20 PM8/25/15
to WebP Discussion
The following should work if you're working within the libwebp tree, have JDK set to the top of your jdk install and use the simple example from swig/README. I tested with vs2013 & jdk1.7.0_40.

libwebp> nmake /f Makefile.vc CFG=release-static RTLIBCFG=static
libwebp
> cd swig
libwebp
> cl /I../src /I"%JDK%\include" /I"%JDK\include\win32" ^
  libwebp_java_wrap
.c ^
 
/MT /LD /Fe:webp_jni.dll ^
 
..\..\obj\release-static\x64\lib\libwebp.lib
libwebp
> "%JDK%\bin\javac.exe" -cp libwebp.jar libwebp_jni_example.java
libwebp
> "%JDK%\bin\java.exe" -Djava.library.path=. -cp libwebp.jar;. libwebp_jni_example


Let me know if it helps and I'll update the README. 
Reply all
Reply to author
Forward
0 new messages