Need to fix an error when compiling ctime library. clock_gettime and CLOCK_REALTIME not declared in this...
I'm calling clock_gettime with CLOCK_REALTIME to measure the time elapsed for a program of mine. The code is like this:
clock_gettime(CLOCK_REALTIME, &start);
int retCode = system(completeString.c_str());
clock_gettime(CLOCK_REALTIME, &finish);
and it gives me this errors when i try to compile it with
gcc -lrt -o timeSpent.exe time.cpp:
time.cpp: In function 'int main(int, char**)':
time.cpp:38:18: error: 'CLOCK_REALTIME' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
time.cpp:38:40: error: 'clock_gettime' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
Header files:
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#include <Windows.h>
Compiler: MinGW
I hope one of you guys is able to help me fix this problem, and i'm grateful for anyone who tries to help.
Ps: I'm using Windows 10, but i have been successful on compiling this same code before on a Win10 PC. Unfortunately i can't access it, since I'm in another country.
Ps²: I've already tried to #define _POSIX_C_SOURCE 199309L, the only thing it does is add a warning.
c++ time ctime
|
show 2 more comments
I'm calling clock_gettime with CLOCK_REALTIME to measure the time elapsed for a program of mine. The code is like this:
clock_gettime(CLOCK_REALTIME, &start);
int retCode = system(completeString.c_str());
clock_gettime(CLOCK_REALTIME, &finish);
and it gives me this errors when i try to compile it with
gcc -lrt -o timeSpent.exe time.cpp:
time.cpp: In function 'int main(int, char**)':
time.cpp:38:18: error: 'CLOCK_REALTIME' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
time.cpp:38:40: error: 'clock_gettime' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
Header files:
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#include <Windows.h>
Compiler: MinGW
I hope one of you guys is able to help me fix this problem, and i'm grateful for anyone who tries to help.
Ps: I'm using Windows 10, but i have been successful on compiling this same code before on a Win10 PC. Unfortunately i can't access it, since I'm in another country.
Ps²: I've already tried to #define _POSIX_C_SOURCE 199309L, the only thing it does is add a warning.
c++ time ctime
Which header files are you including? Which compiler are you using? Also, that isn't a C++ Standard Library function..
– Neil Butterworth
Jan 1 at 22:19
You should see the answer here
– tunglt
Jan 1 at 22:51
@NeilButterworth, i edited the post with the information you asked.
– Nicholas Lopes
Jan 1 at 23:04
@tunglt i tried out the clock_gettime from the post you shared, and one from Carl Staelin worked out, but it still doesn't fix the CLOCK_REALTIME or CLOCK_MONOTONIC issue. Any insights? Thanks for your help <3
– Nicholas Lopes
Jan 1 at 23:05
1
Do you add#define _POSIX_C_SOURCE 199309L
before including the header file#include <time.h>
?
– tunglt
Jan 1 at 23:15
|
show 2 more comments
I'm calling clock_gettime with CLOCK_REALTIME to measure the time elapsed for a program of mine. The code is like this:
clock_gettime(CLOCK_REALTIME, &start);
int retCode = system(completeString.c_str());
clock_gettime(CLOCK_REALTIME, &finish);
and it gives me this errors when i try to compile it with
gcc -lrt -o timeSpent.exe time.cpp:
time.cpp: In function 'int main(int, char**)':
time.cpp:38:18: error: 'CLOCK_REALTIME' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
time.cpp:38:40: error: 'clock_gettime' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
Header files:
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#include <Windows.h>
Compiler: MinGW
I hope one of you guys is able to help me fix this problem, and i'm grateful for anyone who tries to help.
Ps: I'm using Windows 10, but i have been successful on compiling this same code before on a Win10 PC. Unfortunately i can't access it, since I'm in another country.
Ps²: I've already tried to #define _POSIX_C_SOURCE 199309L, the only thing it does is add a warning.
c++ time ctime
I'm calling clock_gettime with CLOCK_REALTIME to measure the time elapsed for a program of mine. The code is like this:
clock_gettime(CLOCK_REALTIME, &start);
int retCode = system(completeString.c_str());
clock_gettime(CLOCK_REALTIME, &finish);
and it gives me this errors when i try to compile it with
gcc -lrt -o timeSpent.exe time.cpp:
time.cpp: In function 'int main(int, char**)':
time.cpp:38:18: error: 'CLOCK_REALTIME' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
time.cpp:38:40: error: 'clock_gettime' was not declared in this scope
clock_gettime(CLOCK_REALTIME, &start);
Header files:
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#include <Windows.h>
Compiler: MinGW
I hope one of you guys is able to help me fix this problem, and i'm grateful for anyone who tries to help.
Ps: I'm using Windows 10, but i have been successful on compiling this same code before on a Win10 PC. Unfortunately i can't access it, since I'm in another country.
Ps²: I've already tried to #define _POSIX_C_SOURCE 199309L, the only thing it does is add a warning.
c++ time ctime
c++ time ctime
edited Jan 1 at 23:02
Nicholas Lopes
asked Jan 1 at 22:15


Nicholas LopesNicholas Lopes
61
61
Which header files are you including? Which compiler are you using? Also, that isn't a C++ Standard Library function..
– Neil Butterworth
Jan 1 at 22:19
You should see the answer here
– tunglt
Jan 1 at 22:51
@NeilButterworth, i edited the post with the information you asked.
– Nicholas Lopes
Jan 1 at 23:04
@tunglt i tried out the clock_gettime from the post you shared, and one from Carl Staelin worked out, but it still doesn't fix the CLOCK_REALTIME or CLOCK_MONOTONIC issue. Any insights? Thanks for your help <3
– Nicholas Lopes
Jan 1 at 23:05
1
Do you add#define _POSIX_C_SOURCE 199309L
before including the header file#include <time.h>
?
– tunglt
Jan 1 at 23:15
|
show 2 more comments
Which header files are you including? Which compiler are you using? Also, that isn't a C++ Standard Library function..
– Neil Butterworth
Jan 1 at 22:19
You should see the answer here
– tunglt
Jan 1 at 22:51
@NeilButterworth, i edited the post with the information you asked.
– Nicholas Lopes
Jan 1 at 23:04
@tunglt i tried out the clock_gettime from the post you shared, and one from Carl Staelin worked out, but it still doesn't fix the CLOCK_REALTIME or CLOCK_MONOTONIC issue. Any insights? Thanks for your help <3
– Nicholas Lopes
Jan 1 at 23:05
1
Do you add#define _POSIX_C_SOURCE 199309L
before including the header file#include <time.h>
?
– tunglt
Jan 1 at 23:15
Which header files are you including? Which compiler are you using? Also, that isn't a C++ Standard Library function..
– Neil Butterworth
Jan 1 at 22:19
Which header files are you including? Which compiler are you using? Also, that isn't a C++ Standard Library function..
– Neil Butterworth
Jan 1 at 22:19
You should see the answer here
– tunglt
Jan 1 at 22:51
You should see the answer here
– tunglt
Jan 1 at 22:51
@NeilButterworth, i edited the post with the information you asked.
– Nicholas Lopes
Jan 1 at 23:04
@NeilButterworth, i edited the post with the information you asked.
– Nicholas Lopes
Jan 1 at 23:04
@tunglt i tried out the clock_gettime from the post you shared, and one from Carl Staelin worked out, but it still doesn't fix the CLOCK_REALTIME or CLOCK_MONOTONIC issue. Any insights? Thanks for your help <3
– Nicholas Lopes
Jan 1 at 23:05
@tunglt i tried out the clock_gettime from the post you shared, and one from Carl Staelin worked out, but it still doesn't fix the CLOCK_REALTIME or CLOCK_MONOTONIC issue. Any insights? Thanks for your help <3
– Nicholas Lopes
Jan 1 at 23:05
1
1
Do you add
#define _POSIX_C_SOURCE 199309L
before including the header file #include <time.h>
?– tunglt
Jan 1 at 23:15
Do you add
#define _POSIX_C_SOURCE 199309L
before including the header file #include <time.h>
?– tunglt
Jan 1 at 23:15
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999363%2fneed-to-fix-an-error-when-compiling-ctime-library-clock-gettime-and-clock-realt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999363%2fneed-to-fix-an-error-when-compiling-ctime-library-clock-gettime-and-clock-realt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Which header files are you including? Which compiler are you using? Also, that isn't a C++ Standard Library function..
– Neil Butterworth
Jan 1 at 22:19
You should see the answer here
– tunglt
Jan 1 at 22:51
@NeilButterworth, i edited the post with the information you asked.
– Nicholas Lopes
Jan 1 at 23:04
@tunglt i tried out the clock_gettime from the post you shared, and one from Carl Staelin worked out, but it still doesn't fix the CLOCK_REALTIME or CLOCK_MONOTONIC issue. Any insights? Thanks for your help <3
– Nicholas Lopes
Jan 1 at 23:05
1
Do you add
#define _POSIX_C_SOURCE 199309L
before including the header file#include <time.h>
?– tunglt
Jan 1 at 23:15