1. 程式人生 > 實用技巧 >Linux c++編譯總結(持續更新)

Linux c++編譯總結(持續更新)

1. 沒有定義的符號

這類的錯誤, 解決辦法A. 新增對應的標頭檔案(原始檔), B.前置宣告

  • 1.1 錯誤描述:
 error: variable has incomplete type 'class XXX ' 
error: 'helper' is not a class, namespace, or enumeration
  • 1.2 編譯器說的很清楚,沒有找到其定義, 看看錯誤的程式碼
class _utils_api_ helper
{
public:
};
  • 1.3 錯誤提示:
[ 20%] Building CXX object CMakeFiles/calc.dir/src/utils.cpp.o
In file included from /home/cube/demo/call_clang/src/utils.cpp:1:
/home/xx/demo/call_clang/include/utils.h:53:2: error: expected expression
        public:
/home/cube/demo/call_clang/include/utils.h:51:20: error: variable has incomplete type 'class _utils_api_'
        class _utils_api_ helper
                          ^
/home/xx/demo/call_clang/include/utils.h:51:8: note: forward declaration of 'utils::_utils_api_'
        class _utils_api_ helper
              ^
/home/xx/demo/call_clang/src/utils.cpp:14:14: error: 'helper' is not a class, namespace, or enumeration
        std::string helper::wstr2str(const std::wstring& wstr)
  • 1.4 分析,這裡提示,沒有定義_utils_api_, 而用_utils_api_修飾了類helper
  • 1.5 解決: 增加對_utils_api_的定義。
  • 1.6 擴充套件, 可能沒有包含標頭檔案就已經在使用標頭檔案中的函式或者型別,也會出現這樣的錯誤,解決: 增加頭對應的型別引用