[英]ARM C++ Cross-Compiling: usual default includes available?
我正在使用 arm-none-eabi-gcc/g++ 工具鏈對 ARM Cortex_M7 的裸機 C++ 進行 x 編譯,它工作正常,在我的板上閃爍漂亮的固件。
現在,當/如果我想包含“好舊的” C++ <mutex>, <queue>, <iostream>...
文件時,我會遇到編譯錯誤的瀑布(我不會費心粘貼在這里,因為我知道這些是不相干..)
這是預期的嗎,因為這些根本不可用,我應該像一個男人一樣,自己編寫自己的隊列,互斥鎖,...類,就像我現在正在做的那樣(雖然聽起來有點像重新發明輪子)還是我缺少“系統根”? 但是……世界上每一個 ARM-Cortex_Mx 架構都有這樣的東西嗎?
在 sysroot、std、linux 之間閱讀這篇文章時,我可能感到困惑,也許我需要下載一個合適的工具鏈(arm-none-linux-gnueabi-g++?),其中包含一個特定的“sysroot”(包含我的所有包含和庫)目標)因為我在Linux 環境中編譯,即使我的目標不會在 Linux(裸機)上運行?
恐怕我不能用谷歌搜索合適的主題(或者用谷歌搜索錯誤?)
感謝您的澄清!
編輯:
包含 and 時出錯:
$~>制作
CXX obj/src/hot_queue.o
在 /usr/arm-none-eabi/include/c++/9.2.0/ext/string_conversions.h:43 包含的文件中,
from /usr/arm-none-eabi/include/c++/9.2.0/bits/basic_string.h:6493, from /usr/arm-none-eabi/include/c++/9.2.0/string:55, from /usr/arm-none-eabi/include/c++/9.2.0/stdexcept:39, from /usr/arm-none-eabi/include/c++/9.2.0/array:39, from /usr/arm-none-eabi/include/c++/9.2.0/tuple:39, from /usr/arm-none-eabi/include/c++/9.2.0/mutex:38, from src/hot_queue.hpp:27, from src/hot_queue.cpp:29:
/usr/arm-none-eabi/include/c++/9.2.0/cstdio:127:11: 錯誤:'::printf' 尚未聲明
127 | 使用::printf;
| ^~~~~~
/usr/arm-none-eabi/include/c++/9.2.0/cstdio:134:11: 錯誤:'::scanf' 尚未聲明 134 | 使用::scanf;
| ^~~~~
make: *** [mak/Makefile.sam.in:359: obj/src/hot_queue.o] 錯誤 1
實際上,另一個很好的例子是:這次 g++確實找到了正確的文件……但無法編譯它……宏錯誤:
~> make
CXX obj/src/hot_can.o
CXX obj/src/hot_main.o
In file included from /usr/arm-none-eabi/include/c++/9.2.0/vector:60,
from src/hot_can.hpp:28,
from src/hot_can.cpp:30:
/usr/arm-none-eabi/include/c++/9.2.0/bits/stl_algobase.h:246:56: error: macro "min" passed 3 arguments, but takes just 2
246 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^
In file included from ./sam/boards/samv71_xplained_ultra/samv71_xplained_ultra.h:40,
from src/hot_can.cpp:24:
./sam/utils/compiler.h:810: note: macro "min" defined here
810 | #define min(a, b) Min(a, b)
|
In file included from /usr/arm-none-eabi/include/c++/9.2.0/vector:60,
from src/hot_can.hpp:28,
from src/hot_can.cpp:30:
/usr/arm-none-eabi/include/c++/9.2.0/bits/stl_algobase.h:268:56: error: macro "max" passed 3 arguments, but takes just 2
268 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^
In file included from ./sam/boards/samv71_xplained_ultra/samv71_xplained_ultra.h:40,
from src/hot_can.cpp:24:
./sam/utils/compiler.h:821: note: macro "max" defined here
821 | #define max(a, b) Max(a, b)
|
In file included from /usr/arm-none-eabi/include/c++/9.2.0/vector:60,
from src/hot_can.hpp:28,
from src/hot_main.cpp:36:
/usr/arm-none-eabi/include/c++/9.2.0/bits/stl_algobase.h:246:56: error: macro "min" passed 3 arguments, but takes just 2
246 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
編輯:
包括在我的代碼中:
CXX obj/src/hot_tmc.o
arm-none-eabi-g++ -mcpu=cortex-m7 -mthumb -D__SAMV71Q21B__ -O1 -DDEBUG -D__SAMV71Q21B__ -Dscanf=iscanf -DARM_MATH_CM7=true -Dprintf=iprintf -DBOARD=SAMV71_XPLAINED_ULTRA -I./src -I./inc -I./lib -I./com/boards -I./com/services/clock -I./com/services/gpio -I./com/services/ioport -I./com/services/sleepmgr -I./com/services/sleepmgr/sam -I./com/services/serial -I./com/services/serial/sam_uart -I./com/utils -I./com/utils/stdio/stdio_serial -I./sam/boards -I./sam/boards/samv71_xplained_ultra -I./sam/drivers -I./sam/drivers/afec -I./sam/drivers/matrix -I./sam/drivers/mcan -I./sam/drivers/mpu -I./sam/drivers/pio -I./sam/drivers/pmc -I./sam/drivers/tc -I./sam/drivers/uart -I./sam/drivers/usart -I./sam/utils -I./sam/utils/cmsis/samv71/source/templates -I./sam/utils/fpu -I./sam/utils/header_files -I./sam/utils/cmsis/samv71/include -I./sam/utils/preprocessor -mfloat-abi=softfp -mfpu=fpv5-sp-d16 -mlong-calls -std=gnu++17 -pipe -Wall -Wpointer-arith -ffunction-sections -fdata-sections -fno-strict-aliasing -Wmain -Wparentheses -Wchar-subscripts -Wcomment -Wformat=2 -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wwrite-strings -Wmissing-declarations -Wsign-compare -Waggregate-return -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -g3 -MD -MP -MQ obj/src/hot_tmc.o -c src/hot_tmc.cpp -o obj/src/hot_tmc.o
In file included from /usr/arm-none-eabi/include/c++/9.2.0/ext/string_conversions.h:43,
from /usr/arm-none-eabi/include/c++/9.2.0/bits/basic_string.h:6493,
from /usr/arm-none-eabi/include/c++/9.2.0/string:55,
from /usr/arm-none-eabi/include/c++/9.2.0/stdexcept:39,
from /usr/arm-none-eabi/include/c++/9.2.0/array:39,
from /usr/arm-none-eabi/include/c++/9.2.0/tuple:39,
from /usr/arm-none-eabi/include/c++/9.2.0/mutex:38,
from src/hot_tmc.cpp:26:
/usr/arm-none-eabi/include/c++/9.2.0/cstdio:127:11: error: '::printf' has not been declared
127 | using ::printf;
| ^~~~~~
/usr/arm-none-eabi/include/c++/9.2.0/cstdio:134:11: error: '::scanf' has not been declared
134 | using ::scanf;
| ^~~~~
In file included from src/hot_tmc.cpp:30:
src/hot_log.hpp: In member function 'void LOG::LogThis(LOG::log_ID, const char*, const char*, int, Params&& ...)':
src/hot_log.hpp:132:13: error: there are no arguments to 'printf' that depend on a template parameter, so a declaration of 'printf' must be available [-fpermissive]
132 | printf(buffer);
| ^~~~~~
src/hot_log.hpp:132:13: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
src/hot_log.hpp:136:7: error: there are no arguments to 'printf' that depend on a template parameter, so a declaration of 'printf' must be available [-fpermissive]
136 | printf(" %s\r\n", RESET);
| ^~~~~~
src/hot_tmc.cpp: In member function 'void TMC::PrintNewTC(const CANPckt&)':
src/hot_tmc.cpp:94:9: error: 'printf' was not declared in this scope
94 | printf("[%d] 0x%2x (%3d)\r\n", i, tcPckt.GetPcktByte(i), tcPckt.GetPcktByte(i) );
| ^~~~~~
src/hot_tmc.cpp:31:1: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
30 | #include "hot_log.hpp"
+++ |+#include <cstdio>
31 |
In file included from src/hot_tmc.cpp:30:
src/hot_log.hpp: In instantiation of 'void LOG::LogThis(LOG::log_ID, const char*, const char*, int, Params&& ...) [with Params = {const char (&)[28]}]':
src/hot_tmc.cpp:65:9: required from here
src/hot_log.hpp:132:19: error: 'printf' was not declared in this scope
132 | printf(buffer);
| ~~~~~~^~~~~~~~
src/hot_log.hpp:1:1: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
+++ |+#include <cstdio>
1 | /* ----------------------------------------------------------------------------
src/hot_log.hpp:134:19: error: 'printf' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
134 | printf(std::forward<Params>(params)...);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/hot_log.hpp:136:13: error: 'printf' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
136 | printf(" %s\r\n", RESET);
| ~~~~~~^~~~~~~~~~~~~~~~~~
src/hot_log.hpp: In instantiation of 'void LOG::LogThis(LOG::log_ID, const char*, const char*, int, Params&& ...) [with Params = {const char (&)[32], unsigned char}]':
src/hot_tmc.cpp:69:5: required from here
src/hot_log.hpp:132:19: error: 'printf' was not declared in this scope
132 | printf(buffer);
| ~~~~~~^~~~~~~~
src/hot_log.hpp:132:19: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
src/hot_log.hpp:134:19: error: 'printf' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
134 | printf(std::forward<Params>(params)...);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/hot_log.hpp:136:13: error: 'printf' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
136 | printf(" %s\r\n", RESET);
| ~~~~~~^~~~~~~~~~~~~~~~~~
因此,確實感覺從 ATMEL/Microchip 的庫/驅動程序中加載的“printf()”保留名稱 ovlerloading 正在毒化 std 包含的使用。
<iostream>
為您提供std::cin
和std::cout
- 標准輸入和標准輸出。 這些是字符設備。 但是 Cortex-M 經常出現在沒有操作系統、沒有鍵盤或其他 I/O 的深度嵌入式系統中。 出於同樣的原因,您可能還會發現<fstream>
丟失。
<queue>
完全不同。 它沒有硬件依賴; 它應該存在。 <mutex>
是一個有爭議的部分。 線程是 C++11 中的新功能,並非所有 Cortex-M 系統都可能具有多核系統。 如果沒有多核系統,也沒有操作系統來進行線程交換,線程和互斥鎖將很難實現。
話雖如此, <queue>
的性質意味着您可能會在構建環境之外使用<queue>
的 Linux 版本。 骯臟,但可能可行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.