Menu

#35 Building branch 1.0.0 in Windows with MSVC 14

open
Geoff
None
5
2018-03-01
2018-02-02
Geoff
No

A number of changes to build branch 1.0.0 in Windows, using MSVC14...

I thought I had made some of these changes in the win-build3 branch, but they do not seem to have been merged... or maybe merged to master after creating the 1.0.0 branch, or something... but have now done them again...

enum using reserved windows variable 'ERROR' in fg_log.hxx

This can be fixed changing the enum class log_prio to use another name like say ERROR2, as suggested in the win-build3 branch, or something else...

diff --git a/src/fglib/fg_log.hxx b/src/fglib/fg_log.hxx
index 3c650b0..f4362b0 100644
--- a/src/fglib/fg_log.hxx
+++ b/src/fglib/fg_log.hxx
@@ -48,7 +48,7 @@ enum class log_prio
    DEBUG,      ///< debug messages
    URGENT  = 64,   ///< log always, regardless of logging level
    CONSOLE = 128,  ///< log to terminal (too)

-   ERROR   = 192   ///< = URGENT | CONSOLE
+   ERROR2  = 192   ///< = URGENT | CONSOLE
 };

 /**

And then change each instance of log_prio::ERROR to log_prio::ERROR2, some 31 instances, in fgms.cxx...

Use of getopt function

A previous kludge was to provide such a funtion for a _MSC_VER build in main.cxx but that was a very minimal implmentation...

Could simply move that block out of main.cxx into fgms.cxx where it is used...

Or by adding a FindGetopt.cmake to CMakeLists.txt could find and link to an fuller external library... I have a wingetopt repo, but there is a question of the NetBSD licence being compatible with FG/fgms... but there are other instances if my kludge, only used for a MSVC build is not sufficient...

Feedback welcome...

constexpr double E2 and E4 and constexpr float SGMISC_PI failed!?

Had to change this to get it to compile... am sure there is a better change... need to check and search...

diff --git a/src/fglib/fg_geometry.cxx b/src/fglib/fg_geometry.cxx
index e2e668d..ee01ca2 100644
--- a/src/fglib/fg_geometry.cxx
+++ b/src/fglib/fg_geometry.cxx
@@ -363,15 +363,24 @@ namespace
 constexpr double SG_NM_TO_METER         { 1852.0000 };
 constexpr double SG_METER_TO_FEET       { 3.28083989501312335958 };
 constexpr double SQUASH                 { 0.9966471893352525192801545 };
-constexpr double E2                     { fabs ( 1 - SQUASH * SQUASH ) };
+#ifdef _MSC_VER
+#define E2                fabs ( 1.0 - SQUASH * SQUASH )
+#define E4               ( E2 * E2 )
+#else
+constexpr double E2                     { fabs((double)(1.0 - SQUASH * SQUASH)) };
 constexpr double E4                     { E2 * E2 };
+#endif
 constexpr double EQURAD                 { 6378137.0 };
 constexpr double RA2                    { 1 / (EQURAD * EQURAD) };
 constexpr double SG_180                 { 180.0 };
 constexpr double SG_PI                  { 3.1415926535 };
 constexpr double SG_RADIANS_TO_DEGREES  { SG_180 / SG_PI };
 constexpr double SG_DEGREES_TO_RADIANS  { SG_PI / SG_180 };
-constexpr float  SGMISC_PI      { 3.1415926535897932384626433832795029L };
+#ifdef _MSC_VER
+constexpr float  SGMISC_PI              { (float)3.1415926535897932384626433832795029 };
+#else
+constexpr float  SGMISC_PI              { 3.1415926535897932384626433832795029L };
+#endif
 } // namespace

 /**

Ideas very welcome....

fg_version.cxx includes a unix only arpa/inet.h...

Adding #include <winsock2.h> under an #ifdef WIN32 seems to fix this...

But could also include the special config.h generated by cmake, since this also includes winsock2.h...

diff --git a/src/fglib/fg_version.cxx b/src/fglib/fg_version.cxx
index 6b8da71..90c85a1 100644
--- a/src/fglib/fg_version.cxx
+++ b/src/fglib/fg_version.cxx
@@ -20,7 +20,11 @@
 // Copyright (C) 2017  Oliver Schroeder
 //

+#ifdef WIN32
+#include <WinSock2.h>
+#else
 #include <arpa/inet.h>
+#endif
 #include "fg_version.hxx"
 #include "fg_util.hxx"

With these 4 changes, the source built, but while I was doing this there have been some other changes, ...

Maybe I should hold off on doing this until we have a settled 1.0.0 branch to work on... or part or all the above patches are applied... thanks...

Discussion

  • Oliver Schroeder

    • Group: considered --> Planned_for_next_release
     
  • Oliver Schroeder

    I will look into this, but currently working on libcli

     
  • Geoff

    Geoff - 2018-03-01

    Hi Oliver,

    Concerning branch 1.0.0, and a MSVC 14 build...

    Thanks for all the changes... mainly everything was
    good, but still ran into a few more...

    The MS compiler reads all decimal as a double,
    unless an 'F' or 'f' is appended... so this
    was my first change -

    -constexpr float SGMISC_PI { 3.1415926535 };
    +constexpr float SGMISC_PI { 3.1415926535f };

    Normally this is a 'warning' which can be suppressed,
    but with constexpr this becomes an error...

    There remains several other warnings of this type,
    which I have not fixed at this time, like the
    group in fgms.cxx, the first being -

    X:\fgms-src\src\fgms\fgms.cxx(2471): warning C4305: '=': truncation from 'double' to 'float'

    As indicated this warning 4305 could be suppressed in
    CMakeLists.txt, like we already suppress 4146 and 4267,
    or removed with either a (float) cast, or adding 'f',
    but here only concentrated on errors...

    The next problem was the use of 'read' and 'write'
    in the re-write of cli_client, so have to add

     #ifndef _MSC_VER
             #include <termios.h>
    +#else
    +#include <io.h> // for read, write, ...
     #endif
    

    Next 'getopt' is used in fgms.cxx... thanks for moving
    this into msc_getopt.hxx/cxx, so in CMakeLists.txt
    added this directory, under if (MSVC) -

    • include_directories( src/libmsc )

    I noted in netsocket.cxx and fg_tracker.cxx you have added
    #include <libmsc/msc_unistd.hxx>...

    These could now be reduced to a simple -
    #include "msc_unistd.hxx", but not important...

    Then added 'msc_getopt.hxx' to the special MSVC
    'config.h.msvc' -> 'config.h'...

    And at the same time also added -
    #include <algorithm> // for std::min, std::max, ...

     #include <time.h>
    +#include <algorithm> // for std::min, std::max, ...
    
    +#include "msc_getopt.hxx" // for getopt, ...
     #ifndef VERSION
    

    And of course, 'getopt' has to also publically
    expose 'optarg' -

    msc_getopt.cxx
    -static char* optarg;
    +char *optarg;
    
    msc_getopt.hxx
    -int getopt ( int argc, char* argv[], char* args );
    +extern int getopt ( int argc, char* argv[], char* args );
    +extern char *optarg;
    

    That was it... and it built fine... the full diff is
    given below -

    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index 72b534c..c63df59 100755
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -271,6 +271,7 @@ if ( MSVC )
                     src/libmsc/msc_getopt.cxx
                     src/libmsc/msc_getopt.hxx
             )
    
    +        include_directories( src/libmsc )
             list ( APPEND add_LIBS libmsc )
     endif ( MSVC )
    
    diff --git a/config.h.msvc b/config.h.msvc
    index ba9e1f0..c704f8a 100644
    --- a/config.h.msvc
    +++ b/config.h.msvc
    @@ -18,7 +18,9 @@
     #include <winsock2.h>   // NOTE: This includes Windows.h
     #include <ws2tcpip.h>
     #include <time.h>
    +#include <algorithm> // for std::min, std::max, ...
    
    +#include "msc_getopt.hxx" // for getopt, ...
     #ifndef VERSION
     #define VERSION "0.10.23-WIN32" // UPD20121026 - Should agree with AGE etc in CMakeLists.txt
     #endif
    diff --git a/src/fglib/fg_geometry.cxx b/src/fglib/fg_geometry.cxx
    index 33fe664..a065930 100644
    --- a/src/fglib/fg_geometry.cxx
    +++ b/src/fglib/fg_geometry.cxx
    @@ -377,7 +377,7 @@ constexpr double SG_180                 { 180.0 };
     constexpr double SG_PI                  { 3.1415926535 };
     constexpr double SG_RADIANS_TO_DEGREES  { SG_180 / SG_PI };
     constexpr double SG_DEGREES_TO_RADIANS  { SG_PI / SG_180 };
    -constexpr float  SGMISC_PI              { 3.1415926535 };
    +constexpr float  SGMISC_PI              { 3.1415926535f };
      //{ 3.1415926535897932384626433832795029L };
     } // namespace
    
    diff --git a/src/libcli/cli_client.hxx b/src/libcli/cli_client.hxx
    index a42c05a..9e098f4 100644
    --- a/src/libcli/cli_client.hxx
    +++ b/src/libcli/cli_client.hxx
    @@ -25,6 +25,8 @@
     #include <unistd.h>
     #ifndef _MSC_VER
             #include <termios.h>
    +#else
    +#include <io.h> // for read, write, ...
     #endif
     #include "common.hxx"
     #include "filter.hxx"
    diff --git a/src/libmsc/msc_getopt.cxx b/src/libmsc/msc_getopt.cxx
    index 88d819c..654e236 100644
    --- a/src/libmsc/msc_getopt.cxx
    +++ b/src/libmsc/msc_getopt.cxx
    @@ -26,7 +26,7 @@
     #include "msc_getopt.hxx"
    
     // kludge for getopt() for WIN32
    -static char* optarg;
    +char *optarg;
     static int curr_arg = 0;
     int getopt ( int argc, char* argv[], char* args )
     {
    diff --git a/src/libmsc/msc_getopt.hxx b/src/libmsc/msc_getopt.hxx
    index fc99fe4..ec71edf 100644
    --- a/src/libmsc/msc_getopt.hxx
    +++ b/src/libmsc/msc_getopt.hxx
    @@ -8,7 +8,8 @@
    
     #ifdef _MSC_VER
    
    -int getopt ( int argc, char* argv[], char* args );
    +extern int getopt ( int argc, char* argv[], char* args );
    +extern char *optarg;
    
     #endif // _MSC_VER
     #endif // #ifndef _msc_getopt_header
    

    Have not yet had a chance to test fgms, but will
    get to that...

    After testing and if you agree with all these I could push them
    directly to the 1.0.0 branch... if you do not get around
    to adding them, if you get the chance...

    What do you think?

    Regards,
    Geoff.

    PS: I am still having troubles with sourceforge at the
    moment... tried to post this yesterday, but sf failed!
    Hope this clears up soon...

     

Log in to post a comment.

MongoDB Logo MongoDB