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

编译arm-linux时为何编译的却是x86 #674

Closed
bigbao9494 opened this issue Nov 28, 2018 · 4 comments
Closed

编译arm-linux时为何编译的却是x86 #674

bigbao9494 opened this issue Nov 28, 2018 · 4 comments

Comments

@bigbao9494
Copy link

我在一个arm平台下编译(全志,非android)
发现它编译的是src/layer/x86而不是src/layer/arm
但是我编译Android版本时却是正常的,不知道需要怎样修改才能编译出arm版本呢???
下面是编译打印:
[ 24%] Building CXX object src/CMakeFiles/ncnn.dir/layer/x86/convolution_x86.cpp.obj
In file included from /home/ncnn-master_20181128_cross/src/layer/x86/convolution_x86.cpp:19:0:

@nihui
Copy link
Member

nihui commented Nov 29, 2018

参考 #28
或者参考 pi3.toolchain.cmake

@nihui nihui closed this as completed Nov 29, 2018
@bigbao9494
Copy link
Author

@nihui
你好
我尝试了#28中的方法,仍然不行,以下是我尝试的方法不知道是否正确:
我使用的芯片是全志的H2
1、
新建一个arm.toolchan.cmake
SET(CMAKE_SYSTEM_NANE Android)
SET(CMAKE_SYSTEM_PROCESSOR "armv7-a")
SET(ANDROID_ARCH_NAME "arm")
SET(ANDROID true)
SET(CMAKE_C_COMPILER "arm-cortexa9-linux-gnueabihf-gcc")
SET(CMAKE_CXX_COMPILER "arm-cortexa9-linux-gnueabihf-g++")
然后:mkdir arm;cd arm;cmake -DCMAKE_TOOLCHAIN_FILE=../arm.toolchain.cmake ..;make -j2
2、
直接修改CMakeLists.txt,全部文件内容如下(注释为ljy的是我添加的内容):
if(CMAKE_TOOLCHAIN_FILE)
set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to")

get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :(

get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME)
find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()

if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
endif()
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")

cmake_minimum_required(VERSION 2.8.10)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE)
endif()

set(COVERAGE OFF CACHE BOOL "Coverage")

project(ncnn)

option(NCNN_OPENMP "openmp support" ON)
option(NCNN_STDIO "load model from external file" ON)
option(NCNN_STRING "plain and verbose string" ON)
option(NCNN_OPENCV "minimal opencv structure emulation" OFF)
option(NCNN_BENCHMARK "print benchmark information for every layer" OFF)
option(NCNN_PIXEL "convert and resize from/to image pixel" ON)
option(NCNN_PIXEL_ROTATE "rotate image pixel orientation" OFF)
option(NCNN_CMAKE_VERBOSE "print verbose cmake messages" OFF)

if(NCNN_OPENMP)
find_package(OpenMP)
# For CMake < 3.9, we need to make the target ourselves
if(NOT TARGET OpenMP::OpenMP_CXX)
find_package(Threads REQUIRED)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
endif()

if(WIN32)
add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-DNOMINMAX)
else()

add_definitions(-Wall -Wextra -Wno-unused-function)

add_definitions(-fPIC)
if(CMAKE_BUILD_TYPE MATCHES "(Release|RELEASE|release)")
    add_definitions(-Ofast)

    add_definitions(-ffast-math)
endif()

if(PI3)
    add_definitions(-march=native)
    add_definitions(-mfpu=neon)
    add_definitions(-mfloat-abi=hard)
    add_definitions(-D__ARM_NEON)
    add_definitions(-D__ANDROID__)
endif()
# add_definitions(-march=native)
# add_definitions(-flto)
add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)

endif()

if(ANDROID)
#if(TRUE) #ljy modify
# disable shared library on android
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
elseif(IOS)
# disable shared library on xcode ios
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
endif()

##############################################

add_subdirectory(examples)

add_subdirectory(benchmark)

add_subdirectory(src)
if(NOT ANDROID AND NOT IOS)
add_subdirectory(tools)
endif()

add_definitions(-mfpu=neon)#ljy added.
add_definitions(-march=native)#ljy added.
add_definitions(-mfloat-abi=hard)#ljy added.
add_definitions(-D__ARM_NEON)#ljy added.

@bigbao9494
Copy link
Author

@nihui 我git clone最新的NCNN没有找到pi3.toolchain.cmake这个文件呢?
里面只有3个iosxxx.toolchain.cmake啊?

@nihui
Copy link
Member

nihui commented Nov 29, 2018

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

2 participants