2

I'm trying to do the first tutorial of ROS on Windows in Visual Studio 2015.

First I created a new WIN 32 Console application and copied the code from here. Then I configured the project as it is described in the guide. While Debugging there came up several errors:

  • The identifier "__builtin_expect" is undefined in the files service_client.h and TestTalker.cpp (which is the name of my program).
  • Cannot open source file "sys/time.h"

The SDK from wiki.ros.org runs, I tested it. I have no idea what's wrong. I hope someone can help me.

Thank you in advance!!

jotik
  • 17,044
  • 13
  • 58
  • 123
chris_2091
  • 47
  • 7

1 Answers1

2

__builtin_expect is a GCC extension. It is not provided by Visual Studio.

Since it only provides a hint to the compiler to optimize for CPU branch-prediction, one could just replace all instances of __builtin_expect(expr, c) with expr.

Or, in cases where it fits, use __assume instead, as described in this answer.

Community
  • 1
  • 1
jotik
  • 17,044
  • 13
  • 58
  • 123
  • Those are different: `__builtin_expect` gives a hint to the compiler that an expression is most likely or more often true whereas `__assume` leads to UB when the hint is wrong. From [`__assume` doc](https://msdn.microsoft.com/en-us/library/1b3fsfxw%28VS.80%29.aspx): "_Because the compiler generates code based on `__assume`, that code might not run correctly if the expression inside the `__assume` statement is false at run time._" – YSC Feb 09 '17 at 12:29
  • I'd suggest to just `#define __builtin_expect(x,y)` and let the optimization and branch prediction do the work. Related: [Optimizing a branch for a known more-common path](http://stackoverflow.com/q/35938249/5470596). – YSC Feb 09 '17 at 12:32
  • @YSC Double underscores in identifiers are reserved for the implementation. – jotik Feb 09 '17 at 12:37
  • Right. Then your answer is the best one can do. Go and `sed` the hell out of `service_client.h`! – YSC Feb 09 '17 at 12:38
  • Thank you all! The problem is that there is no __builtin_expect in service_client.h, the errors appears in the following linie : private: // This works around a problem with the OSX linker that causes the static variable declared by // ROS_ERROR to error with missing symbols when it's used directly in the templated call() method above // This for some reason only showed up in the rxtools package void deserializeFailed(const std::exception& e) { ROS_ERROR("Exception thrown while while deserializing service call: %s", e.what()); } – chris_2091 Feb 09 '17 at 13:04
  • 1
    the real definition is in console.h: #ifdef WIN32 #define ROS_LIKELY(x) (x) #define ROS_UNLIKELY(x) (x) #else #define ROS_LIKELY(x) __builtin_expect((x),1) #define ROS_UNLIKELY(x) __builtin_expect((x),0) #endif – chris_2091 Feb 09 '17 at 13:05
  • @chris_2091 Since this answer helped you, please accept it by clicking the check mark below the vote count. – YSC Feb 09 '17 at 13:16