Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:25:05+00:00 2026-06-12T07:25:05+00:00

I have a native library for Android that has some files that include NEON

  • 0

I have a native library for Android that has some files that include NEON assembly code. I’ve inherited this code from some other coder, and given my knowledge regarding NEON assembly coding (or any assembly, for that matter) is skimpy, to say the least. Anyhow, I’ve noticed the following problem: when I compile with ‘ndk-build NDK_DEBUG=1’, all is fine. When I compile for release, ‘ndk-build NDK_DEBUG=0’, the compiler optimizes away the assembly code. I’ve managed to work around the problem by hacking the ndk build scripts, and splitting my library into two, where one lib has all the assembly files in it – for this lib I set optimization to ‘-O0’ in a very hacky way.
So the question is: how can I specify an optimization level for a specific file? setting APP_OPTIM is done in Application.mk, that affects all the compiled files. So does the NDK_DEBUG flag.

EDIT: as per Alex’s request, here’s the Android.mk I ended up using, splitting the lib into two: one part with assembly code (and -O0), other part with regular C code (and -O2):

LOCAL_PATH := $(call my-dir)

# assembly_neon_code_here (neon) module - turn optimization off
include $(CLEAR_VARS)

LOCAL_MODULE := assembly_neon_code_here
LOCAL_SRC_FILES := assembly_neon_code_here.cpp
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    LOCAL_ARM_NEON := true
endif

LOCAL_CFLAGS := -O0
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog 
include $(BUILD_SHARED_LIBRARY)

# main module
include $(CLEAR_VARS)

LOCAL_MODULE    := complete_lib
LOCAL_SRC_FILES := regular_src1.cpp regular_src2.cpp regular_src3.cpp 
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    LOCAL_ARM_NEON := true
endif

# allow logcat calls
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
LOCAL_SHARED_LIBRARIES := assembly_neon_code_here
include $(BUILD_SHARED_LIBRARY)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:25:06+00:00Added an answer on June 12, 2026 at 7:25 am

    GCC >= 4.4 seems to support #pragma GCC optimize to change the optimization level mid-file, and also attribute optimize to set it per function.

    See http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Function-Specific-Option-Pragmas.html#Function-Specific-Option-Pragmas and http://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Function-Attributes.html#Function-Attributes.

    According to those links, putting #pragma GCC optimize ("O0") at the top of the file causing the problem should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android java library that uses some native code. I have added
This is probably a multi-part question. Background: we have a native (c++) library that
so I have some 3rd party native library that works only in 32 bit
I have a managed dll that calls into a native library. This native library
I am developing an Android application which uses some native code. The native library
I'm beginning with android NDK. I have to compile a native library for the
I have to include a static native library (dsplink.a) which uses System V IPCs
I have a native object (C++) that has a gcroot pointer to a managed
I am developing a library for Android applications which does not use native code
I'm porting to Android. My existing project has a ton of resource files that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.