2017-07-03 22 views
2

每當您在Android Studio中遇到鏈接器錯誤時,都建議您使用-v來查看調用,但是在哪裏放置-v命令獲得「詳細輸出」(according to llvm clang command guide)?如何使用-ng在clang中獲取未定義引用錯誤的詳細輸出(Android-Studio)

已經嘗試過:

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

未在輸出進行任何更改,據我注意到和

--stacktrace --debug

Settings > Compiler > Command-line Options 

這是顯示方式更多的輸出,但不是我在找什麼!
非常感謝您的幫助!

編輯

,因爲我編譯C文件,我顯然不得不使用CFLAGS。現在gradle這個文件看起來如下(感謝@Alex科恩):

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

在幾個C-類我沒有注意到它們不具有添加以下預處理器指令它,我能擺脫我的鏈接錯誤關於丟失的引用:

#ifdef __cplusplus 
extern "C" 
{ 
#endif 

// your includes and your code here 

#ifdef __cplusplus 
} 
#endif 
+0

你試過'cppFlags「-frtti」,「-fexceptions」,「-v」'? –

+0

剛剛嘗試沒有任何成功。 cppFlags「-frtti -fexceptions」是自動生成的,我只添加了-v那裏btw –

+1

這很奇怪;實際上,對於我來說,用逗號分隔的列表和帶空格的引號字符串都是可行的。你應該檢查你的'app/.externalNativeBuild/cmake/debug/armeabi-v7a/android_gradle_build.json'文件。但我有一個假設:也許你正在編譯一個C文件? –

回答

1
  1. cppFlags "-frtti -fexceptions -v"作品,以及cppFlags "-frtti", "-fexceptions", "-v" for 鏗鏘++任務,即得到詳細輸出爲.cpp.cxx文件編譯。

  2. cFlags "-v"工作產生詳細輸出爲.c文件編譯。

  3. 爲了生產用於鏈接步驟的詳細輸出,編輯您的CMakeLists.txt文件,添加-v到相關target_link_libraries語句,例如

    target_link_libraries(myjnilib android log -v) 
    
  4. 上述所有可能沒有足夠的理解和固定未定義參考錯誤。
+1

In我的情況下,鏈接器錯誤是在幾個C文件中丟失的預處理器命令(請參閱我的答案中的更新2)。我需要該命令,因爲我使用Android Studio創建的默認.cpp文件作爲我的Java接口class ...非常感謝您的幫助和時間@Alex Cohn –

+0

還有什麼幫助我將「--debug」設置爲設置>構建,執行,部署(AS 3.0)中的命令行選項。能夠看到一些缺失的鏈接器引用 - 考慮將其添加到列表中 –

相關問題