2012-10-29 183 views
2

我使用Keil uVision4在STM32F2器件上開發。 我正在嘗試使用C++,它應該可以與uVision工具鏈一起提供的armcc(糾正我,如果我錯了)。 但uVision不服標準C++包括道路Keil uVision4 armcc:使用C++標準包括<cstdint>

#include <cstdint> 

不工作而

#include <stdint.h> 

完美。 當我在uVision中打開cstdint(rightclick,打開文檔)時,它會打開文件,但是作爲通用文件,例如不作爲頭文件,沒有花哨的顏色。

我錯過了什麼?這兩個文件都在同一個文件夾 C:\ Keil \ ARM \ ARMCC \ include 並且它是否強制編譯器使用C++(通過追加--cpp)或沒有任何區別。 uVision只是無法接受沒有結尾的文件作爲頭文件?

編輯:在回答問題的答案(感謝您的時間!): 錯誤消息是:

#include <cstdint> and 
    #include <cstdint.h> 
    typedef uint32_t u32; 
    error: #20: identifier uint32_t is undefined 

#include <stdint.h> and 
    #include <stdint> 
    typedef uint32_t u32; 
    and 
    #include <cstdint> 
    typedef std::uint32_t u32; 
    works perfectly. 

這說明了什麼問題。感謝您的幫助!

+0

嘗試複製'cstdint'並將其命名爲'cstdint.h'(不是解決方案,而是測試您的理論) – Praetorian

+0

向我們顯示錯誤消息。 –

+0

你知道''剛剛被添加到C++ 11中,對嗎?它不是C++ 98和C++ 03的一部分 – sellibitze

回答

1

你到了什麼症狀不起作用?即什麼是錯誤信息?可能是因爲cstdint頭文件將其聲明放置在std名稱空間中,所以您只需要一個using namespace std或在所有類型前添加std ::即可。

但請注意,cstdint是一個非常新的頭文件,可能不會被編譯器支持。所以你可能不得不解決stdint.h,這是一樣的好。