Skip to content

Title: Build failure on musl libc: BAUD_2000000 and related enum members missing #523

Closed

Description

@tz12323

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

  1. Use an aarch64-linux-musl GCC toolchain
  2. Build LibSerial from source
  3. 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

  1. tz12323 commented on Oct 17, 2026

    @tz12323
    ContributorAuthor

    @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.cpp fails to compile:

    
    SerialPort.cpp:1226:24: error: 'BAUD_2000000' is not a member of 'LibSerial::BaudRate'
    SerialPort.cpp:1230:24: error: 'BAUD_2500000' is not a member of 'LibSerial::BaudRate'
    SerialPort.cpp:1234:24: error: 'BAUD_3000000' is not a member of 'LibSerial::BaudRate'
    SerialPort.cpp:1238:24: error: 'BAUD_3500000' is not a member of 'LibSerial::BaudRate'
    SerialPort.cpp:1242:24: error: 'BAUD_4000000' is not a member of 'LibSerial::BaudRate'
    
    

    Root cause: in SerialPort.h, the high-baudrate enum entries are guarded by
    #if __MAX_BAUD > B2000000. On musl, <termios.h> only defines baud
    constants up to B1000000, so those enum members are not generated.
    But the case statements in SerialPort.cpp::GetBitRate() reference them
    without the matching guard — hence the hard compile error, not just a
    warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions