Compiling error on windows

Get help for specific problems
Posts: 3
Joined: 17 Jun 2022

whio

Hi, I am trying to compile FreeFileSync under MSYS2 MinGW x64 environment for Windows.

I have compiled some libraries: curl-7.83.1, libssh2-1.10.0, wxWidgets-3.1.7.

Firstly, i ran into a problem "../../zen/guid.h:24:2: error: #error Where is Glibc?"

I try to fix this by skip glibc check as the following:

remove:
#ifndef __GLIBC_PREREQ
#error Where is Glibc?
#endif

#if __GLIBC_PREREQ(2, 25) //getentropy() requires Glibc 2.25 (ldd --version) PS: CentOS 7 is on 2.17
add:
#if 0
Secondly, i ran into this problem "../../zen/time.h:144:11: error: '::localtime_r' has not been declared; did you mean 'localtime_s'?"

Any one could help ?

--------
PS: I am currently using mingw-w64-x86_64-gcc 12.1.0-2 as compiler.
Posts: 3
Joined: 17 Jun 2022

whio

I tried some modifications. Something still went wrong.
../../zen/guid.h:58:59: error: 'O_CLOEXEC' was not declared in this scope
   58 |         const int fd_ = ::open("/dev/urandom", O_RDONLY | O_CLOEXEC);

What i did is posted below. The modifications are done by the guidance in Bug.txt shipped with FFS source.

==== Pre install msys2
Install msys2. The following commands are used under mingw64 env:

pacman -Syu
pacman -S make mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-gtk2
pacman -S base-devel



==== compile and install libssh2 1.10.0
1. CHANGE to libssh2 -> /src/session.c

DELETE:
if(session->state & LIBSSH2_STATE_NEWKEYS) { //<<<< line 893

ADD:
if(1) { //<<<< line 893

DELETE to libssh2 -> /src/sftp.h

/* //<<<< line 42
* MAX_SFTP_OUTGOING_SIZE MUST not be larger than 32500 or so. This is the
* amount of data sent in each FXP_WRITE packet
*/
#define MAX_SFTP_OUTGOING_SIZE 30000

/* MAX_SFTP_READ_SIZE is how much data is asked for at max in each FXP_READ
* packets.
*/
#define MAX_SFTP_READ_SIZE 30000 // <<<< line 51



2. ADD to libssh2 -> /include/libssh2_sftp.h

ADD:
#endif // <<<< line 49

/*
* MAX_SFTP_OUTGOING_SIZE MUST not be larger than 32500 or so. This is the
* amount of data sent in each FXP_WRITE packet
*/
#define MAX_SFTP_OUTGOING_SIZE 30000

/* MAX_SFTP_READ_SIZE is how much data is asked for at max in each FXP_READ
* packets.
*/
#define MAX_SFTP_READ_SIZE 30000

/* Note: Version 6 was documented at the time of writing // <<<< line 62



3. CHANGE to libssh2 -> /src/userauth.c

DELETE:
if(methods_len >= session->userauth_list_data_len - 5) { // <<<< LINE 156

ADD:
if(methods_len > session->userauth_list_data_len - 5) { // <<<< LINE 156

DELETE:
LIBSSH2_ALLOC(session, session->userauth_list_data_len); // <<<< LINE 82
ADD:
LIBSSH2_ALLOC(session, session->userauth_list_data_len + 1); // <<<< LINE 82

DELETE:
memmove(session->userauth_list_data, session->userauth_list_data + 5, // <<<< line 163
ADD:
memcpy(session->userauth_list_data, session->userauth_list_data + 5, // <<<< line 163



4. RUN the followings to compile and install : PS: you may close anti-virus and editor for performance

cd [path to libssh2]
mkdir build && cd build
../configure
make -j8
make install



==== compile and install curl 7.38.1
1. ADD TO curl -> /lib/ftp.c :

} //<<<< line 1814

static bool is_routable_ip_v4(unsigned int ip[4])
{
if (ip[0] == 127 || //127.0.0.0/8 (localhost)
ip[0] == 10 || //10.0.0.0/8 (private)
(ip[0] == 192 && ip[1] == 168) || //192.168.0.0/16 (private)
(ip[0] == 169 && ip[1] == 254) || //169.254.0.0/16 (link-local)
(ip[0] == 172 && ip[1] / 16 == 1)) //172.16.0.0/12 (private)
return false;
return true;
}

static char *control_address(struct connectdata *conn) //<<<< line 1827


2. CHANGE to curl -> /lib/ftp.c :

DELETE:
if (data->set.ftp_skip_ip) //<<<< line 1928

ADD:

/* we got OK from server */ //<<<< line 1927
bool skipIp = data->set.ftp_skip_ip;
if (!skipIp && !is_routable_ip_v4(ip))
{
unsigned int ip_ctrl[4];
if (4 != sscanf(control_address(conn), "%u.%u.%u.%u",
&ip_ctrl[0], &ip_ctrl[1], &ip_ctrl[2], &ip_ctrl[3]) ||
is_routable_ip_v4(ip_ctrl))
skipIp = true;
}

if (skipIp) {
/* told to ignore the remotely given IP but instead use the host we used //<<<< line 1939


3. CHANGE to curl -> /lib/ftp.c :

DELETE:
result = ftp_nb_type(data, conn, TRUE, FTP_LIST_TYPE); //<<<< line 3704

ADD:
result = ftp_nb_type(data, conn, data->state.prefer_ascii, FTP_LIST_TYPE); //<<<< line 3704

4. RESTART mingw x64


5. RUN the followings to compile and install : PS: you may close anti-virus and editor for performance

cd [path to curl]
mkdir build && cd build
../configure --with-openssl --with-libssh2
make -j8
make install



==== compile and install wxWidgets 3.1.7
1. ADD to wxWidgets -> /include/wx/features.h

ADD:
#define _WX_FEATURES_H_ // <<<< LINE 15

#if defined(__WXGTK20__)
#define wxHAS_DPI_INDEPENDENT_PIXELS
#endif

/* radio menu items are currently not implemented in wxMotif, use this // <<<< LINE 21

2. CHANGE to wxWidgets -> /src/aui/framemanager.cpp

DELETE:
// determine the dock's minimum size // <<<< LINE 2242
bool plus_border = false;
bool plus_caption = false;
int dock_min_size = 0;
for (j = 0; j < dock_pane_count; ++j)
{
wxAuiPaneInfo& pane = *dock.panes.Item(j);
if (pane.min_size != wxDefaultSize)
{
if (pane.HasBorder())
plus_border = true;
if (pane.HasCaption())
plus_caption = true;
if (dock.IsHorizontal())
{
if (pane.min_size.y > dock_min_size)
dock_min_size = pane.min_size.y;
}
else
{
if (pane.min_size.x > dock_min_size)
dock_min_size = pane.min_size.x;
}
}
}

if (plus_border)
dock_min_size += (pane_borderSize*2);
if (plus_caption && dock.IsHorizontal())
dock_min_size += (caption_size);

dock.min_size = dock_min_size; // <<<< LINE 2273

ADD:
// determine the dock's minimum size // <<<< LINE 2242
int dock_min_size = 0;
for (j = 0; j < dock_pane_count; ++j)
{
wxAuiPaneInfo& pane = *dock.panes.Item(j);
if (pane.min_size != wxDefaultSize)
{
int paneSize = dock.IsHorizontal() ? pane.min_size.y : pane.min_size.x;
if (pane.HasBorder())
paneSize += 2 * pane_borderSize;
if (pane.HasCaption() && dock.IsHorizontal())
paneSize += caption_size;

if (paneSize > dock_min_size)
dock_min_size = paneSize;
}
}

dock.min_size = dock_min_size; // <<<< LINE 2260



3. CHANGE to wxWidgets -> /src/gtk/menu.cpp

DELETE:
g_signal_connect(m_menu, "map", G_CALLBACK(menu_map), this); // <<<< LINE 900

ADD:
g_signal_connect(m_menu, "show", G_CALLBACK(menu_map), this); // <<<< LINE 900

4. DELETE to wxWidgets -> /src/gtk/window.cpp

DELETE:
static bool isSourceAttached; // <<<< LINE 3777
if (!isSourceAttached)
{
// attach GSource to detect new GDK events
isSourceAttached = true;
static GSourceFuncs funcs = {
source_prepare, source_check, source_dispatch,
NULL, NULL, NULL
};
GSource* source = g_source_new(&funcs, sizeof(GSource));
// priority slightly higher than GDK_PRIORITY_EVENTS
g_source_set_priority(source, GDK_PRIORITY_EVENTS - 1);
g_source_attach(source, NULL);
g_source_unref(source);
} // <<<< LINE 3791


5. RUN the followings to compile and install : PS: you may close anti-virus and editor for performance

pacman -S --needed make
pacman -S --needed ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo
pacman -S --needed ${MINGW_PACKAGE_PREFIX}-libpng
pacman -S --needed ${MINGW_PACKAGE_PREFIX}-libtiff
pacman -S --needed ${MINGW_PACKAGE_PREFIX}-gcc
pacman -S --needed ${MINGW_PACKAGE_PREFIX}-pkg-config
pacman -S --needed ${MINGW_PACKAGE_PREFIX}-gtk2

cd [path to wxWidgets]
mkdir build-1 && cd build-1
# [not this] ../configure --with-gtk=2 --disable-shared --disable-precomp-headers
../configure --with-msw --disable-shared --disable-precomp-headers
make -j8
make install

==== compile FreeFileSync

1. CHANGE to wx+/dc.h

DELETE:
#ifndef wxHAS_DPI_INDEPENDENT_PIXELS // <<<< line 59
#error why is wxHAS_DPI_INDEPENDENT_PIXELS not defined?
#endif // <<<< line 97

ADD:
// #ifndef wxHAS_DPI_INDEPENDENT_PIXELS // <<<< line 59
// #error why is wxHAS_DPI_INDEPENDENT_PIXELS not defined?
// #endif // <<<< line 97

2. CHANGE to zen/guid.h

DELETE:
#ifndef __GLIBC_PREREQ // <<<< line 23
#error Where is Glibc?
#endif

#if __GLIBC_PREREQ(2, 25) //getentropy() requires Glibc 2.25 (ldd --version) PS: CentOS 7 is on 2.17 // << line 27

ADD:
//#ifndef __GLIBC_PREREQ // <<<< line 23
//#error Where is Glibc?
//#endif

#if 0 //getentropy() requires Glibc 2.25 (ldd --version) PS: CentOS 7 is on 2.17 // << line 27


3. CHANGE to zen/time.h

DELETE:
if (::localtime_r(&utc, &ctc) == nullptr) // <<<< LINE 144

ADD:
if (::localtime(&utc) == nullptr) // <<<< LINE 144

DELETE:
if (::gmtime_r(&utc, &ctc) == nullptr) //Linux, macOS: apparently NO limits (tested years 0 to 10.000!) // <<<< line 162

ADD:
if (::gmtime(&utc) == nullptr) //Linux, macOS: apparently NO limits (tested years 0 to 10.000!) // << line 162


DELETE:
time_t utc = ::timegm(&ctc); // <<<< line 190

ADD:
time_t utc = ::mktime(&ctc); // <<<< line 190