gpt4 book ai didi

c - 如何在 Xcode Objective-C 的 .c 文件中修复这些错误 “Implicit declaration of function is invalid in C99” 和 "Conflicting types"?

转载 作者:行者123 更新时间:2023-12-04 10:09:24 26 4
gpt4 key购买 nike

实际上我在objective-c中导入.C文件库。我已经修复了大部分错误。但下面两个错误我无法解决..
第一个是:“函数'read_binary_profile'的隐式声明在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)

最佳答案

“函数的隐式声明”意味着在调用函数时编译器看不到函数声明。自 C99 标准以来,C 中不再允许这样做。

显然,在面对这样的函数调用时,您的编译器仍然试图从中生成一个旧的 C90“隐式 int”,这意味着在发现这个 p=my_read_binary_profile(b_profile,0) ,它会将函数视为声明为 int my_read_binary_profile (int, int)并相应地生成机器码,这显然是错误的。

这给出了第二个错误,“隐式 int”废话与正确的函数定义不匹配 vcp_profile_t * my_read_binary_profile(void *pmem, int allocate) ,因此类型冲突。

通过在文件顶部添加函数声明原型(prototype)来解决此问题:

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

关于c - 如何在 Xcode Objective-C 的 .c 文件中修复这些错误 “Implicit declaration of function is invalid in C99” 和 "Conflicting types"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61400845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com