Maratyszcza / NNPACK

Acceleration package for neural networks on multi-core CPUs
BSD 2-Clause "Simplified" License
1.68k stars 316 forks source link

build error with enable-shared #144

Closed kaishijeng closed 6 years ago

kaishijeng commented 6 years ago

Run "cmake .. -G Ninja -DBUILD_SHARED_LIBS=ON" and then ninja, got the following error: My platform is armv8 (A72)

[56/60] Linking C shared library deps/cpuinfo/libcpuinfo.so FAILED: deps/cpuinfo/libcpuinfo.so : && /usr/bin/cc -fPIC -shared -Wl,-soname,libcpuinfo.so -o deps/cpuinfo/libcpuinfo.so deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/init.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/api.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/uarch.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/cache.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/init.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/cpuinfo.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/clusters.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/chipset.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/midr.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/hwcap.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/arm/linux/aarch64-isa.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/linux/smallfile.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/linux/multiline.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/linux/current.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/linux/cpulist.c.o deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/linux/processors.c.o -pthread deps/cpuinfo/deps/clog/libclog.a && : /usr/bin/ld: deps/cpuinfo/deps/clog/libclog.a(clog.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol __stack_chk_guard@@GLIBC_2.17' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: deps/cpuinfo/deps/clog/libclog.a(clog.c.o)(.text+0x1c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol__stack_chk_guard@@GLIBC_2.17' /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status [59/60] Building C object CMakeFiles/nnpack.dir/src/psimd/2d-fourier-16x16.c.o ninja: build stopped: subcommand failed.

Any idea why this happens. If I disablle enable-shared, then build is OK

Thanks,

Maratyszcza commented 6 years ago

This is because clog is built as a static library (non-PIC), but linked into cpuinfo (NNPACK dependency), which is built as a dynamic library. You can additionally specify -DCMAKE_POSITION_INDEPENDENT_CODE=ON to build all dependencies as position-independent code that can be linked into a shared library.

Also, keep in mind that -DBUILD_SHARED_LIBS=ON will build NNPACK and all its dependencies as shared libraries. If you want NNPACK as a shared library with all its dependencies linked into it as static libraries, use -DNNPACK_LIBRARY_TYPE="shared" instead.

Maratyszcza commented 6 years ago

cpuinfo always builds clog as PIC since pytorch/cpuinfo@91e2aadbe424a43aaac3e3896fb7b21e83d4561e