Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error when building the example #7

Closed
chwangaa opened this issue Jun 30, 2015 · 6 comments
Closed

Error when building the example #7

chwangaa opened this issue Jun 30, 2015 · 6 comments

Comments

@chwangaa
Copy link

Hi

I successfully built torch-android, but when trying to build the example, I obtained the following error. I am wondering if you can help pls

Android NDK: WARNING:jni/Android.mk:torchdemo: non-system libraries in linker flags: -lluaT -ltorch-lua-static -lTH -lnn -ltorch -lnnx -limage -limgraph -lluaT -ltorch-lua-static -lTH -lnn -ltorch -lnnx -limage -limgraph    
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES    
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the    
Android NDK:     current module    
[armeabi-v7a] SharedLibrary  : libtorchdemo.so
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lluaT
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ltorch-lua-static
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lTH
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lnn
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ltorch
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lnnx
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -limage
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -limgraph
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lluaT
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ltorch-lua-static
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lTH
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lnn
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ltorch
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lnnx
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -limage
/home/tom/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -limgraph
jni/torchandroid.cpp:36: error: undefined reference to 'lua_gettop'
jni/torchandroid.cpp:38: error: undefined reference to 'lua_isstring'
jni/torchandroid.cpp:39: error: undefined reference to 'lua_tolstring'
jni/torchandroid.cpp:23: error: undefined reference to 'luaL_openlibs'
jni/torchandroid.cpp:29: error: undefined reference to 'lua_settop'
jni/torchandroid.cpp:52: error: undefined reference to 'lua_getfield'
jni/torchandroid.cpp:53: error: undefined reference to 'luaL_register'
jni/torchandroid.cpp:54: error: undefined reference to 'lua_settop'
jni/torchandroid.cpp:84: error: undefined reference to 'lua_tolstring'
jni/torchandroid.cpp:85: error: undefined reference to 'luaL_gsub'
jni/torchandroid.cpp:107: error: undefined reference to 'luaL_loadbuffer'
jni/torchandroid.cpp:116: error: undefined reference to 'luaL_newstate'
jni/torchandroid.cpp:122: error: undefined reference to 'lua_getfield'
jni/torchandroid.cpp:123: error: undefined reference to 'lua_getfield'
jni/torchandroid.cpp:124: error: undefined reference to 'lua_objlen'
jni/torchandroid.cpp:125: error: undefined reference to 'lua_pushcclosure'
jni/torchandroid.cpp:126: error: undefined reference to 'lua_rawseti'
jni/torchandroid.cpp:127: error: undefined reference to 'lua_settop'
./obj/local/armeabi-v7a/objs/torchdemo/torchandroid.o:torchandroid.cpp:lualibs: error: undefined reference to 'luaopen_base'
./obj/local/armeabi-v7a/objs/torchdemo/torchandroid.o:torchandroid.cpp:lualibs: error: undefined reference to 'luaopen_libtorch'
./obj/local/armeabi-v7a/objs/torchdemo/torchandroid.o:torchandroid.cpp:lualibs: error: undefined reference to 'luaopen_libnn'
./obj/local/armeabi-v7a/objs/torchdemo/torchandroid.o:torchandroid.cpp:lualibs: error: undefined reference to 'luaopen_libnnx'
./obj/local/armeabi-v7a/objs/torchdemo/torchandroid.o:torchandroid.cpp:lualibs: error: undefined reference to 'luaopen_libimage'
jni/torchdemo.cpp:31: error: undefined reference to 'luaL_loadbuffer'
jni/torchdemo.cpp:31: error: undefined reference to 'lua_pcall'
jni/torchdemo.cpp:36: error: undefined reference to 'lua_tolstring'
jni/torchdemo.cpp:37: error: undefined reference to 'lua_tolstring'
jni/torchdemo.cpp:44: error: undefined reference to 'lua_close'
collect2: error: ld returned 1 exit status

The OS is Ubuntu

Many thanks

@chwangaa
Copy link
Author

Referring to issue #5 I found that the .a files are indeed not being compiled to the correct path. So I created the corresponding folder myself and copied the .a files to the directory.

However, now I get the following error:

tom@Tomi:~/Workspace/mnist/Week_2/torch-android/android-demo$ bash build.sh
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
Updated project.properties
Updated local.properties
Updated file ./proguard-project.txt
Android NDK: WARNING:jni/Android.mk:torchdemo: non-system libraries in linker flags: -lluaT -ltorch-lua-static -lTH -lnn -ltorch -lnnx -limage -limgraph -lluaT -ltorch-lua-static -lTH -lnn -ltorch -lnnx -limage -limgraph    
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES    
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the    
Android NDK:     current module    
[armeabi-v7a] Compile++ thumb: torchdemo <= torchandroid.cpp
[armeabi-v7a] Compile++ thumb: torchdemo <= torchdemo.cpp
In file included from jni/torchdemo.cpp:8:0:
jni/torchdemo.cpp: In function '_jstring* Java_com_torch_torchdemo_TorchDemo_callTorch(JNIEnv*, jobject, jobject)':
jni/torchandroid.h:19:78: warning: too many arguments for format [-Wformat-extra-args]
 #  define  D(x...)  __android_log_print(ANDROID_LOG_INFO,"torchdemo", "%s", x)
                                                                              ^
jni/torchdemo.cpp:35:7: note: in expansion of macro 'D'
       D("Error doing resource: %s\n", file);
       ^
[armeabi-v7a] SharedLibrary  : libtorchdemo.so
../lib//libnn.a(init.c.o):init.c:function nn_FloatSqrt_updateGradInput: error: undefined reference to 'GOMP_parallel'
../lib//libnn.a(init.c.o):init.c:function nn_FloatSquare_updateGradInput: error: undefined reference to 'GOMP_parallel'
../lib//libnn.a(init.c.o):init.c:function nn_FloatSquare_updateOutput: error: undefined reference to 'GOMP_parallel'
../lib//libnn.a(init.c.o):init.c:function nn_FloatHardTanh_updateGradInput: error: undefined reference to 'GOMP_parallel'
collect2: error: ld returned 1 exit status

@ZhengRui
Copy link

ZhengRui commented Jul 3, 2015

I got exactly the same error :(

solve it by add

-L/Users/myname/Work/Libs/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/lib

to the LOCAL_LDLIBS variable in jni/Android.mk file, so it can find libgomp.a library

@gokceneraslan
Copy link
Contributor

The thing is toolchain that is used by android-cmake and ndk-build must be the same. Here, android-cmake uses the latest GCC (arm-linux-androideabi-4.9) but ndk-build defaults to arm-linux-androideabi-4.8. The missing symbol GOMP_parallel is only available in GCC 4.9 and since static Torch libraries are compiled with GCC 4.9, we cannot build demo applications with GCC 4.8.

One workaround is to change

ndk-build

to

ndk-build NDK_TOOLCHAIN_VERSION=4.9

in build.sh files of demo applications.

@culurciello
Copy link
Collaborator

If you are looking for the easiest way to deploy on embedded, or Android or iOs, thnets now contains also an easy stripped-version of openBLAS, so it is really easy to compile it on embedded devices: https://github.com/mvitez/thnets. We highly recommend it

@soumith
Copy link
Owner

soumith commented Feb 15, 2016

should be fixed now in the build scripts.

@soumith soumith closed this as completed Feb 15, 2016
@manishcdac
Copy link

home/manish/samsung/p3100/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lsrv_init_SGX540_120
/home/manish/samsung/p3100/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lsrv_um_SGX540_120
hardware/ti/omap4/pvrsrvinit/pvrsrvinit.c:8: error: undefined reference to 'SrvInit'
collect2: error: ld returned 1 exit status
target Executable: r (/home/manish/samsung/p3100/out/target/product/p3100/obj/EXECUTABLES/r_intermediates/LINKED/r)
make: *** [/home/manish/samsung/p3100/out/target/product/p3100/obj/EXECUTABLES/pvrsrvinit_intermediates/LINKED/pvrsrvinit] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory `/home/manish/samsung/p3100'
how to solve plese help

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants