簡體   English   中英

How to fix these error “Implicit declaration of function is invalid in C99” and “Conflicting types” in.c file in Xcode objective-C?

[英]How to fix these error “Implicit declaration of function is invalid in C99” and “Conflicting types” in .c file in Xcode objective-C?

Actually iam importing.C file library in objective-c.I have fixed most of errors.but below two errors iam not able to resolve.. The first one is: "Implicit declaration of function 'read_binary_profile' is invalid in C99"

第二個是:“'read_binary_profile' 的沖突類型”

你能幫忙解決這個問題嗎?

下面是代碼

    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    #define __EXTRA_CMDL_SERVICE
    #define __TEXT_ERRORS_PRINT

    #include "profile.h"
    #include "vcp-api.h"
    #define PROFILE "/vendor/etc/profile.bix"
    extern char* vcp_errorv(err_t err);
    vcp_profile_t* read_binary_profile(void* pmem, int allocate);

    vcp_profile_t *p;
    void *b_profile ;
    mem_reg_t reg[NUM_MEM_REGIONS];
    void *smr[NUM_MEM_REGIONS];
    #define FRAME_VCP  80//120      //  Frame handle lenght 120: 7.5ms 16Bit, 16K  so defined here,   but buffer lenght is 120* size of short
    short *input_frame[4];
    short *spk[2];
    short aec[FRAME_VCP] ;   //¥À¥¶»Áπ˚√ª”–ACE , ø…“‘”√ø’ ˝◊È

    void alango_vcp_init()
{
    unsigned int smem = 16000; //1792;
    void *mem;
    err_t err;
    FILE *fp, *fp2 ;
    int flen , fsize ;

    fp=fopen(PROFILE,"rb");
    fseek(fp,0,SEEK_END);
    flen=ftell(fp);
    b_profile=(char *)malloc(flen);
    if(b_profile==NULL){
        fclose(fp);
        printf("Alango VCP Can't find profile configuration.\n");
        return ;
    }
    if(fp==NULL){
        printf("Alango VCP Can't open profile configuration.\n");
        return ;
    }
    fseek(fp,0,SEEK_SET);
    fsize=fread(b_profile,1,flen,fp);
    if(fsize!=flen){
        printf("read file error , read len ==== %d , return size ===%d", flen, fsize);
        fclose(fp);
        return;
    }
    p=read_binary_profile(b_profile,0);
    printf("alango_vcp_init 111 \n");
    err = vcp_check_profile(p);
    printf("alango_vcp_init 222 \n");
    if (err.err){
         if (err.err == ERR_INVALID_CRC)
             printf("alango_vcp_init Profile error: Invalid CRC!");
         else
             printf("alango_vcp_init Profile error: vcp_errorv(err) \n");
    }
    smem = vcp_get_hook_size();
    mem = malloc(smem);
    printf("alango_vcp_init 333 \n");
        vcp_get_mem_size(p, reg, mem);
        printf("alango_vcp_init 444 \n");
    free(mem);

    input_frame[0] = malloc(FRAME_VCP*sizeof(short));    //  5ms 16K 16bit buffer
    input_frame[1] = malloc(FRAME_VCP*sizeof(short));    //  5ms 16K 16bit buffer
    input_frame[2] = malloc(FRAME_VCP*sizeof(short));    //  5ms 16K 16bit buffer
    input_frame[3] = malloc(FRAME_VCP*sizeof(short));    //  5ms 16K 16bit buffer
    spk[0] = malloc(FRAME_VCP*sizeof(short));    //  5ms 16K 16bit buffer
    spk[1] = malloc(FRAME_VCP*sizeof(short));    //  5ms 16K 16bit buffer
    for (int i = 0; i < NUM_MEM_REGIONS; i++){
        reg[i].mem = smr[i] = (void *)malloc(reg[i].size);
        printf("alango_vcp_init I need %d bytes of memory in memory region %d to work.\n", reg[i].size, i + 1);
    }
    err = vcp_init_debug(p, reg);
    if (err.err == ERR_NOT_ENOUGH_MEMORY)
    {
        printf("alango_vcp_init %d more bytes needed in region %d!\n", -reg[err.pid].size, err.pid);
    }
    else if (err.err == ERR_UNKNOWN)
    {
        printf("alango_vcp_init vcp_init_debug() returns UNKNOWN error\n!");
    }
    else if (err.err != ERR_NO_ERROR)
    {
        printf("alango_vcp_init vcp_init_debug() returns error __text_error[err.err], err.pid!\n");
    }
}



    vcp_profile_t * read_binary_profile(void *pmem, int allocate)
    {
       vcp_profile_t *prof;//base_profile();
       prof= malloc(sizeof(profile_tab));
    }

通過聲明方法解決該錯誤后,它顯示以下錯誤

ld: warning: ignoring file /Users/yq12462/Desktop/ImportingCfileDemo/ImportingCfileDemo/libvcp_32.a, building for iOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file /Users/yq12462/Desktop/ImportingCfileDemo/ImportingCfileDemo/libvcp_64.a, building for iOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
  "_vcp_check_profile", referenced from:
      _alango_vcp_init in AlangoBasic.o
  "_vcp_get_hook_size", referenced from:
      _alango_vcp_init in AlangoBasic.o
  "_vcp_get_mem_size", referenced from:
      _alango_vcp_init in AlangoBasic.o
  "_vcp_init_debug", referenced from:
      _alango_vcp_init in AlangoBasic.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

“函數的隱式聲明”意味着當您調用 function 時,編譯器看不到 function 聲明。 自 C99 標准以來,C 不再允許這樣做。

顯然,在面對這樣的 function 調用時,您的編譯器仍會嘗試從中生成舊的 C90“隱式 int”,這意味着在發現此p=my_read_binary_profile(b_profile,0)時,它將把 function 視為聲明為int my_read_binary_profile (int, int)並相應地生成機器碼,這顯然是錯誤的。

這給出了第二個錯誤,“隱式 int”廢話與正確的 function 定義vcp_profile_t * my_read_binary_profile(void *pmem, int allocate)不匹配,因此類型沖突。

通過在文件頂部添加 function 聲明原型來解決此問題:

vcp_profile_t* my_read_binary_profile(void* pmem, int allocate);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM