2

I'm trying to use boost::program_options and am getting this error at compile:

$ g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright (C) 2015 Free Software Foundation, Inc.

...

/data/shared/ip_tools/include/boost/smart_ptr/detail/yield_k.hpp:143:25: error: variable ‘timespec rqtp’ has initializer but incomplete type
  143 |         struct timespec rqtp = { 0, 0 };
      |                         ^~~~
/data/shared/ip_tools/include/boost/smart_ptr/detail/yield_k.hpp:151:9: error: ‘nanosleep’ was not declared in this scope
  151 |         nanosleep( &rqtp, 0 );
      |         ^~~~~~~~~

My (redacted) code:

#include <boost/program_options.hpp>
int main(int argc, char* argv[]) {
  namespace po = boost::program_options;
  po::options_description cmd_opts{"Options"};
  po::options_description config_file_opts;
etc.

Is this something wrong with my boost install? This seems like a library issue...

jkang
  • 483
  • 7
  • 19

1 Answers1

0

It would indicate a missing include. You should be able to work around it by including it manually before including boost:

https://en.cppreference.com/w/c/chrono/timespec

#include <time.h>

It could also be a compiler lacking C11 support. I'm on GCC 10, for comparison.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Hmm, shouldn't boost include these libraries itself? I'm kinda confused as to why I'd need to include libraries that boost depends on. – jkang Jun 12 '20 at 00:56
  • Yes. That's why I called it a workaround. Does it solve it? If, so please report the bug or submit a pull-request – sehe Jun 12 '20 at 01:04
  • So it appears the issue was unrelated. My project (which I inherited some code from) had a time.h defined. This apparently confused boost as they use time.h as well. It turned out no code used this custom time.h so I just deleted it. And now it at least compiles (but doesn't link, that's another issue...) – jkang Jun 12 '20 at 01:10
  • This spells ODR issues. If you have ostensibly different versions of `time.h` in the path, and they conflict (meaning the header guards were the same), you risk building one Translation Unit ("cpp file") with a different set of definitions than the other. That leads to Undefined Behavior – sehe Jun 12 '20 at 01:13
  • Things to watch for: 1. physical conflicting installations and duplicate/conflicting include paths 2. include all system libraries with `#include ` and only your own (non-system) includes with `#include "headername"` – sehe Jun 12 '20 at 01:14
  • There's a default time.h right? That boost apparently uses? As opposed to this custom time.h code that was part of this project. How are such issues dealt with? Just not naming it time.h? – jkang Jun 12 '20 at 01:15
  • I linked you to the C11 documentation page on cppreference. It doesn't get much clearer than that: it documents the standard. Of course Boost supposes that one to be present. – sehe Jun 12 '20 at 01:16
  • Your job is to find out how corrupt/conflicting copies of a system are poisoning the build. Mind you, GCC 4.8 is old, so perhaps you need to use a suitably old boost version AND perhaps this was at some point reason for someone (else?) to include a hacked-up version of a system header to get some other things to compile (that's not a good a plan, but I've seen people do weirder things I guess) – sehe Jun 12 '20 at 01:18
  • Sure, thanks. I guess the answer is that never name a custom file time.h? – jkang Jun 12 '20 at 01:21
  • @jkang Oh you meant you had a random user header with the same name? I thought you meant "a custom ***version*** of the standard header". Yeah, avoiding standard header names helps. However, if you adhered to the policy of separating `` and `"user.h" includes I mentioned just above, this would mean that boost would never have found your header. Perhaps boost needs to replace `#include "ctime.h"` with `#include ` – sehe Jun 12 '20 at 01:31
  • https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename/41646905 – sehe Jun 12 '20 at 01:31
  • So the project code has #include "time.h" And the other module that included it is Boost, which I have no control over. My code has no reference to the system – jkang Jun 12 '20 at 01:54
  • Note that the header name stays ` regardless of the angle brackets, but yeah you're on track – sehe Jun 12 '20 at 02:22