Repository navigation
Title: Build failure on musl libc: BAUD_2000000 and related enum members missing #523
Description
Describe the bug
Compiling LibSerial with a musl libc toolchain results in a compile error.
In SerialPort.h, high baudrate enum entries (BAUD_2000000, BAUD_2500000, BAUD_3000000, BAUD_3500000, BAUD_4000000) are conditionally defined only when __MAX_BAUD > B2000000.
Musl libc's termios only defines baud constants up to B1000000, so __MAX_BAUD is B1000000. Those enum members are not generated.
However, the GetBitRate() function inside SerialPort.cpp references those enum values via case statements without matching preprocessor guards. This causes GCC to throw an error because those enum identifiers do not exist in musl builds.
To Reproduce
- Use an
aarch64-linux-muslGCC toolchain - Build LibSerial from source
- Compilation fails at
SerialPort.cpp
Error message
/home/tiny/.mcpp/registry/data/xpkgs/compat-x-libserial/1.0.0/libserial-1.0.0/src/SerialPort.cpp:1226:24: error: 'BAUD_2000000' is not a member of 'LibSerial::BaudRate'; did you mean 'BAUD_1000000'?
1226 | case BaudRate::BAUD_2000000:
| ^\\\\\~
| BAUD_1000000
/home/tiny/.mcpp/registry/data/xpkgs/compat-x-libserial/1.0.0/libserial-1.0.0/src/SerialPort.cpp:1230:24: error: 'BAUD_2500000' is not a member of 'LibSerial::BaudRate'; did you mean 'BAUD_500000'?
1230 | case BaudRate::BAUD_2500000:
| ^\\\\\~
| BAUD_500000
/home/tiny/.mcpp/registry/data/xpkgs/compat-x-libserial/1.0.0/libserial-1.0.0/src/SerialPort.cpp:1234:24: error: 'BAUD_3000000' is not a member of 'LibSerial::BaudRate'; did you mean 'BAUD_1000000'?
1234 | case BaudRate::BAUD_3000000:
| ^\\\\\~
| BAUD_1000000
/home/tiny/.mcpp/registry/data/xpkgs/compat-x-libserial/1.0.0/libserial-1.0.0/src/SerialPort.cpp:1238:24: error: 'BAUD_3500000' is not a member of 'LibSerial::BaudRate'; did you mean 'BAUD_500000'?
1238 | case BaudRate::BAUD_3500000:
| ^\\\\\~
| BAUD_500000
/home/tiny/.mcpp/registry/data/xpkgs/compat-x-libserial/1.0.0/libserial-1.0.0/src/SerialPort.cpp:1242:24: error: 'BAUD_4000000' is not a member of 'LibSerial::BaudRate'; did you mean 'BAUD_1000000'?
1242 | case BaudRate::BAUD_4000000:
| ^\\\\\~
| BAUD_1000000
Expected behavior
The case branches for those high baudrates in GetBitRate() should be wrapped using the same preprocessor condition as the header file.
Proposed fix
Wrap the high baudrate case statements:
#ifdef __linux__
#if __MAX_BAUD > B2000000
case BaudRate::BAUD_2000000:
return 2000000;
case BaudRate::BAUD_2500000:
return 2500000;
case BaudRate::BAUD_3000000:
return 3000000;
case BaudRate::BAUD_3500000:
return 3500000;
case BaudRate::BAUD_4000000:
return 4000000;
#endif
#endif
Environment
- Target arch: aarch64
- Toolchain: GCC
- Libc: musl libc
Activity
tz12323 commentedon Oct 17, 2026
@Sunrisepeak
Hi maintainers, gentle ping on this one — this currently blocks musl libc cross-builds of libserial (e.g. aarch64-linux-musl), so it would be great to get it reviewed/merged.
Problem
When building libserial against a musl toolchain,
SerialPort.cppfails to compile:Root cause: in
SerialPort.h, the high-baudrate enum entries are guarded by#if __MAX_BAUD > B2000000. On musl,<termios.h>only defines baudconstants up to
B1000000, so those enum members are not generated.But the
casestatements inSerialPort.cpp::GetBitRate()reference themwithout the matching guard — hence the hard compile error, not just a
warning.