如何设置 libpd 以便在 Java 中使用?

How to setup libpd for use in Java?

PureData 是一种用于声音合成的编程语言。 LibPD 是它的包装器,因此我们可以在 Java/C#/Android 等中使用补丁。 这是包含它的 GitHub 页面:https://github.com/libpd/libpd

现在要在 Java 中使用 LibPD,我想首先我应该将它的库导入我的项目,然后使用它的 类 和方法来调用我的补丁并调整它。问题是,我找不到要添加到我的项目中的 jar 文件。我是否必须 "build" 生成 jar 文件?

如果有人向我解释该过程,我将不胜感激。
谢谢

更新一[2017-01-11]:
在关注@umläute 的 post 之后,我收到以下错误: (我在 Windows 7/64 位中使用 MinGW,在 make 中使用 MinGW-make

C:\Users\Name\Documents\GitHub>cd libpd

C:\Users\Name\Documents\GitHub\libpd>git submodule init

C:\Users\Name\Documents\GitHub\libpd>git submodule update

C:\Users\Name\Documents\GitHub\libpd>make javalib
'make' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Name\Documents\GitHub\libpd>mingw32-make javalib
process_begin: CreateProcess(NULL, uname, ...) failed.
'sed' is not recognized as an internal or external command,
operable program or batch file.
'sed' is not recognized as an internal or external command,
operable program or batch file.
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_arithmetic.o pure-data/src/d_arithmetic.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_array.o pure-data/src/d_array.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_ctl.o pure-data/src/d_ctl.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_dac.o pure-data/src/d_dac.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_delay.o pure-data/src/d_delay.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_fft.o pure-data/src/d_fft.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_fft_fftsg.o pure-data/src/d_fft_fftsg.c
pure-data/src/d_fft_fftsg.c: In function 'mayer_dofft':
pure-data/src/d_fft_fftsg.c:88:11: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
default]
     buf = alloca(n * (2 * sizeof(FFTFLT)));
           ^
pure-data/src/d_fft_fftsg.c: In function 'mayer_realfft':
pure-data/src/d_fft_fftsg.c:121:11: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
 default]
     buf = alloca(n * sizeof(FFTFLT));
           ^
pure-data/src/d_fft_fftsg.c: In function 'mayer_realifft':
pure-data/src/d_fft_fftsg.c:139:11: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
 default]
     buf = alloca(n * sizeof(FFTFLT));
           ^
pure-data/src/d_fft_fftsg.c: In function 'pd_fft':
pure-data/src/d_fft_fftsg.c:156:30: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by
 default]
     FFTFLT *buf2 = (FFTFLT *)alloca(2 * npoints * sizeof(FFTFLT)), *bp2;
                              ^
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_filter.o pure-data/src/d_filter.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_global.o pure-data/src/d_global.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_math.o pure-data/src/d_math.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_osc.o pure-data/src/d_osc.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_resample.o pure-data/src/d_resample.c
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o pure-data/src/d_soundfile.o pure-data/src/d_soundfile.c
pure-data/src/d_soundfile.c:17:21: fatal error: pthread.h: No such file or directory
 #include <pthread.h>
                     ^
compilation terminated.
<builtin>: recipe for target 'pure-data/src/d_soundfile.o' failed
mingw32-make: *** [pure-data/src/d_soundfile.o] Error 1

更新2 [2017-01-11]:
我已经安装了 MSYS2mingw3264 以及 make(感谢@milleniumbug 的帮助)。我已将 mingw64make 的目录添加到 PATH。 现在,当我执行 make javalib 时,出现此错误:

C:\Users\Name\Documents\GitHub\libpd>make javalib
gcc -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src -I./libpd_wrapper -I./libpd_wrapper/util  -DWINVER=0x502 -DWIN
32 -D_WIN32 -DPD_INTERNAL -I"C:\Program Files\Java\jdk1.8.0_45/include" -I"C:\Program Files\Java\jdk1.8.0_45/include/win
32" -O3   -c -o jni/z_jni_plain.o jni/z_jni_plain.c
In file included from jni/z_jni_shared.c:8:0,
                 from jni/z_jni_plain.c:8:
jni/z_jni.h:2:10: fatal error: jni.h: No such file or directory
 #include <jni.h>
          ^~~~~~~

更新 3 [4-11-2017]: 已解决 jni.h 问题。我的 PATH 指向旧的 jdk 而不是更新的。 现在我收到这个错误:

C:/msys32/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Cannot export libpd
_set_concatenated_printhook: symbol not found
C:/msys32/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture o
f input file `libpd_wrapper/util/z_print_util.o' is incompatible with i386:x86-64 output
libpd_wrapper/util/z_print_util.o:z_print_util.c:(.text+0x3a): undefined reference to `_strlen'
libpd_wrapper/util/z_print_util.o:z_print_util.c:(.text+0x75): undefined reference to `_strncat'
libpd_wrapper/util/z_print_util.o:z_print_util.c:(.text+0xad): undefined reference to `_strncat'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:163: java-build/org/puredata/core/natives/windows/x86_64//pdnative.dll] Error 1

用 32 位 MinGW gcc 测试了...还是一样的错误...

更新 4 [6-11-2017]:
已解决问题
看来我已经设法解决了。这是我通常所做的:
1- 首先,我安装了 msys2 并对其进行了全面检查,MinGW32MinGW64 以及 make
注意: 如果您是从旧的原始站点获取的,请删除 mingw32。它不再更新,您可能会遇到依赖性问题。
2- 将 PATH 更改为使用 MinGW32(所以 gcc -v 应该报告 32 位版本)
3- 将 JAVA_HOME 更改为更新后的 jdk 目录。似乎更新 java 不会自动更新环境。变量(这解决了 jni header not found 问题)。
4- 安装 git 并通过 git 命令获取 libpd(按照存储库自述文件中的说明)
5- make clean
6- make clean libpd
7- make clean javalib

我希望这对某人有所帮助

libpd Github project 包含(与其他 源代码 存储库一样)libpd 的 sources(而不是预构建的二进制文件).

来自README

To download libpd & checkout the pure-data submodule do the following:

git clone https://github.com/libpd/libpd.git
cd libpd
git submodule init
git submodule update

然后继续构建:

Currently the main Makefile builds a dynamic lib on Windows (in MinGW), Linux, & Mac OSX and has the following targets:

  • libpd: (default) builds if no target is specified, builds the libpd.so/dylib/dll
  • [...]
  • javalib: builds libpdnative and the jni wrapper
  • clean: removes the object files

因此,要创建您的 libs/libpd.jar,只需执行以下操作:

make javalib