20240502解决ARM32编译器编译quectel-CM时for循环出错的解决
2024/5/2 17:17
缘起:QMIThread.c:2100:9: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
1、修改Makefile为ARM32架构:
Z:\quectel-CM\Makefile
ifneq ($(CROSS_COMPILE),)
CROSS-COMPILE:=$(CROSS_COMPILE)
endif
#CROSS-COMPILE:=/workspace/buildroot/buildroot-qemu_mips_malta_defconfig/output/host/usr/bin/mips-buildroot-linux-uclibc-
#CROSS-COMPILE:=/workspace/buildroot/buildroot-qemu_arm_vexpress_defconfig/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabi-
#CROSS-COMPILE:=/workspace/buildroot-git/qemu_mips64_malta/output/host/usr/bin/mips-gnu-linux-
ifeq ($(CC),cc)
CC:=$(CROSS-COMPILE)gcc
endif
LD:=$(CROSS-COMPILE)ld
修改为:
ifneq ($(CROSS_COMPILE),)
CROSS-COMPILE:=$(CROSS_COMPILE)
endif
#CROSS-COMPILE:=/workspace/buildroot/buildroot-qemu_mips_malta_defconfig/output/host/usr/bin/mips-buildroot-linux-uclibc-
#CROSS-COMPILE:=/workspace/buildroot/buildroot-qemu_arm_vexpress_defconfig/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabi-
#CROSS-COMPILE:=/workspace/buildroot-git/qemu_mips64_malta/output/host/usr/bin/mips-gnu-linux-
CROSS-COMPILE:=/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-
##ifeq ($(CC),cc)
##CC:=$(CROSS-COMPILE)gcc
##endif
CC:=/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc
LD:=$(CROSS-COMPILE)ld
2、
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$ make -j8
cd out/; rm -rf *.o libmnl/*.o quectel-CM quectel-qmi-proxy quectel-mbim-proxy quectel-atc-proxy
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 quectel-qmi-proxy.c -o out/quectel-qmi-proxy -lpthread -ldl -lrt
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 quectel-mbim-proxy.c -o out/quectel-mbim-proxy -lpthread -ldl -lrt
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 quectel-atc-proxy.c atchannel.c at_tok.c util.c -o out/quectel-atc-proxy -lpthread -ldl -lrt
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 QmiWwanCM.c GobiNetCM.c main.c QCQMUX.c QMIThread.c util.c qmap_bridge_mode.c mbim-cm.c device.c atc.c atchannel.c at_tok.c udhcpc.c -o out/quectel-CM -lpthread -ldl -lrt
QMIThread.c: In function ‘requestGetProfile’:
QMIThread.c:2100:9: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for(int i=0; i<profile_num; i++)
^
QMIThread.c:2100:9: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
QMIThread.c:2111:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for(int i=0; i<profile_num; i++)
^
make: *** [Makefile:32: release] Error 1
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$
Z:\quectel-CM\QMIThread.c
_re_check:
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_GET_PROFILE_LIST_REQ, WdsGetProfileListReqSend, profile);
err = QmiThreadSendQMI(pRequest, &pResponse);s_pResponse = malloc(le16_to_cpu(pResponse->QMIHdr.Length) + 1);
qmi_rsp_check_and_return();
pProfileList = (PQMIWDS_PROFILELIST)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x01);
uint8 profile_indexs[42] = {0};
uint8 profile_num = pProfileList->ProfileList[0];
if(profile_num >= 1)
{
uint8 j = 0;
uint8 k = 2;
for(int i=0; i<profile_num; i++)
{
profile_indexs[j++] = pProfileList->ProfileList[k];
if(pProfileList->ProfileList[++k] == 0)
k+=2;
else
k+=2+pProfileList->ProfileList[k];
}
}
free(pResponse);
for(int i=0; i<profile_num; i++)
{
profile->profile_index = profile_indexs[i];
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_GET_PROFILE_SETTINGS_REQ, WdsGetProfileSettingsReqSend, profile);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
pPdpContext = (PQMIWDS_PDPCONTEXT)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x25);
if(pPdpContext->pdp_context == profile->pdp)
break;
else
free(pResponse);
if(i == profile_num-1)
{
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_CREATE_PROFILE_REQ, WdsCreateProfileSettingsReqSend, profile);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
free(pResponse);
goto _re_check;
}
}
修改为:
_re_check:
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_GET_PROFILE_LIST_REQ, WdsGetProfileListReqSend, profile);
err = QmiThreadSendQMI(pRequest, &pResponse);s_pResponse = malloc(le16_to_cpu(pResponse->QMIHdr.Length) + 1);
qmi_rsp_check_and_return();
pProfileList = (PQMIWDS_PROFILELIST)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x01);
uint8 profile_indexs[42] = {0};
uint8 profile_num = pProfileList->ProfileList[0];
if(profile_num >= 1)
{
uint8 j = 0;
uint8 k = 2;
//for(int i=0; i<profile_num; i++)
int i;
for(i=0; i<profile_num; i++)
{
profile_indexs[j++] = pProfileList->ProfileList[k];
if(pProfileList->ProfileList[++k] == 0)
k+=2;
else
k+=2+pProfileList->ProfileList[k];
}
}
free(pResponse);
//for(int i=0; i<profile_num; i++)
int i;
for(i=0; i<profile_num; i++)
{
profile->profile_index = profile_indexs[i];
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_GET_PROFILE_SETTINGS_REQ, WdsGetProfileSettingsReqSend, profile);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
pPdpContext = (PQMIWDS_PDPCONTEXT)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x25);
if(pPdpContext->pdp_context == profile->pdp)
break;
else
free(pResponse);
if(i == profile_num-1)
{
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_CREATE_PROFILE_REQ, WdsCreateProfileSettingsReqSend, profile);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
free(pResponse);
goto _re_check;
}
}
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$ make -j8
cd out/; rm -rf *.o libmnl/*.o quectel-CM quectel-qmi-proxy quectel-mbim-proxy quectel-atc-proxy
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 quectel-qmi-proxy.c -o out/quectel-qmi-proxy -lpthread -ldl -lrt
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 quectel-mbim-proxy.c -o out/quectel-mbim-proxy -lpthread -ldl -lrt
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 quectel-atc-proxy.c atchannel.c at_tok.c util.c -o out/quectel-atc-proxy -lpthread -ldl -lrt
/opt/FriendlyARM/toolchain/4.9.3/bin/arm-none-linux-gnueabihf-gcc -Wall -Wextra -Werror -O1 QmiWwanCM.c GobiNetCM.c main.c QCQMUX.c QMIThread.c util.c qmap_bridge_mode.c mbim-cm.c device.c atc.c atchannel.c at_tok.c udhcpc.c -o out/quectel-CM -lpthread -ldl -lrt
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM$ cd out/
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM/out$ ll
total 272
drwxrwxr-x 2 rootroot rootroot 4096 5月 2 16:29 ./
drwxrwxr-x 5 rootroot rootroot 4096 5月 2 16:29 ../
-rwxrwxr-x 1 rootroot rootroot 45844 5月 2 16:29 quectel-atc-proxy*
-rwxrwxr-x 1 rootroot rootroot 183564 5月 2 16:29 quectel-CM*
-rwxrwxr-x 1 rootroot rootroot 16336 5月 2 16:29 quectel-mbim-proxy*
-rwxrwxr-x 1 rootroot rootroot 20296 5月 2 16:29 quectel-qmi-proxy*
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM/out$
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM/out$ file quectel-CM
quectel-CM: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.0.8, BuildID[sha1]=df17be612cd8840b562e01885b0a84d9afa96d78, with debug_info, not stripped
rootroot@rootroot-ThinkBook-16-G5-IRH:~/quectel-CM/out$
参考资料:
百度:QMIThread.c:2100:9: error: ‘for’ loop initial declarations are only allowe
https://blog.csdn.net/qq_53381910/article/details/131819714
error: ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
https://blog.csdn.net/lei2014lei/article/details/134590485
error: ‘for‘ loop initial declarations are only allowed in C99 or C11 mode