Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

为什么我拿ncnn编译出来的.a文件编译so的时候会报undefined reference to '__kmpc_fork_call'的错误 #292

Closed
zhangyanhbr opened this issue Mar 12, 2018 · 19 comments

Comments

@zhangyanhbr
Copy link

你好,我想请问一下:
我拿ncnn编译出来的.a文件,用ndk-build编译.so的时候会报
undefined reference to '__kmpc_fork_call'
undefined reference to '__kmpc_for_static_init_4'
undefined reference to '__kmpc_for_static_fini'
undefined reference to '__kmpc_for_static_init_4'
layer/convolutiondepthwise.cpp:176: error:undefined reference to '__kmpc_for_static_init_8'

@nihui
Copy link
Member

nihui commented Mar 12, 2018

LOCAL_CFLAGS += -fopenmp
LOCAL_CPPFLAGS += -fopenmp
LOCAL_LDFLAGS += -fopenmp

参考 https://github.com/Tencent/ncnn/blob/master/examples/squeezencnn/jni/Android.mk

@zhangyanhbr
Copy link
Author

你好,谢谢你的回复。但是我有点看不明白。您的意思是我少了这三行代码吗?我的Android.mk文件里有这三行代码的,是我少了什么库吗?

@zhangyanhbr
Copy link
Author

你好,还有一个问题,我编译出来的libncnn.a有4560KB,而你们给出的libncnn.a不到1000KB,请问是什么原因呢?我是按照https://github.com/Tencent/ncnn/wiki/how-to-build这里面的步骤进行编译的。如果方便请回复一下。

@nihui
Copy link
Member

nihui commented Mar 13, 2018

android ndk 自带的cmake toolchain自动加上了 -g 编译,把 toolchain cmake 里的 -g 删掉重新编译一次就小了

@nihui
Copy link
Member

nihui commented Mar 16, 2018

android ndk 版本用 r15c 或者更新的

@suguliwei
Copy link

请问解决了吗?我也是碰到了同样的问题,build.sh发生了变化,现在用的是ndk自带的toolchain cmake,请问在编译的时候需要修改toolchain cmake里面的内容以支持openmp吗?

@zhangyanhbr
Copy link
Author

我没有修改toolchain cmake里面的东西,我修改了.build.sh里面的东西就编译ok了。

@nihui
Copy link
Member

nihui commented Mar 19, 2018

新版使用了 android-ndk clang 编译器编译,openmp 运行时库对应于 libomp.a

@bobby-chiu
Copy link

@nihui, can be the ncnn static library libncnn.a compiled with APP_STL :=c++_static . The released version is compiled with gnustl_static?

@bobby-chiu
Copy link

@nihui, when i was packing libncnn.a into shared library with other libraries by settings stl as c++_static. it threw errors like:
/home/nihui/osd/ncnn/src/modelbin.cpp:(.text._ZNSt6vectorIhSaIhEE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPhS1_EEmRKh[_ZNSt6vectorIhSaIhEE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPhS1_EEmRKh]+0x1bc): undefined reference to `std::__throw_length_error(char const*)'.
This seems like gnustl dependencies

@bobby-chiu
Copy link

these errors were fixed by rebuilt ncnn library with c++_static stl.

@adong7639
Copy link

adong7639 commented Mar 23, 2018

open Application.mk

#APP_STL := stlport_static
APP_STL := gnustl_static
#APP_ABI := armeabi armeabi-v7a
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9

NDK_TOOLCHAIN_VERSION := 4.9

I solve this error like this:

NDK_TOOLCHAIN_VERSION := 4.9 >>>>> #NDK_TOOLCHAIN_VERSION := 4.9

@Victcode
Copy link

@nihui, 我用新版本出现类似的错误
Error:error: ld returned 1 exit status
Error:error: undefined reference to '__kmpc_fork_call'

我使用的是Android studio的cmake方式进行调用,请问如何解决,具体的指令我没有找到

@nihui nihui closed this as completed in 4019505 Mar 30, 2018
@suesunna
Copy link

it has .so file after commend this line

#NDK_TOOLCHAIN_VERSION := 4.9

@maxlchina
Copy link

but after commented NDK_TOOLCHAIN_VERSION := 4.9, the .so will be Invalid

@liujhjack
Copy link

你好,谢谢你的回复。但是我有点看不明白。您的意思是我少了这三行代码吗?我的Android.mk文件里有这三行代码的,是我少了什么库吗?

我这边也是添加了这三行code,还是不行,请问你是怎么解决的呢?

@liujhjack
Copy link

LOCAL_CFLAGS + = -fopenmp
LOCAL_CPPFLAGS + = -fopenmp
LOCAL_LDFLAGS + = -fopenmp

参考https://github.com/Tencent/ncnn/blob/master/examples/squeezencnn/jni/Android.mk

我添加了这个,还是报错,是需要openmp这个库吗?

@CyberKnight001
Copy link

我没有修改toolchain cmake里面的东西,我修改了.build.sh里面的东西就编译ok了。

你好,请问怎么修改呢,谢谢啊

@lvpchen
Copy link

lvpchen commented Apr 11, 2020

these errors were fixed by rebuilt ncnn library with c++_static stl.

@bobby-chiu
hello, if i want to rebuilt ncnn library with c++_static stl, what i need to modify?
than you

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

No branches or pull requests