ublk-org / ublksrv

ublk: userspace block device driver
MIT License
147 stars 50 forks source link

[build error]gettimeofday is undefined #20

Closed old-memories closed 2 years ago

old-memories commented 2 years ago

eqcow2/qcow2.cpp: In constructor ‘MetaFlushingState::MetaFlushingState(Qcow2TopTable&, bool)’: qcow2/qcow2.cpp:917:2: error: ‘gettimeofday’ was not declared in this scope; did you mean ‘SYS_gettimeofday’? 917 | gettimeofday(&last_flush, NULL); | ^~~~ | SYS_gettimeofday qcow2/qcow2.cpp: In member function ‘void MetaFlushingState::done(Qcow2State&, ublksrv_queue*)’: qcow2/qcow2.cpp:1121:2: error: ‘gettimeofday’ was not declared in this scope; did you mean ‘SYS_gettimeofday’? 1121 | gettimeofday(&last_flush, NULL); | ^~~~ | SYS_gettimeofday qcow2/qcow2.cpp: In member function ‘bool MetaFlushingState::need_flush(int)’: qcow2/qcow2.cpp:1324:3: error: ‘gettimeofday’ was not declared in this scope; did you mean ‘SYS_gettimeofday’? 1324 | gettimeofday(&t, NULL); | ^~~~ | SYS_gettimeofday make[2]: [Makefile:750: ublk-qcow2.o] Error 1 make[2]: Leaving directory '/root/work/ubdsrv' make[1]: [Makefile:828: all-recursive] Error 1 make[1]: Leaving directory '/root/work/ubdsrv' make: *** [Makefile:476: all] Error 2

Maybe we should include <sys/time.h> in qcow2/qcow2.h? I did so and it succeeded.

ming1 commented 2 years ago

Maybe we should include <sys/time.h> in qcow2/qcow2.h? I did so and it > succeeded.

OK, care to send one MR?

BTW, not trigger in my test environment(fedora).

thanks,

ming1 commented 2 years ago

Looks it is better to use system_clock of libstdc++, given qcow2 is basically done via c++, and I will fix this issue.

ming1 commented 2 years ago

Fixed by c4995da ("qcow2: replace gettimeofday with std::chrono::system_clock::now()")

old-memories commented 2 years ago

Thanks for the fix, the build succeeds now!