4

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"

The second one is : "Conflicting types for 'read_binary_profile'"

Can you please help to resolve this issuse.

Below is code

    #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));
    }

After solving that errors by declaring method its showing below error

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)
Aslam
  • 231
  • 1
  • 3
  • 15
  • 3
    Just declare your function before calling it, as you should always do. The conflicting types error is a consequence of your forgetting to declare it, so it fell back on a default type which turned out to be different from the actual type. Just copy the function prototype, put it at the top of the file, and terminate it with a semicolon. – Tom Karzes Apr 24 '20 at 04:00
  • Is that a typo? The code does not contain `read_binary_profile`. – Gerhardh Apr 24 '20 at 07:40
  • Does this answer your question? [warning: implicit declaration of function](https://stackoverflow.com/questions/8440816/warning-implicit-declaration-of-function) – Gerhardh Apr 24 '20 at 07:41
  • Thanks for reply. i tired to declare function before calling..but iam getting new errors like thisUndefined 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 – Aslam Apr 24 '20 at 09:39

1 Answers1

3

"Implicit declaration of function" means that no function declaration was visible to the compiler when you called the function. This is no longer allowed in C since the C99 standard.

Apparently upon facing such a function call, your compiler still tries to make an old C90 "implicit int" out of it, meaning that upon spotting this p=my_read_binary_profile(b_profile,0), it will treat the function as if it was declared as int my_read_binary_profile (int, int) and generate machine code accordingly, which is obviously wrong.

This gives the second error, the "implicit int" crap doesn't match the correct function definition vcp_profile_t * my_read_binary_profile(void *pmem, int allocate), hence conflicting types.

Solve this by adding a function declaration prototype on top of the file:

vcp_profile_t* my_read_binary_profile(void* pmem, int allocate);
Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Thanks for reply..After declaration that error is gone..but its showing some other error like this Undefined symbols "_vcp_check_profile" Undefined symbols "_vcp_get_hook_size" Undefined symbols "_vcp_get_mem_size" Undefined symbols "_vcp_init_debug" – Aslam Apr 24 '20 at 09:40
  • @Aslam It seems that your overall problem is missing header files/libraries. – Lundin Apr 24 '20 at 10:46
  • Actually i got this files/libraries from client.i imported all files and libraries...is there any alternative to fix this issue? – Aslam Apr 25 '20 at 02:11
  • @Aslam If the problems are reported from the object files, maybe you are simply trying to link the original object files from the client and there's some path missing or whatever. You could attempt to delete them and make a clean build. Otherwise, the IDE failing to find some sub directory etc is common. – Lundin Apr 25 '20 at 08:29