1

我正在尝试在 C 中构建一些本机库,以加快 Java 项目的蒙特卡罗模拟。我正在使用 MINGW 在 Netbeans 7.0.1 上执行此操作

我正在使用 Geof Kuenning ( http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html ) 的 mtwist 源代码来提供 Mersenne Twister 伪随机数。

我要模拟三个不同的模型,每个模型都可以自行编译(输出到文件而不是使用 JNI)。但是,当我在 JNI 头文件下组合三个模型时,我在尝试构建时开始得到一长串错误:

CLEAN SUCCESSFUL (total time: 7s) "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: 进入目录/c/Users/Tom/Documents/LongMemoryModels/longMemModels' "/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_1- Windows/liblongMemModels.dll make[2]: Entering directory/c/Users/Tom/Documents/LongMemoryModels/longMemModels' mkdir -p build/Debug/MinGW_1-Windows rm -f build/Debug/MinGW_1-Windows/longmem.od gcc.exe -std=c99 -c -g -I ../../../../../Program\ Files/Java/jdk1.7.0/include/ -I../../../../../Program\ Files/Java/ jdk1.7.0/include/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/longmem.od -o build/Debug/MinGW_1-Windows/longmem.o longmem.c mkdir -p build/Debug/MinGW_1-Windows /_ext/2069311947 rm -f build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.od gcc.exe -std=c99 -c -g -I../../../../../ Program\ Files/Java/jdk1.7.0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/include/win32 -MMD -MP -MF build/ Debug/MinGW_1-Windows/_ext/2069311947/mtwist.od -o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o ../../../../../cinclude/mtwist/mtwist .c mkdir -p build/Debug/MinGW_1-Windows/_ext/2069311947 rm -f build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.od gcc.exe -std=c99 -c -g -I../。 ./../../../Program\ Files/Java/jdk1.7.0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/包括/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.od -o build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o ../../../ ../../cinclude/mtwist/randistrs.c mkdir -p dist/Debug/MinGW_1-Windows gcc.exe -std=c99 -shared -o dist/Debug/MinGW_1-Windows/liblongMemModels.dll build/Debug/MinGW_1 -Windows/longmem.o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o > build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/include/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/_ext/ 2069311947/randistrs.od -o build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o ../../../../../cinclude/mtwist/randistrs.c mkdir -p dist/Debug /MinGW_1-Windows gcc.exe -std=c99 -shared -o dist/Debug/MinGW_1-Windows/liblongMemModels.dll build/Debug/MinGW_1-Windows/longmem.o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist .o > 构建/调试/MinGW_1-Windows/_ext/2069311947/randistrs.o0/include/ -I../../../../../Program\ Files/Java/jdk1.7.0/include/win32 -MMD -MP -MF build/Debug/MinGW_1-Windows/_ext/ 2069311947/randistrs.od -o build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o ../../../../../cinclude/mtwist/randistrs.c mkdir -p dist/Debug /MinGW_1-Windows gcc.exe -std=c99 -shared -o dist/Debug/MinGW_1-Windows/liblongMemModels.dll build/Debug/MinGW_1-Windows/longmem.o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist .o > 构建/调试/MinGW_1-Windows/_ext/2069311947/randistrs.oexe -std=c99 -shared -o dist/Debug/MinGW_1-Windows/liblongMemModels.dll build/Debug/MinGW_1-Windows/longmem.o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o > build/Debug /MinGW_1-Windows/_ext/2069311947/randistrs.oexe -std=c99 -shared -o dist/Debug/MinGW_1-Windows/liblongMemModels.dll build/Debug/MinGW_1-Windows/longmem.o build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o > build/Debug /MinGW_1-Windows/_ext/2069311947/randistrs.o
build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o: 在函数mts_lrand': C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition ofmts_lrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:402: 首先在这里定义 build/ Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o: 在函数mts_llrand': C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition ofmts_llrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:431: 首先定义在这里 [... ] build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o: 在函数mts_lrand': C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition ofmts_lrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:402: 这里首先定义 build /Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o: 在函数mts_llrand': C:\Users\Tom\Documents\LongMemoryModels\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition ofmts_llrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:431: 这里首先定义 [.. .] make[2]: 离开目录/c/Users/Tom/Documents/LongMemoryModels/longMemModels' make[1]: Leaving directory/c/Users/Tom/Documents/LongMemoryModels/longMemModels'

collect2.exe: 错误: ld 返回 1 退出状态 make[2]: * [dist/Debug/MinGW_1-Windows/liblongMemModels.dll] 错误 1 ​​make[1]:[.build-conf] 错误 2 make: * * [.build-impl] 错误 2

BUILD FAILED(退出值2,总时间:22s)

(这里的省略号 [...] 表示我省略的类似错误)

如您所见,多个包含似乎与 mtwist.h 标头有关,而不是与 JNI 标头有关。此外,即使 mtwist 已经成功构建为静态或动态库,我在尝试构建 JNI 项目时也会遇到相同的错误......

我不希望这个问题太像一篇文章,我希望这个错误会向比我更精明的人揭示一个明显的错误。但是,如果这还不足以指出解决方案,我也会发布源代码。

如果可以的话,请帮我解决这个构建错误。汤姆

编辑:使包含结构比评论中更清晰......在当前安排中:

  • [JNI 模型头].h 包括 jni.h
  • mtwist.h 包括 stdio.h、stdint.h
  • randistrs.h,包括 mtwist.h
  • [个别模型函数].c 包括 stdio.h stdlib.h math.h mtwist/mtwist.h mtwist/randistrs.h jni.h (我想是不必要的)
  • mtwist.c 包括 inttypes.h stdio.h stdlib.h sys/timeb.h mtwist.h
  • randistrs.c 包括 mtwist.h randistrs.h math.h stdlib.h

所有 .h 文件都有使用 #ifndef 的包含保护

4

1 回答 1

0

我想这是一个包含多个原型的情况。请尝试使用 mtwist.h 中的#ifdef #endif 宏来保护所有那些给出错误的原型。

于 2013-05-06T12:35:46.843 回答