build smbclient for windows

Binary download

Working-in-progress

Guide

This guide is for building smbclient and smbd (https://github.com/samba-team/samba) for windows.

Install dependencies

Use cygwin64 (usually better) or cygwin32. Install latest version of the following mandatory package: gcc-g++, bash, flex, libintl-devel, libgnutls-devel, perl, python3, python3-devel, zlib-devel, liblmdb-devel, rpcsvc-proto, m4 and the following optional package: libjansson-devel, libarchive-devel, openldap-devel, libicu-devel.

Then run pip3 install dnspython markdown

Then install perl-parse-yapp manually. You should manually copy these file into correct directory in your cygwin shell. You may download the following file here or get the latest version from archlinux pacman -S perl-parse-yapp.

perl-parse-yapp /usr/bin/vendor_perl/yapp => /usr/bin/yapp
perl-parse-yapp /usr/lib/perl5/5.32/vendor_perl/auto/Parse/Yapp/
perl-parse-yapp /usr/share/perl5/vendor_perl/ => You may have to move to /usr/share/perl5/5.32/vendor_perl/
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp.pm
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/Driver.pm
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/Grammar.pm
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/Lalr.pm
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/Options.pm
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/Output.pm
perl-parse-yapp /usr/share/perl5/vendor_perl/Parse/Yapp/Parse.pm

Please run echo 'use Parse::Yapp::Driver;' | perl, and make sure it works. Then run yapp, also make sure it works.

Build

Then download the samba git repository, run ./configure --without-gpgme --without-pam. Please add corresponding argument if you skipped any optional package in previous step:

Missing Package Extra Command Line
libjansson-devel --without-json
libarchive-devel –without-libarchive
openldap-devel –without-ldap

If configure is success, continue.

Fix

Run the following command to patch ld:

cd /usr/x86_64-pc-cygwin/bin
mv ld ld.real

echo '#!/bin/bash
_result=()
for ele in "$@"; do
    [[ "$ele" = "--export-dynamic" ]] && _result+=("--export-all-symbols") || _result+=("$ele")
done
/usr/bin/ld.real "${_result[@]}"
exit $?
' > ld

chmod +x ld

And apply this git-patch to your repository:

diff --git a/source3/lib/cluster_support.c b/source3/lib/cluster_support.c
index c11b1f76dbb..007e76f0953 100644
--- a/source3/lib/cluster_support.c
+++ b/source3/lib/cluster_support.c
@@ -59,7 +59,7 @@ const char *lp_ctdbd_socket(void)
 {
        const char *ret;

-       ret = lp__ctdbd_socket();
+       ret = NULL; /* lp__ctdbd_socket(); */
        if (ret != NULL && strlen(ret) > 0) {
                return ret;
        }
diff --git a/third_party/popt/poptconfig.c b/third_party/popt/poptconfig.c
index f0a92e01bd5..d9fa848a786 100644
--- a/third_party/popt/poptconfig.c
+++ b/third_party/popt/poptconfig.c
@@ -42,7 +42,7 @@ extern int glob_pattern_p (const char *__pattern, int __quote)
 /*@=declundef =exportheader =incondefs =protoparammatch =redecl =type @*/
 #endif /* __LCLINT__ */

-#if !defined(__GLIBC__)
+#if 0
 /* Return nonzero if PATTERN contains any metacharacters.
    Metacharacters can be quoted with backslashes if QUOTE is nonzero.  */
 static int

Build

OK. Now run make bin/smbclient -j8 and you're all set.