Author Topic: Need on help on hardware_concurrency  (Read 52004 times)

will

  • Newbie
  • *
  • Posts: 1
    • View Profile
Need on help on hardware_concurrency
« on: October 19, 2011, 03:47:34 PM »
Hi Can anyone help me with the following code snippet testing hardware_concurrency.

will@localhost:~/testspace/thread$ cat testHardware.cpp
#include <iostream>
#include <thread>
using namespace std;
int main() {
  cerr << "Hardware concurrency: " << std::thread::hardware_concurrency() << endl;
  return 0;
}
will@localhost:~/testspace/thread$ g++ -O2 -o hardware testHardware.cpp -I/usr/include/justthread -L/usr/lib64/ -ljustthread -pthread
/usr/lib64//libjustthread.a(chrono.o): In function `std::__jssZ46::chrono::(anonymous namespace)::get_monotonic_nanoseconds()':
chrono.cpp:(.text+0x1e): undefined reference to `clock_gettime'
/usr/lib64//libjustthread.a(chrono.o): In function `std::__jssZ46::chrono::system_clock::now()':
chrono.cpp:(.text+0x5b): undefined reference to `clock_gettime'
/usr/lib64//libjustthread.a(chrono.o): In function `std::__jssZ46::this_thread::__sleep_until(std::__jssZ46::chrono::time_point<std::__jssZ46::chrono::system_clock, std::__jssZ46::chrono::duration<long long, std::__jssZ46::ratio<1ll, 1000000000ll> > > const&)':
chrono.cpp:(.text+0x1bd): undefined reference to `clock_nanosleep'
/usr/lib64//libjustthread.a(chrono.o): In function `std::__jssZ46::this_thread::__sleep_until(std::__jssZ46::chrono::time_point<std::__jssZ46::chrono::monotonic_clock, std::__jssZ46::chrono::duration<long long, std::__jssZ46::ratio<1ll, 1000000000ll> > > const&)':
chrono.cpp:(.text+0x220): undefined reference to `clock_nanosleep'
collect2: ld returned 1 exit status

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: Need on help on hardware_concurrency
« Reply #1 on: October 19, 2011, 03:58:12 PM »
You also need to link against librt if you're using the static library

g++ -O2 -o hardware testHardware.cpp -I/usr/include/justthread -L/usr/lib64/ -ljustthread -pthread -lrt

I am surprised that the shared library libjustthread.so (which automatically pulls in librt) isn't being used though.