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,编译成功


 

猜你喜欢

转载自blog.csdn.net/MashiMaroJ/article/details/126489792