Search code examples
androidandroid-studioandroid-ndkclang

How to get verbose output for undefined reference error using -v in clang (Android-Studio)


Whenever you get a linker error in Android Studio it suggests you to use -v to see invocation, but where to put the -v command to get the "verbose output" (according to llvm clang command guide)?

Already tried:

externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions -v"
            }
        }

which is not changing anything in the output as far as i noticed and

--stacktrace --debug

in

Settings > Compiler > Command-line Options  

Which is showing way more output but not what I am looking for!
Thank you very much for your help in advance!

EDIT

Since i am compiling C files i obviously had to use cFlags. Now the gradle file looks as follows (thx to @Alex Cohn):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "<my_id>"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cFlags "-v"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    testCompile 'junit:junit:4.12'
}

EDIT 2

Adding following pre-processor command in a few C-classes i did not notice they were missing it, i was able to get rid of my linker error about the missing reference:

#ifdef __cplusplus
extern "C"
{
#endif   

// your includes and your code here

#ifdef __cplusplus
}
#endif

Solution

    1. cppFlags "-frtti -fexceptions -v" works as well as cppFlags "-frtti", "-fexceptions", "-v" for clang++ tasks, that is, to get verbose output for .cpp or .cxx files compilation.

    2. cFlags "-v" works to produce verbose output for .c files compilation.

    3. To produce verbose output for link step, edit your CMakeLists.txt file, add -v to the relevant target_link_libraries statement, e.g.

      target_link_libraries(myjnilib android log -v)
      
    4. All above may not be enough to understand and fix undefined reference error.