razibmimran / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Linker errors when building on Mac or Windows (undefined/unresolved symbol: JNI_CreateJavaVM) #253

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. download and install opencv 2.4.2
2. download and install javacpp "0.2" (f179b01)
3. download and install javacv "0.2" (77ec07c)

What is the expected output? What do you see instead?
Expected: no errors; target files installed to local maven repository
Actual, by platform:

Mac OS X 10.6.8 Snow Leopard, with JDK 1.6.0_37, maven 3.0.4, gcc 4.2.1:
> [INFO] --- exec-maven-plugin:1.2:exec (javacpp) @ javacv ---
> Generating source file: 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp
> Building library file: 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/macosx-x
86_64/libjnicvkernels.dylib
> g++ 
-I/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include 
-I/opt/local/include/ 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp -msse3 -ffast-math -Wl,-rpath,@loader_path/. -march=x86-64 -m64 -Wall 
-O3 -fPIC -dynamiclib -o 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/macosx-x
86_64/libjnicvkernels.dylib 
> 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp: In function ‘int JavaCPP_init(int, const char**)’:
> 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp:166: warning: ‘JNI_CreateJavaVM’ is deprecated (declared at 
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include/jni.h:1
937)
> 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp:166: warning: ‘JNI_CreateJavaVM’ is deprecated (declared at 
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include/jni.h:1
937)
> Undefined symbols:
>   "_JNI_CreateJavaVM", referenced from:
>       _JavaCPP_init in ccfooZk2.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> [INFO] 
------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] 
------------------------------------------------------------------------

This occurs regardless of whether opencv was installed from source or through 
macports.

Windows 7 (32-bit), with JDK 1.6.0_37, maven 3.0.4, Visual Studio Pro 2012:
> [INFO] --- exec-maven-plugin:1.2:exec (javacpp) @ javacv ---
> Generating source file: 
C:\Users\semaine\workspace\javacv\target\classes\com\goo
> glecode\javacv\cpp\jnicvkernels.cpp
> Building library file: 
C:\Users\semaine\workspace\javacv\target\classes\com\goog
> lecode\javacv\cpp\windows-x86\jnicvkernels.dll
> cl "/IC:\Program Files\Java\jdk1.6.0_37\include" "/IC:\Program 
Files\Java\jdk1.6
> .0_37\include\win32" /IC:/opencv/build/include/ 
C:\Users\semaine\workspace\javac
> v\target\classes\com\googlecode\javacv\cpp\jnicvkernels.cpp /arch:SSE2 
/fp:fast
> /W3 /Oi /O2 /EHsc /Gy /GL /MD /LD /link 
/OUT:C:\Users\semaine\workspace\javacv\t
> arget\classes\com\googlecode\javacv\cpp\windows-x86\jnicvkernels.dll
> Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 
> jnicvkernels.cpp
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(127) : warning C4244: '=' : conversion from 'int' to 'float', possible 
lo
> ss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(160) : warning C4244: 'initializing' : conversion from 'double' to 
'unsig
> ned char', possible loss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(299) : warning C4244: '=' : conversion from 'float' to 'unsigned 
char', p
> ossible loss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(369) : warning C4244: '=' : conversion from 'float' to 'unsigned 
char', p
> ossible loss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(377) : warning C4244: '=' : conversion from 'float' to 'unsigned 
char', p
> ossible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(117) : warning C4996: 'strcpy': This function or variable may be 
uns
> afe. Consider using strcpy_s instead. To disable deprecation, use 
_CRT_SECURE_NO
> _WARNINGS. See online help for details.
>         C:\Program Files\Microsoft Visual Studio 
11.0\VC\INCLUDE\string.h(110) :
>  see declaration of 'strcpy'
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(119) : warning C4996: 'strncpy': This function or variable may be 
un
> safe. Consider using strncpy_s instead. To disable deprecation, use 
_CRT_SECURE_
> NO_WARNINGS. See online help for details.
>         C:\Program Files\Microsoft Visual Studio 
11.0\VC\INCLUDE\string.h(191) :
>  see declaration of 'strncpy'
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 's' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: '.' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'c' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'g' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'j' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'w' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(318) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(331) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(340) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(356) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(371) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(916) : warning C4800: 'jboolean' : forcing value to bool 'true' 
or '
> false' (performance warning)
> Microsoft (R) Incremental Linker Version 11.00.50727.1
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 
> /out:jnicvkernels.dll
> /ltcg
> /dll
> /implib:jnicvkernels.lib
> 
/OUT:C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\
> windows-x86\jnicvkernels.dll
> jnicvkernels.obj
>    Creating library jnicvkernels.lib and object jnicvkernels.exp
> jnicvkernels.obj : error LNK2001: unresolved external symbol 
__imp__JNI_CreateJa
> vaVM@12
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\windo
> ws-x86\jnicvkernels.dll : fatal error LNK1120: 1 unresolved externals
> [INFO] 
------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] 
------------------------------------------------------------------------

Windows 7 (64-bit), with JDK 1.6.0_37, maven 3.0.4, Visual Studio Pro 2012:
> [INFO] --- exec-maven-plugin:1.2:exec (javacpp) @ javacv ---
> Generating source file: 
C:\Users\semaine\workspace\javacv\target\classes\com\goo
> glecode\javacv\cpp\jnicvkernels.cpp
> Building library file: 
C:\Users\semaine\workspace\javacv\target\classes\com\goog
> lecode\javacv\cpp\windows-x86_64\jnicvkernels.dll
> cl "/IC:\Program Files\Java\jdk1.6.0_37\include" "/IC:\Program 
Files\Java\jdk1.6
> .0_37\include\win32" /IC:/opencv/build/include/ 
C:\Users\semaine\workspace\javac
> v\target\classes\com\googlecode\javacv\cpp\jnicvkernels.cpp /fp:fast /W3 /Oi 
/O2
>  /EHsc /Gy /GL /MD /LD /link 
/OUT:C:\Users\semaine\workspace\javacv\target\class
> es\com\googlecode\javacv\cpp\windows-x86_64\jnicvkernels.dll
> Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 
> jnicvkernels.cpp
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(127) : warning C4244: '=' : conversion from 'int' to 'float', possible 
lo
> ss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(160) : warning C4244: 'initializing' : conversion from 'double' to 
'unsig
> ned char', possible loss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(299) : warning C4244: '=' : conversion from 'float' to 'unsigned 
char', p
> ossible loss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(369) : warning C4244: '=' : conversion from 'float' to 'unsigned 
char', p
> ossible loss of data
> 
c:\users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\cvker
> nels.h(377) : warning C4244: '=' : conversion from 'float' to 'unsigned 
char', p
> ossible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(117) : warning C4996: 'strcpy': This function or variable may be 
uns
> afe. Consider using strcpy_s instead. To disable deprecation, use 
_CRT_SECURE_NO
> _WARNINGS. See online help for details.
>         C:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\INCLUDE\string.h(
> 110) : see declaration of 'strcpy'
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(119) : warning C4996: 'strncpy': This function or variable may be 
un
> safe. Consider using strncpy_s instead. To disable deprecation, use 
_CRT_SECURE_
> NO_WARNINGS. See online help for details.
>         C:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\INCLUDE\string.h(
> 191) : see declaration of 'strncpy'
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 's' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: '.' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'c' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'g' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'j' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(161) : warning C4129: 'w' : unrecognized character escape sequence
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(326) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(339) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(348) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(364) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(379) : warning C4244: 'argument' : conversion from 'jlong' to 
'size_
> t', possible loss of data
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\jnicv
> kernels.cpp(916) : warning C4800: 'jboolean' : forcing value to bool 'true' 
or '
> false' (performance warning)
> Microsoft (R) Incremental Linker Version 11.00.50727.1
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 
> /out:jnicvkernels.dll
> /ltcg
> /dll
> /implib:jnicvkernels.lib
> 
/OUT:C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\
> windows-x86_64\jnicvkernels.dll
> jnicvkernels.obj
>    Creating library jnicvkernels.lib and object jnicvkernels.exp
> jnicvkernels.obj : error LNK2001: unresolved external symbol 
__imp__JNI_CreateJa
> vaVM@12
> 
C:\Users\semaine\workspace\javacv\target\classes\com\googlecode\javacv\cpp\windo
> ws-x86_64\jnicvkernels.dll : fatal error LNK1120: 1 unresolved externals
> [INFO] 
------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] 
------------------------------------------------------------------------

On both architectures, this occurs regardless of whether opencv was built from 
source or unpacked from the binary release package downloaded from 
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/OpenCV-2.4.
2.exe

What version of the product are you using? On what operating system?
(see above)

Please provide any additional information below.
Everything is fine on linux (both 32 and 64-bit), with opencv installed from 
source.

Original issue reported on code.google.com by psi...@gmail.com on 23 Oct 2012 at 9:52

GoogleCodeExporter commented 9 years ago
Fix for Mac:

The g++ invocation must include the option "-framework JavaVM" (without the 
quotes). One way to inject this is to use the javacpp option -Xcompiler for 
*each* token (because of the space), and to pass this through maven using the 
javacpp.options property. This in turn can be set in the macosx profile (see 
attached patch).

Original comment by psi...@gmail.com on 23 Oct 2012 at 10:14

Attachments:

GoogleCodeExporter commented 9 years ago
Fix for Windows (32-bit):

The cl.exe invocation must include the option '/LIBPATH 
"%JAVA_HOME%\lib\jvm.lib"' (without the single quotes). Running mvn install 
succeeds with the attached patch on Windows 7 32-bit, but fails as before on 
Windows 7 64-bit...

Original comment by psi...@gmail.com on 23 Oct 2012 at 10:42

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the feedback! This is something that should be fixed in JavaCPP 
actually. I made some changes here that should fix that, but I haven't tested 
them yet:
http://code.google.com/p/javacpp/source/detail?r=e544f7c74edc2b34b125bf02dee6e74
41a130224
Can you try them out for me? Thanks!

Original comment by samuel.a...@gmail.com on 27 Oct 2012 at 3:06

GoogleCodeExporter commented 9 years ago
Thanks! I've updated to javacpp@c523018 and javacv@77ec07c and on the Mac it 
builds, but ld generates warnings:
> Generating source file: 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp
> Building library file: 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/macosx-x
86_64/libjnicvkernels.dylib
> g++ -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers 
-I/opt/local/include/ 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/jnicvker
nels.cpp -msse3 -ffast-math -Wl,-rpath,@loader_path/. -march=x86-64 -m64 -Wall 
-O3 -fPIC -dynamiclib -o 
/Users/ingmar/workspace/javacv/target/classes/com/googlecode/javacv/cpp/macosx-x
86_64/libjnicvkernels.dylib 
-L/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries 
-Wl,-rpath,/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries
 -ljvm -framework JavaVM 
> ld: warning: in 
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/libjvm.dyl
ib, file was built for i386 which is not the architecture being linked (x86_64)

This I believe is due to the presence of `-ljvm`, which seems to override the 
`-framework JavaVM`, the latter being the "proper" way to link to jvm on the 
mac, apparently. Indeed, suppressing the `-ljvm` makes the warnings go away.
In any case, the result builds fine and my test app can call native functions 
successfully through its javacv dependency.

Original comment by psi...@gmail.com on 31 Oct 2012 at 6:06

GoogleCodeExporter commented 9 years ago
Are there any circumstances where "-framework JavaVM" does not work on Mac OS 
X? For example, what happens with Oracle JDK 7?

Original comment by samuel.a...@gmail.com on 1 Nov 2012 at 1:48

GoogleCodeExporter commented 9 years ago
This issue should be fixed by the changes I made for that issue:
    http://code.google.com/p/javacpp/issues/detail?id=33
Basically, if we don't use the "-header" option, to be able to use named 
callbacks out of the blue, it won't try to link with libjvm explicitly.

But let me know if that doesn't fix this issue, thanks!

Original comment by samuel.a...@gmail.com on 16 Sep 2013 at 11:11