1

我有这个 cpp 文件:

//pkgnative_tries__native_NativeSystem.cpp
#include <pkgnative_tries__native_NativeSystem.h>
#include<iostream>
using namespace std;

extern "C"
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobject obj, jstring javaString)
{
    //Get the native string from javaString
    const char *nativeString = env->GetStringUTFChars(javaString, 0);
    cout << nativeString;

    env->ReleaseStringUTFChars(javaString, nativeString);
}

pkgnative_tries__native_NativeSystem.h:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class pkgnative_tries__native_NativeSystem */

#ifndef _Included_pkgnative_tries__native_NativeSystem
#define _Included_pkgnative_tries__native_NativeSystem
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     pkgnative_tries__native_NativeSystem
 * Method:    println
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_pkgnative_tries__1native_NativeSystem_println
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif

问题是,当我尝试将其编译为 DLL 时g++,它说:

g++ -c -DBUILDING_EXAMPLE_DLL pkgnative_tries__native_NativeSystem.cpp

pkgnative_tries__native_NativeSystem.cpp:1:50: fatal error: pkgnative_tries__native_NativeSystem.h: No such file or directory
compilation terminated

有谁知道为什么?我确定这两个文件都在同一个目录中

4

1 回答 1

7

当您在包含(例如#include <xyz>)中使用尖括号时,它不会在包含完成的目录中查找。请改用双引号,例如#include "xyz".

于 2013-09-16T16:24:28.257 回答