LuaJava compile error “Unresolved external symbol”

左心房为你撑大大i 提交于 2019-12-25 02:43:03

问题


Finally I compiled it. Main mistake was about VS enviromental variables. To compile and link proper I needed to type

%VisualStudoFolder%\VC\vcvarsall.bat amd64
nmake -f makefile

Default LuaJava distributions provides only 32-bit binaries. Obviously using them with 64-bit VM\OS causes exception.

Also I can't just change Lua binaries to 64-bit, because this causes

Exception in thread "main" java.lang.UnsatisfiedLinkError:
org.keplerproject.luajava.LuaState._open()Lorg/keplerproject/luajava/CPtr;

I don't know why is it so and Google didn't help me.

I've decided it's because 64- and 32-bit libs are completely different, so I must recompile LuaJava and make linking myself.

I downloaded sources from Lua repo at SourceForge (luabinaries/files/5.1.4/Windows%20Libraries/) (btw I tried with different versions, but I have not succeeded), installed MSVS to use nmake utility with Makefiles. Finally I followed guides from "LuaJava Manual" but I got only this:

...\luajava-1.1>nmake -f makefile
"
#Here was java-files compilation logs

#C compilation
cl -nologo -DWIN32 -I"C:\Program Files\Java\jdk1.7.0_21\/include" -I"C:\Program Files\Java\jdk1.7.0_21\/include/win32" -I"P:\Lua\include" -Fosrc\C\\ -MD /c src\c\luajava.c luajava.c

link  /dll /nodefaultlib:"msvcrt.lib" -out:luajava-1.1.dll src\c\luajava.obj P:\Lua\lib\lua5.1.lib
Microsoft (R) Incremental Linker Version 12.00.20827.3
Copyright (C) Microsoft Corporation.  All rights reserved.

Creating library luajava-1.1.lib and object luajava-1.1.exp
luajava.obj : error LNK2019: unresolved external symbol __imp____iob_func referenced in function _Java_org_keplerproject_luajava_LuaState_luajava_1open@16
luajava.obj : error LNK2019: unresolved external symbol __imp__fprintf referenced in function Java_org_keplerproject_luajava_LuaState_luajava_1open@16
luajava.obj : error LNK2019: unresolved external symbol __imp__exit referenced in function Java_org_keplerproject_luajava_LuaState_luajava_1open@16
luajava.obj : error LNK2001: unresolved external symbol "__fltused"
LINK : error LNK2001: unresolved external symbol "__DllMainCRTStartup@12"
luajava-1.1.dll : fatal error LNK1120: 5 unresolved externals
NMAKE : fatal error U1077: "P:\MS Visual Studio 2010\VC\BIN\link.EXE" : return code "0x460"
Stop.

Also here is luajava.h and luajava.c

So the question is how to resolve that problem (desirable so that it will work with at least LuaStateFactory.newLuaState().openLibs())?


回答1:


I have encountered this problem, but later resolved. Here is the solution.
I've managed to compile a 64-bit luajava-64.dll, 64-bit luajava-64.so, 32-bit dynamic link libraries, and so on.

Here are the steps.

1.   Install vs2010

2.   Locate vs2010-visual studio tools
     Open visual studio x64 Win64 Command Prompt tool
    
3.   Download lua-5.1.5_Win64_vc10_lib.zip
     . (Static library wrong key point is that this static library may download error, or you download as a dynamic library dll, download address: lua static library download:
     http://sourceforge.net/projects/luabinaries/files/5.1.5/Windows%20Libraries/Static/)
     Download luajava-1.1.zip
    
4.   Open config.win modify LUA_DIR and JDK two paths for their own path
     Note that you may not have your LUA_DIR below lib directory, then create your own needs and into which lua5.1.lib
    
5.   cd enter luajava-1.1 directory
    
6.   Run nmake -f Makefile.win
    
7.   Compile success
    
    
     Here is the situation at compile time:
     C: \ Users \ softm \ Desktop \ luajava \ luajava-1.1> nmake -f Makefile.win
    
     Microsoft (R) Program Maintenance Utility 10.00.30319.01 version
     Copyright (C) Microsoft Corporation. All rights reserved.
    
             "D: \ soft \ Java \ jdk6_33 \ bin \ javac" -sourcepath ./src/java src / java / org / kep
     lerproject / luajava / CPtr.java
             "D: \ soft \ Java \ jdk6_33 \ bin \ javac" -sourcepath ./src/java src / java / org / kep
     lerproject / luajava / JavaFunction.java
     Note: Some input files use unchecked or unsafe operations.
     Note: For more information, please use the -Xlint: unchecked recompiled.
             "D: \ soft \ Java \ jdk6_33 \ bin \ javac" -sourcepath ./src/java src / java / org / kep
     lerproject / luajava / LuaJavaAPI.java
     Note: Some input files use unchecked or unsafe operations.
     Note: For more information, please use the -Xlint: unchecked recompiled.
             "D: \ soft \ Java \ jdk6_33 \ bin \ javac" -sourcepath ./src/java src / java / org / kep
     lerproject / luajava / Console.java
     Note: Some input files use unchecked or unsafe operations.
     Note: For more information, please use the -Xlint: unchecked recompiled.
             cd src / java
             "D: \ soft \ Java \ jdk6_33 \ bin \ jar" cvf ../../luajava-1.1.jar org / keplerproje
     ct / luajava / *. class
     Marked list (manifest)
     Increase: org / keplerproject / luajava / Console.class (read = 1921) (write = 1122) (compressed 41
     %)
     Increase: org / keplerproject / luajava / CPtr.class (read = 510) (write = 359) (29% compression)
     Increase: org / keplerproject / luajava / JavaFunction.class (read = 942) (write = 524) (compressed
      44%)
     Increase: org / keplerproject / luajava / LuaException.class (read = 556) (write = 352) (compressed
      36%)
     Increase: org / keplerproject / luajava / LuaInvocationHandler.class (read = 1621) (written = 83
     3) (48% compression)
     Increase: org / keplerproject / luajava / LuaJavaAPI.class (read = 7168) (write = 3745) (compressed
      47%)
     Increase: org / keplerproject / luajava / LuaObject.class (read = 9045) (write = 3978) (compressed
     56%)
     Increase: org / keplerproject / luajava / LuaState.class (read = 18118) (write = 6435) (compressed
     64%)
     Increase: org / keplerproject / luajava / LuaStateFactory.class (read = 1293) (write = 722) (Pressure
     Reduced by 44%)
             cd ..
             cd ..
             "D: \ soft \ Java \ jdk6_33 \ bin \ javadoc" -classpath "src / java /" -public -quiet
      -d "doc / us / API" src / java / org / keplerproject / luajava / JavaFunction.java src / java /
     org / keplerproject / luajava / LuaException.java src / java / org / keplerproject / luajava /
     LuaInvocationHandler.java src / java / org / keplerproject / luajava / LuaObject.java sr
     c / java / org / keplerproject / luajava / LuaState.java src / java / org / keplerproject / luaja
     va / LuaStateFactory.java src / java / org / keplerproject / luajava / Console.java
             "D: \ soft \ Java \ jdk6_33 \ bin \ javah" -o src / c / luajava.h -classpath "luajava-
     1.1.jar "org.keplerproject.luajava.LuaState
             cl -nologo -DWIN32 -I "D: \ soft \ Java \ jdk6_33 / include" -I "D: \ soft \ Java \ jdk6
     _33 / Include / win32 "-I" C: \ Users \ softm \ Desktop \ luajava \ lua \ include "-Fosrc \ C \\ -MD
      / c src \ c \ luajava.c
     luajava.c
             link / dll /nodefaultlib:"msvcrt.lib "-out: luajava-1.1.dll src \ c \ luajava
     .obj C: \ Users \ softm \ Desktop \ luajava \ lua \ lib \ lua5.1.lib
     Microsoft (R) Incremental Linker Version 10.00.30319.01
     Copyright (C) Microsoft Corporation. All rights reserved.
        Creating library luajava-1.1.lib and objects luajava-1.1.exp
     luajava.obj: warning LNK4217: locally defined symbol exit function Java_org_keplerproject
     Import _luajava_LuaState_luajava_1open
     luajava.obj: warning LNK4217: locally defined symbol fprintf function Java_org_keplerproj
     Import ect_luajava_LuaState_luajava_1open
     luajava.obj: warning LNK4217: locally defined symbol __iob_func function Java_org_keplerp
     Import roject_luajava_LuaState_luajava_1open
             del src \ java \ org \ keplerproject \ luajava \ *. class src \ c \ *. obj * .pdb * .exp *
     .lib * .exp * .ilk
     ------------------
     Build Complete
     ------------------


来源:https://stackoverflow.com/questions/19728418/luajava-compile-error-unresolved-external-symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!