2013-07-30 112 views
0

當我在終端運行NDK建造我下面的下面的教程 http://taylorpeer.com/hello-world-cpp-android-ndk/NDK-生成錯誤而將源代碼編譯

。我收到以下錯誤

Compile++ thumb : hello-jni <= hello-jni.cpp 
jni/hello-jni.cpp:4:5: error: stray '\342' in program 
jni/hello-jni.cpp:4:5: error: stray '\200' in program 
jni/hello-jni.cpp:4:5: error: stray '\234' in program 
jni/hello-jni.cpp:4:5: error: stray '\342' in program 
jni/hello-jni.cpp:4:5: error: stray '\200' in program 
jni/hello-jni.cpp:4:5: error: stray '\235' in program 
jni/hello-jni.cpp:9:17: error: stray '\342' in program 
jni/hello-jni.cpp:9:17: error: stray '\200' in program 
jni/hello-jni.cpp:9:17: error: stray '\234' in program 
jni/hello-jni.cpp:9:17: error: stray '\342' in program 
jni/hello-jni.cpp:9:17: error: stray '\200' in program 
jni/hello-jni.cpp:9:17: error: stray '\235' in program 
jni/hello-jni.cpp:4:15: error: 'C' does not name a type 
make: *** [obj/local/armeabi/objs/hello-jni/hello-jni.o] Error 1 

下面是我的文件

Java文件中src文件夾

發現列表中。

package com.example; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

    public class Hellojnicpp extends Activity { 
      /** Called when the activity is first created. */ 
      @Override 
      public void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       /** Create a TextView and set it to display 
       * text loaded from a native method. 
       */ 
       TextView tv = new TextView(this); 
       tv.setText(stringFromJNI()); 
       setContentView(tv); 
      } 
      /** A native method that is implemented by the 
      * ‘hello-jni’ native library, which is packaged 
      * with this application. 
      */ 
      public native String stringFromJNI(); 
      /** Load the native library where the native method 
      * is stored. 
      */ 
      static { 
       System.loadLibrary("hello-jni"); 
      } 
    } 

Android.mk文件

LOCAL_PATH := $(call my-dir) 


include $(CLEAR_VARS) 
LOCAL_LDLIBS := -llog 

LOCAL_MODULE := hello-jni 
LOCAL_SRC_FILES := hello-jni.cpp 

include $(BUILD_SHARED_LIBRARY) 

.cpp文件

#include <string.h> 
#include <jni.h> 

    extern 「C」 { 
      JNIEXPORT jstring JNICALL 
      Java_com_example_Hellojnicpp_stringFromJNI 
      (JNIEnv *env, jobject obj) 
      { 
       return env->NewStringUTF(「Hello from C++ over JNI!」); 
      } 
    } 

請幫我修復錯誤已經從過去的72個小時 搜索網謝謝ñ推進

現在改變「C」爲 「C」 後,收到以下錯誤

Compile++ thumb : hello-jni <= hello-jni.cpp 
jni/hello-jni.cpp:9:17: error: stray '\342' in program 
jni/hello-jni.cpp:9:17: error: stray '\200' in program 
jni/hello-jni.cpp:9:17: error: stray '\234' in program 
jni/hello-jni.cpp:9:17: error: stray '\342' in program 
jni/hello-jni.cpp:9:17: error: stray '\200' in program 
jni/hello-jni.cpp:9:17: error: stray '\235' in program 
jni/hello-jni.cpp: In function '_jstring* Java_com_example_Hellojnicpp_stringFromJNI(JNIEnv*, jobject)': 
jni/hello-jni.cpp:9:45: error: 'Hello' was not declared in this scope 
make: *** [obj/local/armeabi/objs/hello-jni/hello-jni.o] Error 1 
+0

你對字符串的報價也是錯誤的。我已經在我的答案中解決了它。嘗試它 – yushulx

回答

2

檢查你的 「」:

#include <string.h> 
#include <jni.h> 

    extern "C" { 
      JNIEXPORT jstring JNICALL 
      Java_com_example_Hellojnicpp_stringFromJNI 
      (JNIEnv *env, jobject obj) 
      { 
       return env->NewStringUTF("Hello from C++ over JNI!"); 
      } 
    } 
1
extern 「C」 

應該

extern "C" 

即沒有 「花」 引號。確保你的文本編輯器不會「美化」你的直接引號。

+0

更改外部「C」到「C」,現在得到不同的錯誤 –

+0

請檢查我的最新錯誤,並幫助 –

+0

嗯,讓我們看看,你有一個錯誤的捲曲報價行。我告訴過你不要在該行中使用卷積引號,並且在*另一個*行中還有一個非常類似的錯誤,該行也包含卷積引號。我可以恭敬地建議你可能還沒有足夠的編程經驗來有效地使用Android NDK? – wolfgang