Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build re2c in windows? #210

Closed
chjhaijiang opened this issue Jul 4, 2018 · 15 comments

Comments

@chjhaijiang
Copy link

commented Jul 4, 2018

Do we have any specific request for GCC version to build Re2c on Windows?

Follow the steps:
6. Build for windows using mingw:
$ ../configure --host i686-w64-mingw32 [--prefix=]
$ make

I got below errors:
c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwchar:164:11: error: '::vfwscanf' has not been declared
using ::vfwscanf;
^~~~~~~~
c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwchar:170:11: error: '::vswscanf' has not been declared
using ::vswscanf;
^~~~~~~~
c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwchar:174:11: error: '::vwscanf' has not been declared
using ::vwscanf;
^~~~~~~
c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwchar:191:11: error: '::wcstof' has not been declared
using ::wcstof;
^~~~~~
In file included from c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\locale_facets.h:39:0,
from c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\basic_ios.h:37,
from c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\ios:44,
from c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\ostream:38,
from c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\iostream:39,
from ../src/code/go.h:4,
from ../src/code/bitmap.cc:5:
c:\hchen\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwctype:89:11: error: '::iswblank' has not been declared
using ::iswblank;
^~~~~~~~

@sergeyklay

This comment has been minimized.

Copy link
Contributor

commented Jul 4, 2018

This can be related to the compiler configuration issues. I'm not pretty sure but it's probably an issue related to the older MinGW compiler. Just for test try to use mingw-w64.

P.S. As you can see it's not platform specific issue sass/libsass#1894

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Jul 4, 2018

@chjhaijiang, are you able to build a minimal hello-world C++ program with you MinGW toolchain?

@chjhaijiang

This comment has been minimized.

Copy link
Author

commented Jul 5, 2018

@skvadrik, Yes. The simple hello-world example below can be run.

#include <iostream>
int main()
{
  std::cout<<"hello, world!"<<std::endl;  
  return 0;
}
@chjhaijiang

This comment has been minimized.

Copy link
Author

commented Jul 6, 2018

Alternatively, Do we have a 1.0.3 release binary for windows 64-bit to use?

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Jul 6, 2018

I've uploaded a windows binary built on linux (built with MinGW version 7.3.0): https://github.com/skvadrik/re2c/releases/download/1.0.3/re2c-1.0.3.exe.zip.

I'm also trying to build in a windows VM with MinGW to see if I can reproduce the failure, but so far I have problems setting up a working environment.

@chjhaijiang

This comment has been minimized.

Copy link
Author

commented Jul 9, 2018

@skvadrik, Build re2c.exe with cygwin64 seems worked for me.
But if I build with ../configure --host i686-w64-mingw32, then If I run re2c.exe, It pop up a error that libgcc_s_sjlj-1.dll is missed.

Is it because re2c is dynamic linked with other dlls? Do we have a static link configure option to be used with?
Thanks

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Jul 9, 2018

See https://stackoverflow.com/a/4703059/815525.
I think you get the error because 1) re2c.exe is dynamically linked with this libgcc_s_sjlj-1.dll, and 2) when you run re2c.exe, the dynamic linker cannot find this library. Item 1 can be fixed with -static-libgcc -static-libstdc++, and item 2 can be fixed by adding the path to the library to PATH environment variable. Fixing either 1 or 2 should fix the problem.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Jul 9, 2018

Note that you can add the options to CXXFLAGS as follows:

$ configure CXXFLAGS="-static-libgcc -static-libstdc++" --host i686-w64-mingw32

If you then run make V=1, you'll see that the options are passed to the C++ compiler. Finally, on Linux (and perhaps in Cygwin) you can see all the dynamic dependencies of your re2c.exe executable with ldd. For example, on my system I have the following, when running configure without options:

$ ldd re2c
        linux-vdso.so.1 (0x00007ffcacfb3000)
        libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/8.1.0/libstdc++.so.6 (0x00007fcf787f6000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fcf784a4000)
        libgcc_s.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/8.1.0/libgcc_s.so.1 (0x00007fcf7828c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fcf77eca000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fcf78e6b000

And if I configure with -static-libgcc -static-libstdc++, the dependency list shrinks to this:

$ ldd re2c
        linux-vdso.so.1 (0x00007ffdcf1de000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f251f4f4000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f251f132000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f251fc09000)
@chjhaijiang

This comment has been minimized.

Copy link
Author

commented Jul 9, 2018

@skvadrik, Thank you very much. I will get it confirmed and give another comment here.

@TomUdale

This comment has been minimized.

Copy link

commented Nov 27, 2018

Greetings, I was wondering if this had been resolved. I am seeing the exact same error messages as the original post while trying to compile re2c v 1.1.1 using brand new mingw (updated Nov 16, 2018) on Windows 7 64 bit.

I agree with @sergeyklay that is very much feels like a compiler configuration issue but I am way out of my depth with mingw/gcc. Any thoughts on what to try? I am happy to provide screenshots of my mingw configuration or whatever else might be helpful.

@chjhaijiang

This comment has been minimized.

Copy link
Author

commented Nov 27, 2018

Yes, this issue can be closed. I switched to use cygwin for building. It was working to me.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Nov 27, 2018

@TomUdale It seems to be a mingw issue (googling shows lots of similar errors in other projects). You can try reporting the bug upstream (former sf issue tracker https://sourceforge.net/p/mingw/bugs/ now points to osdn tracker https://osdn.net/projects/mingw/ticket/). Some suggest using -std=gnu++11 compiler flag as a workaround (RE2C use -std=c++98 by default).

@TomUdale

This comment has been minimized.

Copy link

commented Nov 28, 2018

@skvadrik I edited the config.ac file to change the -std setting to gnu++11 as you suggested (not sure if this is the "correct" way - I expect there is some switch to configure that is more appropriate) and it worked in my hands. I did get two integer conversion warnings in parser.cc - they do not look dramatic.

I ran the resulting re2c.exe (both in the build location and in another location) in the mingw environment and a regular cmd prompt and it told me "error no source file" which was true. So it appears that the linking is fine and if there is any dynamic linking going on, it is all handled correctly by default and regardless of path.

I will actually try it with a real input later and see how that goes.

Let me know if you want to see the output of the build warning or anything.

@chjhaijiang thanks for the information on cygwin. I was going there next if mingw failed me.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Nov 28, 2018

@TomUdale Good to know that it worked!

The usual way to override CXXFLAGS defined in configure.ac is to pass CXXFLAGS="-std=gnu++11" to configure.

You can validate the build by running RE2C test suite: make test, but that runs a bash script, so it won't work on windows unless you use cygwin or WSL.

@skvadrik

This comment has been minimized.

Copy link
Owner

commented Nov 28, 2018

@TomUdale About the warnings in parser.cc, they come from the code autogenerated by bison, and normally people don't see them because they don't set -Wconversion -Wsign-conversion compiler options. They are relativey harmless, but they can only be fixed in bison (and bison devs are busy doing more useful stuff).

@skvadrik skvadrik closed this Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.