jni - C multiple definition error Netbeans -


i'm trying build native libraries in c speed monte-carlo simulation java project. i'm doing on netbeans 7.0.1, using mingw

i'm using mtwist source code of geof kuenning (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/mt/emt.html) provide mersenne twister pseudorandom numbers.

i have 3 different models simulate, , each compiles fine on own (with output file rather using jni). however, when combine 3 models under jni header file, start long list of errors when try build:

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.o.d 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.o.d -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.o.d 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.o.d -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.o.d 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.o.d -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 ofmts_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 ofmts_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 ofmts_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 ofmts_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'

collect2.exe: error: ld returned 1 exit status make[2]: * [dist/debug/mingw_1-windows/liblongmemmodels.dll] error 1 make[1]: [.build-conf] error 2 make: ** [.build-impl] error 2

build failed (exit value 2, total time: 22s)

(here elipsis, [...], denotes similar errors have omitted)

as can see, multiple inclusions seem relate mtwist.h header rather jni header. moreover, same errors trying build jni project when mtwist has been built static or dynamic library...

i don't want question of essay, , i'm hoping error reveal obvious error more savvy me. but, i'll post source code too, if isn't enough point solution.

please me resolve build error if can. tom

edit: make include structure clearer in comments... in current arrangement:

  • [jni models header].h includes jni.h
  • mtwist.h includes stdio.h, stdint.h
  • randistrs.h, includes mtwist.h
  • [individual model functions].c includes stdio.h stdlib.h math.h mtwist/mtwist.h mtwist/randistrs.h jni.h (unnecessary suppose)
  • mtwist.c includes inttypes.h stdio.h stdlib.h sys/timeb.h mtwist.h
  • randistrs.c includes mtwist.h randistrs.h math.h stdlib.h

all of .h files have inclusion guards using #ifndef

i guess it's case of multiple inclusion of prototype.please try guarding using #ifdef #endif macro in mtwist.h, prototypes giving error.


Comments