简体   繁体   English

C多定义错误Netbeans

[英]C multiple definition error Netbeans

I'm trying to build some native libraries in C that will speed up the monte-carlo simulation for a Java project. 我正在尝试使用C建立一些本机库,以加快Java项目的蒙特卡洛模拟。 I'm doing this on Netbeans 7.0.1, using MINGW 我正在使用MINGW在Netbeans 7.0.1上执行此操作

I'm using the mtwist source code of Geof Kuenning ( http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html ) to provide Mersenne Twister pseudorandom numbers. 我正在使用Geof Kuenning的mtwist源代码( http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html )提供Mersenne Twister伪随机数。

I have three different models to simulate, and each compiles fine on its own (with output to file rather than using the JNI). 我有三种不同的模型可以模拟,每种模型都可以自行编译(将输出输出到文件而不是使用JNI)。 However, when I combine the three models under the JNI header file, I start to get a long list of errors when I try to build: 但是,当我在JNI头文件下合并这三个模型时,尝试构建时会出现一堆错误:

CLEAN SUCCESSFUL (total time: 7s) "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: Entering directory /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/20693 干净成功(总时间:7秒)“ / 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 / 20693 11947/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/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 > build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o 11947 / mtwist.od -o build / Debug / MinGW_1-Windows / _ext / 2069311947 / mtwist.o ../../../../../cinclude/mtwist/mtwist.c mkdir -p构建/调试/ 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 / 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> build / Debug / MinGW_1-Windows / _ext / 2069311947 / randistrs.o
build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o: In function mts_lrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition of mts_lrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:402: first defined here build/Debug/MinGW_1-Windows/_ext/2069311947/mtwist.o: In function mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of mts_llrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:431: first defined here [...] build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o: In function mts_lrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition of mts_lrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:402: first defined here build/Debug/MinGW_1-Windows/_ext/2069311947/randistrs.o: In function mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of build / Debug / MinGW_1-Windows / _ext / 2069311947 / mtwist.o:在函数mts_lrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition of / Debug / MinGW_1-Windows / longmem.o:C:/cinclude/mtwist/mtwist.h:402的mts_lrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition of :此处首先定义build / Debug / MinGW_1-Windows / _ext / 2069311947 / mtwist.o:在函数mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of mts_llrand'build / Debug / MinGW_1-Windows / longmem.o:C:/cinclude/mtwist/mtwist.h:431的mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of :首先在此处定义build / Debug / MinGW_1-Windows / _ext / 2069311947 /randistrs.o:在函数mts_lrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:402: multiple definition of mts_lrand”建立/调试/ MinGW_1-视窗/ longmem.o:C:/cinclude/mtwist/mtwist.h:402:这里首先定义建立/调试/ MinGW_1-视窗/ _ext / 2069311947 / randistrs.o:在功能mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of mts_llrand' build/Debug/MinGW_1-Windows/longmem.o:C:/cinclude/mtwist/mtwist.h:431: first defined here [...] make[2]: Leaving directory /c/Users/Tom/Documents/LongMemoryModels/longMemModels' make[1]: Leaving directory /c/Users/Tom/Documents/LongMemoryModels/longMemModels' mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of mts_llrand'build / Debug / MinGW_1-Windows / longmem的mts_llrand': C:\\Users\\Tom\\Documents\\LongMemoryModels\\longMemModels/../../../../../cinclude/mtwist/mtwist.h:431: multiple definition of 。 o:C:/cinclude/mtwist/mtwist.h:431:首先在这里定义[[2]:离开目录/c/Users/Tom/Documents/LongMemoryModels/longMemModels' make[1]: Leaving directory / c / Users / Tom / Documents / LongMemoryModels / longMemModels'

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

BUILD FAILED (exit value 2, total time: 22s) 生成失败(退出值2,总时间:22秒)

(here the elipsis, [...], denotes similar errors that I have omitted) (这里的省略号[...]表示我已省略的类似错误)

As you can see, the multiple inclusions seem to relate to the mtwist.h header rather than the JNI header. 如您所见,多个包含似乎与mtwist.h标头有关,而不与JNI标头有关。 Moreover, I get the same errors trying to build the JNI project even when mtwist has already been successfully built as a static or dynamic library... 而且,即使已经成功地将mtwist构建为静态或动态库,尝试构建JNI项目时也会遇到相同的错误...

I don't want this question to be too much of an essay, and I'm hoping that error will reveal an obvious error to someone more savvy than me. 我不想让这个问题成为一篇论文的重点,我希望这个错误会给比我更精明的人揭示一个明显的错误。 BUT, I'll post source code too, if this isn't enough to point to a solution. 但是,如果这还不足以指出解决方案,我也将发布源代码。

Please help me resolve this build error if you can. 如果可以,请帮助我解决此构建错误。 Tom 汤姆

EDIT: to make the include structure clearer than in the comments... In the current arrangement: 编辑:使包含结构比注释中更清楚...在当前排列中:

  • [JNI models header].h includes jni.h [JNI模型头] .h包括jni.h
  • mtwist.h includes stdio.h, stdint.h mtwist.h包括stdio.h,stdint.h
  • randistrs.h, includes mtwist.h randistrs.h,包括mtwist.h
  • [individual model functions].c includes stdio.h stdlib.h math.h mtwist/mtwist.h mtwist/randistrs.h jni.h (unnecessary I suppose) [单个模型函数] .c包括stdio.h stdlib.h math.h mtwist / mtwist.h mtwist / randistrs.h jni.h(我认为是不必要的)
  • mtwist.c includes inttypes.h stdio.h stdlib.h sys/timeb.h mtwist.h mtwist.c包含inttypes.h stdio.h stdlib.h sys / timeb.h mtwist.h
  • randistrs.c includes mtwist.h randistrs.h math.h stdlib.h randistrs.c包括mtwist.h randistrs.h math.h stdlib.h

All of the .h files have inclusion guards using #ifndef 所有.h文件都有使用#ifndef的包含防护

我想这是一个包含多个原型的情况。请尝试在mtwist.h中使用#ifdef #endif宏进行防护,以防所有出现错误的原型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM