sdcv icon indicating copy to clipboard operation
sdcv copied to clipboard

port sdcv to windows

Open Dushistov opened this issue 8 years ago • 19 comments

It would be nice to have MS Windows port of SDCV (command line stardict, capable of running as "filter", e.g. sdcv.exe "apple" > output.txt), or maybe DLL (with simple interface) will be enought for including StarDict in other projects.

Dushistov avatar Jun 02 '16 22:06 Dushistov

I have sdcv working on Windows. Also added some patches to deal with some features of stardict 3.0.0 dictionaries. Originally, my Windows patches worked with the code pretty much as is. However, I'm not using glib/gtk+ on most of my operating systems any more, so I ended up removing the glib dependencies in sdcv. It's easier to include the code with other GUI libraries like Qt or FLTK without the glib dependencies.

Command line support for internationalization on Windows is pretty rough. For internationalized input/output, one can redirect from files and use a text editor with UTF-8 support. Was also thinking about possibly using a hypertext application on Windows as an interface. I've been looking into better UTF-8 support for SDL and PDCurses. It shouldn't be too hard to create a PDCurses front end with some UTF-8 character support.

I also ran across a Windows port of dictzip and that works well with dictionaries used by sdcv. Plus, I'm using some of the stardict-tools to convert tab or Babylon format into dictionaries. I have a small dictionary I created using the Moby project and those tools. I use the dictionary with sdcv and it works fine.

lm8 avatar Jun 13 '16 12:06 lm8

Maybe port to MSYS2?

ShuguangSun avatar Oct 06 '16 08:10 ShuguangSun

On Thu, October 6, 2016 1:27 am, ShuguangSun wrote:

Maybe port to MSYS2?

Why would you want to port to msys2? If you build with the msys DLLs, you'll end up having to worry about meeting the msys license restrictions as well as adding more libraries to the build process. Besides, sdcv already runs in msys2 as is. There's a project that fixes console apps so they work properly with msys and msys2. (There's a link to the project and more information on console applications working with terminal emulators at http://lmemsm.livejournal.com/13111.html ) I believe cygwin already has a sdcv port so that code should work with no or minimal patching if built with msys2 or msys DLLs instead of cygwin DLLs. Also, if you really want a Linux-like build environment on Windows, check out the midipix project not the cygwin derived msys2 and msys projects.

lm8 avatar Oct 30 '16 17:10 lm8

Understand. Thanks.

ShuguangSun avatar Oct 31 '16 02:10 ShuguangSun

https://opensourcepack.blogspot.com/2013/04/stardict-console-native-version.html?showComment=1574134353730#c59939695882788654

VimWei avatar Nov 19 '19 03:11 VimWei

Still have my executable of sdcv plus some dictionary tools. I use it on my own computer. If anyone's interested, I can upload and make them available somewhere along with the patches I used to get them to build and to access some later stardict dictionary formats.

lm8 avatar Nov 30 '19 15:11 lm8

Still have my executable of sdcv plus some dictionary tools. I use it on my own computer. If anyone's interested, I can upload and make them available somewhere along with the patches I used to get them to build and to access some later stardict dictionary formats.

That's great, I'm interested!

VimWei avatar Nov 30 '19 15:11 VimWei

Actually with a simple path one can compile sdcv in Msys2's Mingw64 environment, from this blog

It works in my compile test.

Strip dowm procedure:

  1. Install dependency and clone repo:
pacman -S mingw-w64-x86_64-zlib mingw-w64-x86_64-readline mingw-w64-x86_64-cmake
git clone https://github.com/Dushistov/sdcv.git
  1. Then apply this small patch:
$ git diff
diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp
index a911ddd..427e062 100644
--- a/src/stardict_lib.cpp
+++ b/src/stardict_lib.cpp
@@ -564,7 +564,7 @@ bool OffsetIndex::load_cache(const std::string &url)
     const std::list<std::string> vars = get_cache_variant(url);

     for (const std::string &item : vars) {
-        struct ::stat idxstat, cachestat;
+        struct ::stat64 idxstat, cachestat;
         if (g_stat(url.c_str(), &idxstat) != 0 || g_stat(item.c_str(), &cachestat) != 0)
             continue;
         if (cachestat.st_mtime < idxstat.st_mtime)
diff --git a/src/utils.cpp b/src/utils.cpp
index 33bfeaa..a5f1e21 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -25,11 +25,11 @@
 #include <algorithm>
 #include <cstdio>
 #include <cstdlib>
-#include <glib.h>
-#include <glib/gi18n.h>
 #include <iomanip>
 #include <sstream>

+#include <glib.h>
+#include <glib/gi18n.h>
 #include "utils.hpp"

 std::string utf8_to_locale_ign_err(const std::string &utf8_str)
  1. run cmake and make
cd sdcv
cmake ./ -G "MSYS Makefiles"
make VERBOSE=1
  1. copy the compiled sdcv to <your_msys2_install_path>/mingw64/bin/

I might miss some dependencies, in case you do, run pacman -S zlib-devel libreadline-devel glib2-devel Also, is it possiable to merge this patch?

ghost avatar Mar 26 '21 10:03 ghost

@pRot0ta1p which version of sdcv do you use? I cant compile because the following error

# make verbose=1
[ 12%] Building CXX object CMakeFiles/sdcv.dir/src/sdcv.cpp.obj
In file included from D:/msys64/usr/lib/glib-2.0/include/glibconfig.h:9,
                 from D:/msys64/usr/include/glib-2.0/glib/gtypes.h:32,
                 from D:/msys64/usr/include/glib-2.0/glib/galloca.h:32,
                 from D:/msys64/usr/include/glib-2.0/glib.h:30,
                 from D:/msys64/home/hh/sdcv/src/sdcv.cpp:36:
D:/msys64/usr/include/glib-2.0/glib/gtypes.h: In function 'gboolean _GLIB_CHECKED_ADD_U64(guint64*, guint64, guint64)':
D:/msys64/usr/include/glib-2.0/glib/gtypes.h:463:47: error: static assertion failed: Expression evaluates to false
  463 |   G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
D:/msys64/usr/include/glib-2.0/glib/gmacros.h:762:46: note: in definition of macro 'G_STATIC_ASSERT'
  762 | #define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false")
      |                                              ^~~~
make[2]: *** [CMakeFiles/sdcv.dir/build.make:76: CMakeFiles/sdcv.dir/src/sdcv.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/sdcv.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

lld2001 avatar Jun 11 '21 07:06 lld2001

@lld2001 The latest commit 3963e358cd8f6e24e59916ead97bc47a1d932c8d , you also have to use the MINGW64 shell and use the mingw64 version of cmake and gcc if you use the patch I posted.

ghost avatar Jun 11 '21 07:06 ghost

use the MINGW64 shell and use the mingw64 version of cmake and gcc

Thank you for your tip. I can successfuly buld sdcv. But when I query a word nothing displayed. image

I've built sdcv on Cygwin and used it normally by the same dictionary.

lld2001 avatar Jun 11 '21 08:06 lld2001

@lld2001 sdcv seems demand a UTF8 environment to work well... try some like this:

env LANG="zh_CN.UTF-8" sdcv.exe  -n <word to query> -0 -1 --data-dir=<dictionary folder> --use-dict=<dictionary name>

Also try set the language env to UTF8 in mintty too.

ghost avatar Jun 11 '21 08:06 ghost

Thank you for your patience. I set all as your tip and built again. But that does not work. My os is win7 and the default coding is not utf-8.

image

lld2001 avatar Jun 11 '21 09:06 lld2001

I dont know if it depend on coding system when make. The cmake output:

# cmake  ~/sdcv  -G "MSYS Makefiles"
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CXX_SUPPORTS_CXX11
-- Performing Test CXX_SUPPORTS_CXX11 - Success
-- Found ZLIB: D:/msys64/mingw64/lib/libz.dll.a (found version "1.2.11")
-- Found PkgConfig: D:/msys64/mingw64/bin/pkg-config.exe (found version "1.7.4")
-- Checking for one of the modules 'glib-2.0'
-- Found GLib2: glib-2.0;intl D:/msys64/mingw64/include/glib-2.0;D:/msys64/mingw64/lib/glib-2.0/include;D:/msys64/mingw64/include
-- Looking for include file glib/gregex.h
-- Looking for include file glib/gregex.h - not found
-- REQUIRED_VARS
-- Looking for mmap
-- Looking for mmap - not found
-- Looking for locale.h
-- Looking for locale.h - found
-- Configuring done
-- Generating done
-- Build files have been written to: D:/msys64/tmp/build-sdcv

lld2001 avatar Jun 11 '21 09:06 lld2001

@lld2001 I don't think coding system make a difference when compiling it ... Try pass the "-0 -1" flags to sdcv when using it. Those two flags force sdcv use utf8 strings, which should avoid those messy output... Run sdcv --help for details.

For example, to query the word "apple":

1

ghost avatar Jun 11 '21 09:06 ghost

Still failed. Nothing displayed. What's your OS's coding?

image

lld2001 avatar Jun 11 '21 09:06 lld2001

@lld2001 I run chcp in windows cmd returns Active code page: 936, which should be GBK coding.

I'm out of ideas :rofl: . I suspect some of your dictionary files are problematic, may be try rename the folders' and files' names to pure ascii strings?

ghost avatar Jun 11 '21 10:06 ghost

Thank you. I finally solve this by built using MSYS2 MSYS.

Everything is OK except this sdcv still can't work in Windows cmd.exe.

lld2001 avatar Jun 11 '21 11:06 lld2001

@lld2001 The MSYS environment can't produce native windows excutable, but you can (sort of) invoke msys's bash in window cmd or use a bat file.

ghost avatar Jun 12 '21 03:06 ghost