Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difftime not found by linker? #1125

Closed
zgoda opened this issue May 10, 2017 · 1 comment
Closed

difftime not found by linker? #1125

zgoda opened this issue May 10, 2017 · 1 comment

Comments

@zgoda
Copy link
Contributor

zgoda commented May 10, 2017

The standard function difftime from time.h and ctime seems to be not available for linker. The code that uses this function compiles, but I get linker errors:

C+ app/application.cpp
AR out/build/app_app.a
LD out/build/app.out
out/build/app_app.a(application.o):(.text._Z8showTimev+0x10): undefined reference to `difftime'
out/build/app_app.a(application.o): In function `showTime()':
/opt/Sming/Sming/SmingCore/Boards.h:18: undefined reference to `difftime'
collect2: error: ld returned 1 exit status

Sample code that causes this:

#include <SmingCore/SmingCore.h>
#include "user_config.h"

time_t t0;

Timer procTimer;

void showTime()
{
	time_t now = SystemClock.now().toUnixTime();
	Serial.print("elapsed: ");
	Serial.println(difftime(now, t0));
}


void init()
{
	Serial.begin(SERIAL_BAUD_RATE);
	t0 = SystemClock.now().toUnixTime();
	procTimer.initializeMs(2000, showTime).start();
}

Do I need to do anything special to use it?

@mikee47
Copy link
Contributor

mikee47 commented Apr 8, 2024

Just a note that difftime is available. However, it returns a double float:

double
difftime (time_t tim1,
	time_t tim2)
{
  return (double)(tim1 - tim2);
}

I suspect double is used as historically some platforms used floating-point values to represent time_t. Better to just subtract the two values and stick with integers.

@mikee47 mikee47 closed this as completed Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants