Eclipse之NDK編譯——常見錯誤的解決方案記錄

來源:互聯網
上載者:User

標籤: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編譯——常見錯誤的解決方案記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.