C/C++編譯報錯printf was not declared in this scope問題及解決
C C++編譯報錯printf was not declared in this scope
原因是這個 printf 函數(shù)需要頭文件 "stdio",但是程序中沒寫,解決辦法是在頭文件中加入此頭文件。
C語言加入
#include<stdio.h>
C++加入
#include<cstdio>
C C++常見編譯錯誤提示釋義
1.iteration 16 invokes undefined behavior**
常見于對數(shù)組的操作,數(shù)組溢出錯誤。
數(shù)組定義為20個字節(jié),而for循環(huán)判斷條件應為<20
? uint8_t oldrelay[20] ?= { 0U };
? for ( i = INDUCTOR_160nH; i <= 20; i++ )
? ? {
? ? ? ? oldrelay[ i ] = SET;
? ? ? ? relay[ i ] = RESET;
? ? }2.warning: excess elements in array initializer**
數(shù)組元素比定義元素多
3.passing argument 1 of ‘sprintf’ discards ‘volatile’ qualifier from pointer target type**
加上強制轉換
volatile uint8_t str[10]; sprintf((char*)str,“0”);
4.in expansion of macro
宏定義錯誤
在頭文件中避免短宏定義,容易重復;例如
//#define SIZE 24 prop_name 參數(shù)為 SIZE LV_STYLE_##prop_name
預編譯為 LV_STYLE_24 出錯
C C++編譯錯誤整理
面這些是我自己在學習工作遇到的編譯問題,以及可行的解決辦法,整理一下,也方便自己及時查閱 ︿( ̄︶ ̄)︿︿( ̄︶ ̄)︿︿( ̄︶ ̄)︿
1.VC打開已存在的工程提示錯誤 C1083:缺少 *.pch
問題解決:
Project->c/c++,然后點擊Category的下拉框,選擇Precompiled Headers,
接著選擇第二項,Automatic use of precompiled headers , 編輯框里填 *.h ,這樣做的前提是你的 *.h 和 *.cpp 都已存在。
問題就解決了。
2.VS打開已存在工程,出現(xiàn) error MSB3073
英文版處理辦法:
- Project->Configuration Properties->General->Target Extension設置為.ocx 或者.dll
- Project->Configuration Properties->Linkerl->General ->Output File設置為$(OutDir)$(ProjectName)$(TargetExt)
中文版處理辦法:
- 在項目上點右鍵,選擇“屬性”->“配置屬性”->“常規(guī)”->“目標文件擴展名”,設置為.ocx 或者.dll
- 在項目上點右鍵,選擇“屬性”->“配置屬性”->“鏈接器”->“ 常規(guī) ”->“輸出文件”,設置為$(OutDir)$(ProjectName)$(TargetExt)
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
C++ main函數(shù)中的argc與argv全面解析
C/C++中的main函數(shù)可以接受命令行參數(shù),通過argc和argv來傳遞這些參數(shù),argc表示參數(shù)總數(shù),argv是一個字符串數(shù)組,包含具體的參數(shù),本文介紹C++ main函數(shù)中的argc與argv,感興趣的朋友跟隨小編一起看看吧2026-03-03
C++實現(xiàn)LeetCode(142.單鏈表中的環(huán)之二)
這篇文章主要介紹了C++實現(xiàn)LeetCode(142.單鏈表中的環(huán)之二),本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下2021-07-07

