7 Replies Latest reply on Sep 9, 2019 1:23 AM by AnjanaM_61

    How to add libm for math funtion?

    HyCh_4218006

      Hi teams,

       

      I am using ModusToolbox with BTSDK 1.4.

      To use math function, I included math.h, and -lm flags via IDE Project  properties.

      During build, I got the following errors.

      How can I add libm successfully?

       

      00:10:02 **** Incremental Build of configuration Debug for project BLE_Mesh_Tracker_mainapp ****

      "C:\\Users\\firebird\\ModusToolbox\\tools\\modus-shell-1.0\\bin\\make" -j16 all

      make --no-print-directory pre-build

      C:/Users/firebird/ModusToolbox/tools/modus-shell-1.0/bin/bash --norc --noprofile "C:/Users/firebird/ModusToolbox/tools/wiced-scripts-1.0/bt_pre_build.bash" "--shell=C:/Users/firebird/ModusToolbox/tools/modus-shell-1.0" "--scripts=C:/Users/firebird/ModusToolbox/tools/wiced-scripts-1.0" "--defs=XIP_DS_OFFSET=0x10100 XIP_OBJ=./mesh_location_server.o;./spar_setup.o;./wiced_platform.o;./wiced_platform_pin_config.o;./lib_installer.o APP_DS2_OBJ=./fw_update_copy_sflash.o;./ofu_ds2_lib.a APP_DS2_LEN=0x2000 BTP=C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/platforms/208XX_OCF.btp FLASH0_BEGIN_ADDR=0x00500000 FLASH0_LENGTH=0x00040000 SRAM_BEGIN_ADDR=0x00200000 SRAM_LENGTH=0x00070000 AON_AREA_END=0x00204574 ISTATIC_BEGIN=0x500C00 ISTATIC_LEN=0x400 NUM_PATCH_ENTRIES=256" "--patch=C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/internal/20819A1/patches/patch.elf" "--ld=C:\Users\firebird\Documents\mtw\BLE_Mesh_Tracker_mainapp/Debug/mainapp.ld"

      generated C:\Users\firebird\Documents\mtw\BLE_Mesh_Tracker_mainapp/Debug/mainapp.ld

       

      make --no-print-directory main-build

      Building file: ../20819/generated/lib_installer.c

      Invoking: GNU ARM Cross C Compiler

      arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mthumb-interwork -mlittle-endian -mfloat-abi=soft -Os -ffunction-sections -Wall  -g3 -DWICED_BT_TRACE_ENABLE -DHCI_CONTROL -DLOW_POWER_NODE=0 -DOTA_FW_UPGRADE_SFLASH_COPY -DENABLE_SFLASH_UPGRADE -DSS_LOCATION=0x500000 -DVS_LOCATION=0x500400 -DDS_LOCATION=0x501400 -DDS2_LOCATION=0x53E000 -DCYW20819A1=1 -DBCM20819A1=1 -DBCM20819=1 -DCYW20819=1 -DCHIP=20819 -DAPP_CHIP=20819 -DOTA_CHIP=20819 -DCHIP_REV_A_20819A1=1 -DCOMPILER_ARM -DSPAR_APP_SETUP=application_setup -D__TARGET_CPU_CORTEX_M4 -D__ARMCC_VERSION=400677 -DPLATFORM='"CYBT_213043_MESH"' -DWICED_SDK_MAJOR_VER=1 -DWICED_SDK_MINOR_VER=1 -DWICED_SDK_REV_NUMBER=4 -DWICED_SDK_BUILD_NUMBER=993 -DSPAR_CRT_SETUP=spar_crt_setup -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/include/20819/stack" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/include/20819/hal" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/include/20819/internal" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/include" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/common/include" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/include/20819" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/internal/20819A1" -I"C:\Users\firebird\Documents\mtw\BLE_Mesh_Tracker_mainapp" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/common/libraries/mesh_app_lib" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/platforms/CYBT_213043_MESH" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/common" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/platforms" -I"C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/common/libraries/fw_upgrade_lib" -std=gnu11 -mlong-calls -ffreestanding -Wno-implicit-function-declaration -fshort-wchar -funsigned-char -Wno-strict-aliasing -std=gnu11 -isystem "C:/Users/firebird/ModusToolbox/tools/gcc-7.2.1-1.0/arm-none-eabi/include" -isystem "C:/Users/firebird/ModusToolbox/tools/gcc-7.2.1-1.0/arm-none-eabi/lib/include" -isystem "C:/Users/firebird/ModusToolbox/tools/gcc-7.2.1-1.0/arm-none-eabi/lib/include-fixed" -Wno-implicit-function-declaration -Wno-unused-variable -Wno-unused-function @C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/internal/20819A1/gcc/20819A1.cflag -MMD -MP -MF"20819/generated/lib_installer.d" -MT"20819/generated/lib_installer.o" -c -o "20819/generated/lib_installer.o" "../20819/generated/lib_installer.c"

      Finished building: ../20819/generated/lib_installer.c

       

      Building target: BLE_Mesh_Tracker_mainapp.elf

      Invoking: GNU ARM Cross C Linker

      arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mthumb-interwork -mlittle-endian -mfloat-abi=soft -Os -ffunction-sections -Wall  -g3 -T "C:\Users\firebird\Documents\mtw\BLE_Mesh_Tracker_mainapp/Debug/mainapp.ld" -nostartfiles -nostdlib -LC:/Users/firebird/ModusToolbox/tools/gcc-7.2.1-1.0/lib -Wl,-Map,"BLE_Mesh_Tracker_mainapp.map" -funsigned-char -Wno-strict-aliasing -Xlinker --gc-sections -Wl,-A,thumb -nodefaultlibs -Wl,--entry=spar_crt_setup -Wl,-z,muldefs -Wl,--no-warn-mismatch -Wl,--just-symbols="C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/internal/20819A1/patches/patch.elf" -o "BLE_Mesh_Tracker_mainapp.elf" -Wl,--start-group  ./libraries/mesh_app_lib/mesh_app_gatt.o ./libraries/mesh_app_lib/mesh_app_hci.o ./libraries/mesh_app_lib/mesh_app_provision_server.o ./libraries/mesh_app_lib/mesh_application.o ./libraries/mesh_app_lib/wiced_bt_cfg.o  ./libraries/fw_upgrade_lib/ecc_pp.o ./libraries/fw_upgrade_lib/fw_update_copy_sflash.o ./libraries/fw_upgrade_lib/fw_upgrade.o ./libraries/fw_upgrade_lib/ota_fw_upgrade.o ./libraries/fw_upgrade_lib/ota_fw_upgrade_common.o ./libraries/fw_upgrade_lib/sha256.o  ./bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/common/spar_setup.o  ./GeneratedSource/cycfg.o ./GeneratedSource/cycfg_pins.o ./GeneratedSource/cycfg_routing.o  ./20819/generated/lib_installer.o  ./led_control.o ./mesh_tracker.o ./wiced_platform.o  C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/adc_audio_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/multi_adv_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/wiced_ble_pre_init_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/wiced_hidd_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/celt_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/air_motion.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/adpcm_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/ofu_ds2_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/mesh_core_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/mesh_models_lib.a C:/Users/firebird/ModusToolbox/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/mesh_provisioner_lib.a -l"gcc" -l"m" -Wl,--end-group

      c:/users/firebird/modustoolbox/tools/gcc-7.2.1-1.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m\libm.a(lib_a-w_pow.o): In function `pow':

      w_pow.c:(.text.pow+0x104): undefined reference to `__errno'

      w_pow.c:(.text.pow+0x11e): undefined reference to `__errno'

      w_pow.c:(.text.pow+0x17c): undefined reference to `__errno'

      w_pow.c:(.text.pow+0x240): undefined reference to `__errno'

      w_pow.c:(.text.pow+0x24a): undefined reference to `__errno'

      collect2.exe: error: ld returned 1 exit status

      make[1]: *** [BLE_Mesh_Tracker_mainapp.elf] Error 1

      make: *** [all] Error 2

       

      00:10:06 Build Finished (took 3s.462ms)

        • 1. Re: How to add libm for math funtion?
          PICH_4397076

          You can try like the below.

           

          Go to Project and select Properties. Expand C/C++ Build and choose Settings. Under the Tool settings tab expand GCC Linker and select Libraries. At the right of the window, add a library named m at Libraries (-l).

           

          Thanks,

          • 2. Re: How to add libm for math funtion?
            PICH_4397076

            I'm so sorry for the misinformation.

            I thought it worked, but I get the same error like the below.

             

            Building target: BLE_Mesh_Dimmer_mainapp.elf

            Invoking: GNU ARM Cross C Linker

            arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mthumb-interwork -mlittle-endian -mfloat-abi=soft -Os -ffunction-sections -Wall  -g3 -T "C:\Users\PilHeon\mtw\BLE_Mesh_Dimmer_mainapp/Debug/mainapp.ld" -nostartfiles -nostdlib -LC:/Users/PilHeon/ModusToolbox_1.1/tools/gcc-7.2.1-1.0/lib -Wl,-Map,"BLE_Mesh_Dimmer_mainapp.map" -funsigned-char -Wno-strict-aliasing -Xlinker --gc-sections -Wl,-A,thumb -nodefaultlibs -Wl,--entry=spar_crt_setup -Wl,-z,muldefs -Wl,--no-warn-mismatch -Wl,--just-symbols="C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/internal/20819A1/patches/patch.elf" -o "BLE_Mesh_Dimmer_mainapp.elf" -Wl,--start-group  ./libraries/mesh_app_lib/mesh_app_gatt.o ./libraries/mesh_app_lib/mesh_app_hci.o ./libraries/mesh_app_lib/mesh_app_provision_server.o ./libraries/mesh_app_lib/mesh_application.o ./libraries/mesh_app_lib/wiced_bt_cfg.o  ./libraries/fw_upgrade_lib/ecc_pp.o ./libraries/fw_upgrade_lib/fw_update_copy_sflash.o ./libraries/fw_upgrade_lib/fw_upgrade.o ./libraries/fw_upgrade_lib/ota_fw_upgrade.o ./libraries/fw_upgrade_lib/ota_fw_upgrade_common.o ./libraries/fw_upgrade_lib/sha256.o  ./bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/common/spar_setup.o  ./GeneratedSource/cycfg.o ./GeneratedSource/cycfg_pins.o ./GeneratedSource/cycfg_routing.o  ./20819/generated/lib_installer.o  ./button_control.o ./dimmer.o ./wiced_platform.o  C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/adc_audio_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/multi_adv_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/wiced_ble_pre_init_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/wiced_hidd_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/celt_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/air_motion.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/adpcm_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/ofu_ds2_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/mesh_core_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/mesh_models_lib.a C:/Users/PilHeon/ModusToolbox_1.1/libraries/bt_sdk-1.1/components/BT-SDK/208XX-A1_Bluetooth/WICED/libraries/mesh_provisioner_lib.a -l"gcc" -lm -Wl,--end-group

            c:/users/pilheon/modustoolbox_1.1/tools/gcc-7.2.1-1.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m\libm.a(lib_a-w_pow.o): In function `pow':

            w_pow.c:(.text.pow+0x104): undefined reference to `__errno'

            w_pow.c:(.text.pow+0x11e): undefined reference to `__errno'

            w_pow.c:(.text.pow+0x17c): undefined reference to `__errno'

            w_pow.c:(.text.pow+0x240): undefined reference to `__errno'

            w_pow.c:(.text.pow+0x24a): undefined reference to `__errno'

            collect2.exe: error: ld returned 1 exit status

            make[1]: *** [BLE_Mesh_Dimmer_mainapp.elf] Error 1

            make: *** [all] Error 2

            • 3. Re: How to add libm for math funtion?
              PICH_4397076

              Dear All,,,

               

              Any update for us???

              The libm linking required for floating point operations does not work as requested last time.

               

              I did the below to use pow() function!

              ============================================================================

              Go to Project and select Properties. Expand C/C++ Build and choose Settings. Under the Tool settings tab expand GCC Linker and select Libraries. At the right of the window, add a library named m at Libraries (-l).

              ===============================================================

               

              But, the error is happened like the below capture.

              =====================================================

              w_pow.c:(.text.pow+0x104): undefined reference to `__errno'

              w_pow.c:(.text.pow+0x11e): undefined reference to `__errno'

              w_pow.c:(.text.pow+0x17c): undefined reference to `__errno'

              w_pow.c:(.text.pow+0x240): undefined reference to `__errno'

              w_pow.c:(.text.pow+0x24a): undefined reference to `__errno'

              collect2.exe: error: ld returned 1 exit status

              make[1]: *** [BLE_Mesh_Dimmer_mainapp.elf] Error 1

              make: *** [all] Error 2

              ============================================


              Please let us know how to do!!!

               

              Thanks,

              • 4. Re: How to add libm for math funtion?
                AnjanaM_61

                Hello ,

                 

                Could you please try the below format in make file with lib file location ?

                CY_APP_INCLUDES += -I$(CY_WICED_LIB_COMP_FULL)/../examples/BT-SDK/20706-A2_Bluetooth/apps/demo/audio/headset

                 

                Thanks,

                Anjana

                • 5. Re: How to add libm for math funtion?
                  AnjanaM_61

                  Hi,

                   

                  Not sure how well we can be expected to support issues with external libraries. Could you please try add the flag -lc also ?

                  As in the following link which looks close to your issue: http://pinguino.cc/forum/showthread.php?tid=4463

                   

                  Thanks,

                  Anjana

                  • 6. Re: How to add libm for math funtion?
                    HyCh_4218006

                    I added -lc as you suggested, and the errno related error disappered, and built.

                    Seems to be solved, but still I can't check the result because printf() does not support %f.

                    Do you know how I can use %f in printf() or TRACE() function?

                    • 7. Re: How to add libm for math funtion?
                      AnjanaM_61

                      Hi,

                       

                      I am sorry, %f is not supported in our SDK lib. You may have to use %d itself to print by multiplying or dividing the answer by 10's power.

                      I don't see any other way.

                       

                      Regards,
                      Anjana

                      1 of 1 people found this helpful