android cmake下的c ++编译错误

时间:2018-06-08 11:03:33

标签: android c++ android-ndk

我使用android studio编译c ++代码,我的ndk版本是android-ndk-r12b。在我的项目中,我在mp4muxer.h中定义了两个函数:

void Engine_create(const char *file, uint32_t flag);

void Engine_readFile(const char *file);

并在mp4muxer.cpp中实现,如下所示:

void Engine_readFile(const char *file, uint32_t flag) {


    MP4FileHandle handle = MP4Read(file);
    if (handle == MP4_INVALID_FILE_HANDLE) {
        __android_log_print(ANDROID_LOG_ERROR, TAG, "Create mp4 file failed invalid handle!");
        return;
    }
    MP4TrackId trackId = MP4FindTrackId(handle, 0, MP4_TEXT_TRACK_TYPE, 0);

    __android_log_print(ANDROID_LOG_ERROR, TAG, "Read trackId: %d", trackId);
    if (trackId == MP4_INVALID_TRACK_ID) {
        __android_log_print(ANDROID_LOG_ERROR, TAG, "Create mp4 file using mp4v2 library! invalid trackId: %d", trackId);
        return;
    }

    uint32_t count;
    uint8_t* data = (uint8_t * ) malloc((size_t)(10 * sizeof(uint8_t)));
    uint32_t sid = 1;
    while (MP4ReadSample(handle, trackId, sid++, &data, &count)) {

       int i;
       for (i = 0; i < 5; i++) {
           __android_log_print(ANDROID_LOG_ERROR, TAG, "value: %d", data[i]);
       }

    }

    MP4Close(handle);
}

void Engine_create(const char* file) {

    MP4FileHandle handle = MP4Create(file);
    if (handle == MP4_INVALID_FILE_HANDLE) {
        __android_log_print(ANDROID_LOG_ERROR, TAG, "Create mp4 file failed invalid handle!");
        return;
    }
    MP4TrackId trackId = MP4AddTextTrack(handle, 3);

    __android_log_print(ANDROID_LOG_ERROR, TAG, "Create trackId: %d", trackId);
    if (trackId == MP4_INVALID_TRACK_ID) {
        __android_log_print(ANDROID_LOG_ERROR, TAG, "Create mp4 file using mp4v2 library! invalid trackId: %d", trackId);
        return;
    }

    uint32_t count = 50;
    uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    while (count-- > 0) {

        MP4WriteSample(handle, trackId, data, 10);

    }

    MP4Close(handle);

}

并调用函数:

include <jni.h>

#include "../mp4muxer.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "../muxing.h"
#ifdef __cplusplus
}
#endif





static void MuxerEngine_engine(JNIEnv *env, jobject clazz, jstring fileName) {

    jboolean isCopy;
//    const char * cstr = env->GetStringUTFChars(fileName, &isCopy);
    const char * cstr = NULL;
    Engine_create(cstr, 0);
    env->ReleaseStringUTFChars(fileName, cstr);
}


static void MuxerEngine_read(JNIEnv *env, jobject clazz, jstring fileName) {

    jboolean isCopy;
    const char * cstr = env->GetStringUTFChars(fileName, &isCopy);
    Engine_readFile(cstr);
    env->ReleaseStringUTFChars(fileName, cstr);
}

但是当我编译编译时说:

  

错误:未定义引用&#39; Engine_create(char const *,unsigned   INT)&#39;错误:未定义引用&#39; Engine_readFile(char const *)&#39;

困惑我的是:我定义了函数:Engine_create(const char*, unsigned int)但得到了错误信息:

  

Engine_create(char const *,unsigned int),参数为       const char *但不是       char cont *

0 个答案:

没有答案