private-octopus / picoquic

Minimal implementation of the QUIC protocol
MIT License
540 stars 159 forks source link

Build seems to fail because of math unlinked #1503

Closed ogkloo closed 1 year ago

ogkloo commented 1 year ago

Does this happen for anyone else? This is on a fresh install of Ubuntu 20.04 (a vagrant VM), with openssl and picotls compiled. It works if I link math in. Is this worth opening a pull request for or does this not happen consistently?

Edit: This does not happen consistently, build works fine on 22.04 (also through vagrant).

Bug: Build fails with error:

[ 90%] Linking CXX executable picoquic_ct
/usr/bin/ld: libpicoquic-test.a(mediatest.c.o): in function `mediatest_check_stats':
mediatest.c:(.text+0x5e1): undefined reference to `sqrt'
/usr/bin/ld: libpicoquic-test.a(mediatest.c.o): in function `mediatest_one':
mediatest.c:(.text+0x2320): undefined reference to `sqrt'
/usr/bin/ld: mediatest.c:(.text+0x2336): undefined reference to `sqrt'
/usr/bin/ld: libpicoquic-test.a(warptest.c.o): in function `warptest_check_stats':
warptest.c:(.text+0xe91): undefined reference to `sqrt'
/usr/bin/ld: libpicoquic-test.a(warptest.c.o): in function `warptest_one':
warptest.c:(.text+0x2d2a): undefined reference to `sqrt'
/usr/bin/ld: libpicoquic-test.a(warptest.c.o):warptest.c:(.text+0x2d40): more undefined references to `sqrt' follow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/picoquic_ct.dir/build.make:92: picoquic_ct] Error 1
make[1]: *** [CMakeFiles/Makefile2:182: CMakeFiles/picoquic_ct.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

How to reproduce: Follow instructions as written in README.md.

How I got it working: Add -lm to linker flags:

macro(set_picoquic_compile_settings)
    set_target_properties(${ARGV0}
        PROPERTIES
            C_STANDARD 11
            C_STANDARD_REQUIRED YES
            C_EXTENSIONS YES)
    set_target_properties(${ARGV0}
        PROPERTIES
            CXX_STANDARD 11
            CXX_STANDARD_REQUIRED YES
            CXX_EXTENSIONS YES)
    target_compile_options(${ARGV0}
        PRIVATE
            $<$<C_COMPILER_ID:Clang>: -O3 -Wall -fno-exceptions
                -fno-signed-zeros -fno-trapping-math
                ${PICOQUIC_ADDITIONAL_C_FLAGS}>
            $<$<C_COMPILER_ID:AppleClang>: -O3 -Wall -fno-exceptions
                -fno-signed-zeros -fno-trapping-math
                ${PICOQUIC_ADDITIONAL_C_FLAGS}>
            $<$<C_COMPILER_ID:GNU>: -O3 -Wall -fno-exceptions
                -fno-signed-zeros -frename-registers -fno-trapping-math
                ${PICOQUIC_ADDITIONAL_C_FLAGS}>
            $<$<C_COMPILER_ID:MSVC>: >
            $<$<CXX_COMPILER_ID:Clang>: -O3 -Wall -fno-exceptions
                -fno-signed-zeros -fno-trapping-math
                ${PICOQUIC_ADDITIONAL_CXX_FLAGS}>
            $<$<CXX_COMPILER_ID:AppleClang>: -O3 -Wall -fno-exceptions
                -fno-signed-zeros -fno-trapping-math
                ${PICOQUIC_ADDITIONAL_CXX_FLAGS}>
            $<$<CXX_COMPILER_ID:GNU>: -O3 -Wall -fno-exceptions
                -fno-signed-zeros -frename-registers -fno-trapping-math
                ${PICOQUIC_ADDITIONAL_CXX_FLAGS}>
            $<$<CXX_COMPILER_ID:MSVC>: >)
    target_compile_definitions(${ARGV0} PRIVATE ${PICOQUIC_COMPILE_DEFINITIONS})
    target_link_options(${ARGV0} PRIVATE ${PICOQUIC_LINKER_FLAGS} -lm)
endmacro()
huitema commented 1 year ago

@ogkloo I have created PR #1507, which simply removes usage of sqrt() in tests, Can you verify that it solves your issue?

ogkloo commented 1 year ago

@huitema confirmed that does fix it on 20.04.

huitema commented 1 year ago

Thanks, @ogkloo! I will merge the PR.