0

我想在 Windows 中为 Java 创建一个库。

在 Ubuntu 中编译的代码和 make.so库。

但是当我在 Windows 中编译 C 代码时,会出现以下错误。

D:\WorkSpace\LogReceiver\jni>gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -shared -o JavaImp.dll amr-nb-jni.c
amr-nb-jni.c: In function 'Java_XXX_logic_voice_vocoder_AMRNB_EIFamrnbencode':
amr-nb-jni.c:74:5: warning: pointer targets in passing argument 3 of 'E_IF_amrnb_encode' differ in signedness [-Wpointer
-sign]
amrnb_if.h:59:8: note: expected 'UWord8 *' but argument is of type 'jbyte *'
amr-nb-jni.c:74:5: warning: passing argument 4 of 'E_IF_amrnb_encode' from incompatible pointer type [enabled by default
]
amrnb_if.h:59:8: note: expected 'Word32 *' but argument is of type 'jint *'
amr-nb-jni.c: In function 'Java_XXX_logic_voice_vocoder_AMRNB_EIFamrnbqueryBlockSize':
amr-nb-jni.c:94:5: warning: passing argument 1 of 'E_IF_amrnb_queryBlockSize' from incompatible pointer type [enabled by
 default]
amrnb_if.h:67:6: note: expected 'Word32 *' but argument is of type 'jint *'
amr-nb-jni.c: In function 'Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbdecode':
amr-nb-jni.c:138:5: warning: pointer targets in passing argument 2 of 'D_IF_amrnb_decode' differ in signedness [-Wpointe
r-sign]
amrnb_if.h:75:8: note: expected 'UWord8 *' but argument is of type 'jbyte *'
amr-nb-jni.c: In function 'Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbqueryBlockSize':
amr-nb-jni.c:157:5: warning: passing argument 1 of 'D_IF_amrnb_queryBlockSize' from incompatible pointer type [enabled b
y default]
amrnb_if.h:82:6: note: expected 'Word32 *' but argument is of type 'jint *'
amr-nb-jni.c: In function 'Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbgetFrameProperties':
amr-nb-jni.c:177:5: warning: pointer targets in passing argument 1 of 'D_IF_amrnb_getFrameProperties' differ in signedne
ss [-Wpointer-sign]
amrnb_if.h:86:8: note: expected 'UWord8 *' but argument is of type 'jbyte *'
amr-nb-jni.c:177:5: warning: passing argument 2 of 'D_IF_amrnb_getFrameProperties' from incompatible pointer type [enabl
ed by default]
amrnb_if.h:86:8: note: expected 'Word32 *' but argument is of type 'jint *'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x49): undefined reference to `E_IF_amrnb_init'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x189): undefined reference to `E_IF_amrnb_encode'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x287): undefined reference to `E_IF_amrnb_queryBloc
kSize'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x300): undefined reference to `D_IF_amrnb_init'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x401): undefined reference to `D_IF_amrnb_decode'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x4d3): undefined reference to `D_IF_amrnb_queryBloc
kSize'
C:\Users\xxx~1\AppData\Local\Temp\ccYB8RmO.o:amr-nb-jni.c:(.text+0x58b): undefined reference to `D_IF_amrnb_getFrameP
roperties'
collect2: ld returned 1 exit status

C源是:

#include "jni.h"
#include "typedef.h"
#include "amrnb_if.h"

JNIEXPORT jint
Java_XXX_logic_voice_vocoder_AMRNB_EIFamrnbinit( JNIEnv*  env, jobject this,
                                                 jintArray hState,
                                                 jint iEnableVAD
                                                 )
{
    jint *p0;

    p0 = (*env)->GetIntArrayElements(env, hState, 0);
    if (p0 == 0)  return 1;

    E_IF_amrnb_init(p0, iEnableVAD);

    (*env)->ReleaseIntArrayElements(env, hState, p0, 0);

    return 0;
}

JNIEXPORT  jint
Java_XXX_logic_voice_vocoder_AMRNB_EIFamrnbencode( JNIEnv*  env, jobject this,
                                                 jintArray hState,
                                                 jshortArray pSpeech,
                                                 jbyteArray pBitstream,
                                                 jintArray iOutputSize,
                                                 jint iMode
                                                 )
{
    jint *p0;
    jshort *p1;
    jbyte *p2;
    jint *p3;
    jint errCode;

    p0 = (*env)->GetIntArrayElements(env, hState, 0);
    if (p0 == 0)  return 1;
    p1 = (*env)->GetShortArrayElements(env, pSpeech, 0);
    if (p1 == 0)  return 1;
    p2 = (*env)->GetByteArrayElements(env, pBitstream, 0);
    if (p2 == 0)  return 1;
    p3 = (*env)->GetIntArrayElements(env, iOutputSize, 0);
    if (p3 == 0)  return 1;


    errCode = E_IF_amrnb_encode(p0, p1, p2, p3, iMode);

    (*env)->ReleaseIntArrayElements(env, hState, p0, 0);
    (*env)->ReleaseShortArrayElements(env, pSpeech, p1, 0);
    (*env)->ReleaseByteArrayElements(env, pBitstream, p2, 0);
    (*env)->ReleaseIntArrayElements(env, iOutputSize, p3, 0);

    return errCode;
}

JNIEXPORT  jint
Java_XXX_logic_voice_vocoder_AMRNB_EIFamrnbqueryBlockSize( JNIEnv*  env, jobject this,
                                                 jintArray iSize
                                                 )
{
    jint *p0;

    p0 = (*env)->GetIntArrayElements(env, iSize, 0);
    if (p0 == 0)  return 1;

    E_IF_amrnb_queryBlockSize(p0);

    (*env)->ReleaseIntArrayElements(env, iSize, p0, 0);

    return 0;
}

 JNIEXPORT jint
Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbinit( JNIEnv*  env, jobject this,
                                                 jintArray hState
                                                 )
{
    jint *p0;

    p0 = (*env)->GetIntArrayElements(env, hState, 0);
    if (p0 == 0)  return 1;

    D_IF_amrnb_init(p0);

    (*env)->ReleaseIntArrayElements(env, hState, p0, 0);

    return 0;
}

JNIEXPORT  jint
Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbdecode( JNIEnv*  env, jobject this,
                                                 jintArray hState,
                                                 jbyteArray pBitstream,
                                                 jshortArray pSpeech,
                                                 jint iBadFrame
                                                 )
{
    jint *p0;
    jbyte *p1;
    jshort *p2;
    jint errCode;

    p0 = (*env)->GetIntArrayElements(env, hState, 0);
    if (p0 == 0)  return 1;
    p1 = (*env)->GetByteArrayElements(env, pBitstream, 0);
    if (p1 == 0)  return 1;
    p2 = (*env)->GetShortArrayElements(env, pSpeech, 0);
    if (p2 == 0)  return 1;

    errCode = D_IF_amrnb_decode(p0, p1, p2, iBadFrame);

    (*env)->ReleaseIntArrayElements(env, hState, p0, 0);
    (*env)->ReleaseByteArrayElements(env, pBitstream, p1, 0);
    (*env)->ReleaseShortArrayElements(env, pSpeech, p2, 0);

    return errCode;
}

JNIEXPORT  jint
Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbqueryBlockSize( JNIEnv*  env, jobject this,
                                                 jintArray iSize
                                                 )
{
    jint *p0;

    p0 = (*env)->GetIntArrayElements(env, iSize, 0);
    if (p0 == 0)  return 1;

    D_IF_amrnb_queryBlockSize(p0);

    (*env)->ReleaseIntArrayElements(env, iSize, p0, 0);

    return 0;
}
JNIEXPORT  jint
Java_XXX_logic_voice_vocoder_AMRNB_DIFamrnbgetFrameProperties( JNIEnv*  env, jobject this,
                                                 jbyteArray pBitstream,
                                                 jintArray iPackedFrameSize
                                                 )
{
    jbyte *p0;
    jint *p1;

    p0 = (*env)->GetByteArrayElements(env, pBitstream, 0);
    if (p0 == 0)  return 1;
    p1 = (*env)->GetIntArrayElements(env, iPackedFrameSize, 0);
    if (p1 == 0)  return 1;

    D_IF_amrnb_getFrameProperties(p0, p1);

    (*env)->ReleaseByteArrayElements(env, pBitstream, p0, 0);
    (*env)->ReleaseIntArrayElements(env, iPackedFrameSize, p1, 0);

    return 0;
}

更新: typedef.h:

#ifndef typedef_h
#define typedef_h "$Id $"

typedef int Word32;
typedef unsigned int UWord32;
typedef short Word16;
typedef unsigned short UWord16;
typedef char Word8;
typedef unsigned char UWord8;

#endif

amrnb_if.h:

#ifndef _AMRNB_IF_H_
#define _AMRNB_IF_H_

#include "typedef.h"

// codec version
extern const int amrnb_major_version;
extern const int amrnb_minor_version;
extern const int amrnb_build_version;

#define L_FRAME8K_AMR     160    /* Frame size at 8kHz  */
#define L_PACKED_AMR      32     /* max serial size     */

#define AMR_MAGIC_NUMBER "#!AMR\n"

#define _good_frame  0
#define _bad_frame   1
#define _lost_frame  2
#define _no_frame    3

// encoder error codes
#define AMRNBENC_ERROR_NONE         0x0   // no error
#define AMRNBENC_ERROR_GENERAL      0x1   // general error
#define AMRNBENC_ERROR_INVALIDMODE  0x2   // Encoder mode is out of range (0..7)

// decoder error codes
#define AMRNBDEC_ERROR_NONE         0x0   // no error
#define AMRNBDEC_ERROR_GENERAL      0x1   // general error
#define AMRNBDEC_ERROR_BITSTREAM    0x2   // bitstream is corrupt

#define AMR_GetModeFromBITSTREAM(a)   ((a[0] >> 3) & 0x000F)

#ifdef __cplusplus
extern "C" {
#endif

Word32 E_IF_amrnb_init(
  void *hState,
  Word32 iEnableVAD);

Word32 E_IF_amrnb_encode(
        void *hState,
        Word16 *pSpeech,
        UWord8 *pBitstream,
        Word32 *iOutputSize,
        Word32 iMode
);

void E_IF_amrnb_queryBlockSize(
        Word32 *iSizeState
);

Word32 D_IF_amrnb_init(
        void *hState
);

Word32 D_IF_amrnb_decode(
        void *hState,
        UWord8 *pBitstream,
        Word16 *pSynthSpeech,
        Word32 iBadFrame
);

void D_IF_amrnb_queryBlockSize(
        Word32 *iSizeState
);

Word32 D_IF_amrnb_getFrameProperties(
        UWord8 *pBitstream,
        Word32 *iPackedFrameSize
);

#ifdef __cplusplus
}
#endif

#endif //_AMRNB_IF_H_
4

0 回答 0