ut-issl / s2e-core

Spacecraft Simulation Environment Core codes
MIT License
46 stars 18 forks source link

Build failed on Linux about size_t #103

Closed sksat closed 2 years ago

sksat commented 2 years ago

Overview

Build failed on some Linux environment because of lack of include cstddef.

Details

Description

Some files use size_t type without include cstdef.

Conditions of occurrence

Additional information

Build log

[ 60%] Building CXX object src/Interface/SpacecraftInOut/CMakeFiles/SC_IO.dir/Ports/I2CPort.cpp.o
In file included from /s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp:1:
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.h:22:3: error: 'size_t' does not name a type
   22 |   size_t WriteCommand(const unsigned char i2c_addr, const unsigned char* tx_data, const size_t length);
      |   ^~~~~~
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.h:3:1: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
    2 | #include <map>
  +++ |+#include <cstddef>
    3 | 
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.h:23:3: error: 'size_t' does not name a type
   23 |   size_t ReadCommand(const unsigned char i2c_addr, unsigned char* rx_data, const size_t length);
      |   ^~~~~~
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.h:23:3: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp: In member function 'int I2CPort::WriteRegister(unsigned char, unsigned char)':
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp:16:48: warning: unused parameter 'i2c_addr' [-Wunused-parameter]
   16 | int I2CPort::WriteRegister(const unsigned char i2c_addr, const unsigned char reg_addr) {
      |                            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp: At global scope:
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp:58:1: error: 'size_t' does not name a type
   58 | size_t I2CPort::WriteCommand(const unsigned char i2c_addr, const unsigned char* tx_data, const size_t length) {
      | ^~~~~~
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp:2:1: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
    1 | #include "I2CPort.h"
  +++ |+#include <cstddef>
    2 | 
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp:79:1: error: 'size_t' does not name a type
   79 | size_t I2CPort::ReadCommand(const unsigned char i2c_addr, unsigned char* rx_data, const size_t length) {
      | ^~~~~~
/s2e-core/src/Interface/SpacecraftInOut/Ports/I2CPort.cpp:79:1: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?

Task

Scope of influence

Some Linux environment.

Supplement

Write additional comments if you need.

Note

sksat commented 2 years ago

状況からして,たぶんCIが通ってしまっているのがおかしい

sksat commented 2 years ago

今めっちゃ疑っているのはgcc(というかlibc++か)のバージョン差異です

sksat commented 2 years ago

ubuntu:focalだとExtLibrariesのビルドにコケまくるが,これはCMakeのバージョンによるものか...?(3.16.3)

sksat commented 2 years ago

ubuntu:focalで,(ExtLibrariesがコケたところは手動でどうにかしたけど)同じ操作でビルド成功(ビルドCIの再現ができた). ということで,問題は

の2つ

sksat commented 2 years ago

なので,やるべきこととしては

sksat commented 2 years ago

あとCIで諸々の使ってるやつのバージョン表示する,とかもかな

sksat commented 2 years ago

あっActionsのCMakeはWinもUbuntuも3.23.0なのか

200km commented 2 years ago

@sksat こちら、v5.0.0更新前に修正したほうが良いと思っていますが、私ができる範囲であればやるので遠慮なく申し付けてください。私の環境ではビルドエラーは出ていませんが、GCCのバージョンを更新したほうが良いですよね?

sksat commented 2 years ago

あ,そうですね.やるだけなのでやります.

sksat commented 2 years ago

focalだと素直にはgcc-10までしかないか.まあ試してみよう.

sksat commented 2 years ago

結局gcc-11になりました.とりあえず実用上は #111 で問題ないです.

sksat commented 2 years ago

clangとCMakeの話はここで出たというだけで別問題なので別Issueとします.

200km commented 2 years ago

ありがとうございます。こちらは次のような理解で良いのでしょうか?

sksat commented 2 years ago

いや,コンパイラ(正確には標準ライブラリ)の実装が適当でないことによって適当でないコードのコンパイルが通っていた,ということが問題なので,ユーザ・開発者がgccのバージョンを意識する必要はあまりないです.

200km commented 2 years ago

今回のように手元でエラー出ていなくても、CIがエラー出すからその時に気づいて修正すれば良いって感じですかね。

sksat commented 2 years ago

そういうことです.基本的にCIが最大限エラー・ワーニングを出せればよい(その意味で最新のコンパイラを使うとワーニングが増えていたりしてよいがち),という考えです. 準拠すべきなのは各々のコンパイラやバージョンによる差異ではなくC++の規格(のバージョン)であって,複数のコンパイラ実装でビルドCIを組むことでその差異に気付けるようにしたい,というかんじです.なので,コンパイラのバージョンを気にするとしてもCI側で複数バージョンのコンパイラでビルドするようにしたいですかね(が,これははあまり必要ないと思います).

200km commented 2 years ago

わかりました。ありがとうございます。