標籤:eclipse ndk c c++
在工程目錄下的jni檔案夾下編寫的c/c++代碼在編譯時間,通常會遇到如下的幾種類型錯誤:
1、Unresolved inclusion:<XXX>
2、syntax error
3、Function ‘XXX‘ could not be resolved
4、Type ‘XXX‘ could not be resolved
5、Symbol ‘XXX‘ could not be resolved
6、Method ‘XXX‘ could not be resolved
7、Invalid arguments ‘Candidates are: ...‘
錯誤原因:
大多數情況是因為相關標頭檔沒有加入導致,也有一些是因為一些參數無效導致的(當然無效參數也可能是因為標頭檔未加入,見下述)。
相關錯誤解決方案——添加標頭檔:
錯誤內容一:
1、Unresolved inclusion: <jni.h>、Unresolved inclusion: <stdio.h>、Unresolved inclusion: <malloc.h>、Unresolved inclusion: <android/log.h>、...
2、Function ‘__android_log_print‘ could not be resolved、Type ‘JNIEnv‘ could not be resolved、Type ‘jstring‘ could not be resolved、Type ‘jclass‘ could not be resolved、Function ‘malloc‘ could not be resolved、Function ‘memcpy‘ could not be resolved、Method ‘FindClass‘ could not be resolved、Type ‘jsize‘ could not be resolved、Symbol ‘NULL‘ could not be resolved、...
解決方案:
右擊項目 --> Properties --> 左側C/C++ General --> Paths and Symbols --> 右側Includes --> GNU C++(.cpp) --> Add
| __>GNU C(.c) __|
${NDKROOT}\platforms\android-18\arch-arm\usr\include
錯誤內容二:
1、Unresolved inclusion: <iostream>、Unresolved inclusion: <fstream>、Symbol ‘std‘ could not be resolved、..
2、Type ‘fstream‘ could not be resolved、Symbol ‘in‘ could not be resolved、Method ‘seekg‘ could not be resolved、Method ‘read‘ could not be resolved、...
解決方案:
添加路徑(步驟見上述解決方案):
${NDKROOT}\sources\cxx-stl\gnu-libstdc++\4.8\include 、${NDKROOT}\sources\cxx-stl\gnu-libstdc++\4.8\libs\armeabi\include
錯誤內容三:
Invalid arguments ‘Candidates are:void * malloc(?)‘、Invalid arguments ‘Candidates are:void * memcpy(void *, const void *, ?)‘
解決方案:
添加路徑(步驟見上述解決方案):
${NDKROOT}\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.8\include
相關錯誤解決方案——符號替換:
有時編譯時間會遇到這樣的錯誤提示:Invalid arguments ‘Candidates are:std::basic_istream<char,std::char_traits<char>> & read(char *, ?)‘,儘管我們添加了相應的標頭檔,但仍然有無效參數這樣的錯誤,錯誤提示中的‘?’表示無效參數。
碰到這類錯誤,可以索引到對應函數(ctrl+點擊該函數)read,查看函數定義中的參數類型,此函數索引到的標頭檔中的參數類型為streamsize,但使用時用到的long。
解決方案:
右擊項目 --> Properties --> 左側C/C++ General --> Paths and Symbols --> 右側Symbols --> GNU C++(.cpp) --> Add
| __>GNU C(.c) __|
Name的值:streamsize,Value的值:long
添加完成後,點擊確定後,錯誤消失。
Eclipse之NDK編譯——常見錯誤的解決方案記錄