Ncnn: linux x86上跑example

Created on 6 Sep 2018  ·  5Comments  ·  Source: Tencent/ncnn

x86上很容易把ncnn编译成功,在build目录下生成include 和 libncnn.a文件
照着例子写了个在x86上进行推理程序,但是,无法生成可执行文件啊

g++ -o stand_alone stand_alone.cpp -I/home/code/ncnn-master/build/install/include/ -L/home//code/ncnn-master/build/install/lib -lncnn -static

报了一堆符号未定义的错误。。。

dequantize.cpp:(.text+0xcc8): undefined reference to GOMP_parallel' dequantize.cpp:(.text+0xd0e): undefined reference toGOMP_parallel'
dequantize.cpp:(.text+0xd61): undefined reference to GOMP_parallel' dequantize.cpp:(.text+0xd78): undefined reference toGOMP_parallel'
dequantize.cpp:(.text+0xdaa): undefined reference to `GOMP_parallel'

mat.cpp:(.text+0x1235): undefined reference to GOMP_parallel' mat.cpp:(.text+0x125a): undefined reference toGOMP_parallel'
mat.cpp:(.text+0x1284): undefined reference to `GOMP_parallel'

convolutiondepthwise.cpp:(.text+0x1b2): undefined reference to omp_get_num_threads' convolutiondepthwise.cpp:(.text+0x1b9): undefined reference toomp_get_thread_num

求指教。

Most helpful comment

在CMakeLists.txt加入OpenMP依赖:
FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

All 5 comments

是要依赖哪个库么?

搞定了,关闭。

请问你是怎么解决这个问题的?

在CMakeLists.txt加入OpenMP依赖:
FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

@nidetaoge @xhappy 我也遇到了同样的问题,不过我在build ncnn.a的时候找到了OpenMP.

-- CMAKE_INSTALL_PREFIX = /home/karl/Documents/work_code/py/ncnn/build/install
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")

但我在build inference cpp的时候, 也遇到了楼主的问题, 出现一堆没找到

/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(cpu.cpp.o): In function `ncnn::get_omp_num_threads()':
cpu.cpp:(.text+0x61): undefined reference to `omp_get_num_threads'
/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(cpu.cpp.o): In function `ncnn::set_omp_num_threads(int)':
cpu.cpp:(.text+0x71): undefined reference to `omp_set_num_threads'
/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(cpu.cpp.o): In function `ncnn::get_omp_dynamic()':
cpu.cpp:(.text+0x81): undefined reference to `omp_get_dynamic'
/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(cpu.cpp.o): In function `ncnn::set_omp_dynamic(int)':
cpu.cpp:(.text+0x91): undefined reference to `omp_set_dynamic'
/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(cpu.cpp.o): In function `_GLOBAL__sub_I_cpu.cpp':
cpu.cpp:(.text.startup+0x5): undefined reference to `omp_get_max_threads'
/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(mat.cpp.o): In function `ncnn::Mat::substract_mean_normalize(float const*, float const*) [clone ._omp_fn.1]':
mat.cpp:(.text+0x16): undefined reference to `omp_get_num_threads'
mat.cpp:(.text+0x1e): undefined reference to `omp_get_thread_num'
/home/karl/Documents/work_code/py/ncnn/build/install/lib/libncnn.a(mat.cpp.o): In function `ncnn::Mat::substract_mean_normalize(float const*, float const*) [clone ._omp_fn.0]':
mat.cpp:(.text+0x216): undefined reference to `omp_get_num_threads'
mat.cpp:(.text+0x21e): undefined reference to `omp_get_thread_num'

请问如何解决

谢谢

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mychina75 picture mychina75  ·  4Comments

Abel119 picture Abel119  ·  4Comments

sbsb99 picture sbsb99  ·  4Comments

varbegin picture varbegin  ·  3Comments

soham24 picture soham24  ·  3Comments