• undefined reference to `timersub‘ 错误处理


    将paho mqtt C移植到IMX6上去,编译时报错

    Scanning dependencies of target test95
    [ 51%] Building C object test/CMakeFiles/test95.dir/test95.c.o
    /home/gateway/Eden/paho.mqtt.c/test/test95.c: In function ‘MyLog’:
    /home/gateway/Eden/paho.mqtt.c/test/test95.c:124:2: warning: implicit declaration of function ‘localtime_r’; did you mean ‘localtime’? [-Wimplicit-function-declaration]
      localtime_r(&ts.tv_sec, &timeinfo);
      ^~~~~~~~~~~
      localtime
    /home/gateway/Eden/paho.mqtt.c/test/test95.c: In function ‘MySleep’:
    /home/gateway/Eden/paho.mqtt.c/test/test95.c:147:2: warning: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
      usleep(milliseconds*1000);
      ^~~~~~
      sleep
    /home/gateway/Eden/paho.mqtt.c/test/test95.c: In function ‘elapsed’:
    /home/gateway/Eden/paho.mqtt.c/test/test95.c:198:2: warning: implicit declaration of function ‘timersub’; did you mean ‘utimes’? [-Wimplicit-function-declaration]
      timersub(&now, &start_time, &res);
      ^~~~~~~~
      utimes
    [ 53%] Linking C executable test95
    CMakeFiles/test95.dir/test95.c.o: In function `elapsed':
    test95.c:(.text+0x3e4): undefined reference to `timersub'
    collect2: error: ld returned 1 exit status
    test/CMakeFiles/test95.dir/build.make:95: recipe for target 'test/test95' failed
    make[2]: *** [test/test95] Error 1
    CMakeFiles/Makefile2:352: recipe for target 'test/CMakeFiles/test95.dir/all' failed
    make[1]: *** [test/CMakeFiles/test95.dir/all] Error 2
    Makefile:160: recipe for target 'all' failed
    make: *** [all] Error 2

    原因是我写的cmake配置文件(CMAKE_TOOLCHAIN_FILE)中

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -mfloat-abi=hard ....")

    有-std=c99,这个是之前其他项目中保留的,将-std=c99删除,再cmake生成MAKEFILE,然后再make,编译成功


     

  • 相关阅读:
    二叉树—堆(C语言实现)
    Mysql Explain
    (栈)剑指 Offer 09. 用两个栈实现队列(java)
    非技术背景项目经理如何发展?
    LeetCode //C - 173. Binary Search Tree Iterator
    提升医院安全的关键利器——医院安全(不良)事件报告系统源码
    2024-Pop!_OS新版本,新桌面环境的消息
    快递单号物流揽收后没有信息的单号快速筛选出
    SpringBoot 学习笔记
    李航《统计学习方法》笔记之k近邻法
  • 原文地址:https://blog.csdn.net/MashiMaroJ/article/details/126489792