Question

I built a static library from the GPSTk source (following the directions under "BuildingGPSTkUnderWindows") using MS Visual C++ 2005 Express Edition.

Now, I want to include that library in another project which also includes sockets. The problem is that Daytime.hpp redefines struct timeval, which causes a compile error. Again, the library compiles fine under VC++ 2005 Express Edition. The problem occurs when I add the resulting library to another project.

How can this be fixed?

-- AmyV - 03 Apr 2008

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

I'm going to discuss the reason DayTime defined the structure. with some of the developers. There is a comment in the code that says "timeval is defined in winsock.h, which we don't want to include because it breaks lots of this code". I'm not sure if it breaks stuff in the header or just in the .cpp file. Thus, the fix might be just adding a ifndef around the timeval definition in DayTime.hpp like:
#ifndef timeval
struct timeval {
  long    tv_sec;         /* seconds */
  long    tv_usec;        /* and microseconds */
};
#endif
Of course this may break the code due to the comment but that is what I'm going to discuss and get back with you on.

-- RickMach - 04 Apr 2008

Well in doing a test with the current version of the compiler, putting an include of winsock/winsock2.h instead of defining it breaks lots of the GPSTk code. Did putting the ifndef work ok for you?

-- RickMach - 18 Apr 2008

Solution provided an no note that it didn't work. Closing.

-- RickMach - 14 Nov 2008

It appears that I am also getting a compile error saying that timeval is redefined. I believe that: "#ifndef timeval" statement should be: "#ifndef _WINSOCKAPI_".

-- JasonTobiasz - 03 Aug 2010

Changing status to Asked Questions so that this will be looked at again.

-- JasonTobiasz - 31 Aug 2010

After consulting our Windows folks, there appears to be no easy solution here, since we have not yet been able to build the TK with sockets on Windows. Is it possible for you to provide more information about the origin of the error so we may be able to suggest how DayTime might be modified?

-- SusanCummins - 18 Oct 2010

From Susan Cummins: On the max() issue, the recommended solution is to "use qualifiers in your code to remove the ambiguity, i.e. std::max() everywhere instead of just max(). This is purely a Windows issue." Not necessarily a quick fix, but should resolve the issue.

-- JasonTobiasz - 18 Oct 2010

For the min/max issue, we decided to just add NOMINMAX as a preprocessor definition to all of our projects so that the std min/max function templates are used, rather than the legacy min/max macros. We just didn’t want to have to add “std::” in a whole bunch of places. Seemed too risky.

-- JasonTobiasz - 18 Oct 2010

Whoops! I added comments to the wrong bug. Ack..and I didn't update. Such fail.

-- JasonTobiasz - 18 Oct 2010

Jason, some additional info on this from one of our folks with GPSTk on Windows expertise: "As is, this works only on Windows. It should be:

#if defined MSC_VER and not defined _WINSOCKAPI

Otherwise it looks promising as a solution to the timeval problem. I would recommend compiling on (many) other platforms to make sure it does not break anything. It compiles in Linux with gcc 4.4.3."

We will need to check out this potential solution further, on the other supported platforms, to be sure it's a robust one for the toolkit. If it works for your purposes, that's great. We can look into it further after the next stable release is done, to see if it can be incorporated permanently. Thanks!

-- SusanCummins - 19 Oct 2010

I commit a change on Revision2933 on this issue.

#if defined _MSC_VER
#ifndef _WINSOCKAPI_
// timeval is defined in winsock.h, which we don't want to include
// because it breaks lots of this code
#ifndef timeval
struct timeval {
   long    tv_sec;         /* seconds */
   long    tv_usec;        /* and microseconds */
};
#endif   // #ifndef timeval
#endif   // #ifndef _WINSOCKAPI_
#else
#include 
#endif

It does work on windows with including 'winsock.h'.

-- YanWei - 12 Nov 2011 No such template def TMPL:DEF{PROMPT:supportquery}

Topic revision: r11 - 12 Nov 2011, YanWei
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback