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

Build error on windows #1

Closed
petrushy opened this Issue Mar 17, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@petrushy

petrushy commented Mar 17, 2017

Hi,

Tried to compile this version of jcc but get a error:

jcc/sources/jcc.cpp(197): warning C4244: 'initializing': conversion from 'Py_hash_t' to 'long', possible loss of data
jcc/sources/jcc.cpp(199): error C2131: expression did not evaluate to a constant
jcc/sources/jcc.cpp(199): note: failure was caused by non-constant arguments or reference to a non-constant symbol
jcc/sources/jcc.cpp(199): note: see usage of 'hexdig'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe' failed with exit status 2

the section is:

static PyObject *t_jccenv_strhash(PyObject *self, PyObject *arg)
{
    long hash = PyObject_Hash(arg);
    size_t hexdig = sizeof(long) * 2;
    char buffer[hexdig + 1];                            # Line 199

    sprintf(buffer, "%0*lx", (int)hexdig, (unsigned long)hash);
    return PyUnicode_FromStringAndSize(buffer, hexdig);
}

I'm on windows, anaconda and MSVS v14 (Python 3.6)

I'm not so familiar with C++ but found these references:
http://stackoverflow.com/questions/33625180/strange-error-c2131-expression-did-not-evaluate-to-a-constant-in-vc-2015/33625383

Somehow the compiler don't get that it is a static value i think..

@rudimeier

This comment has been minimized.

Show comment
Hide comment
@rudimeier

rudimeier Mar 17, 2017

Owner

Hm this about Visual studio does not support VLAs (variable length array), see
http://stackoverflow.com/questions/20010716/gnu-compilers-vs-visual-studio-on-arrays-allocated-w-length-constant-w-in-a-sc

But actually we don't need VLA there. The compiler should know the size already. Could you try whether either this would work for you:

const size_t hexdig = sizeof(long) * 2;
char buffer[hexdig + 1];

or this

size_t hexdig = sizeof(long) * 2;
char buffer[sizeof(long) * 2 + 1];

Or the most stupid workaround like this

size_t hexdig = sizeof(long) * 2;
char buffer[17];
Owner

rudimeier commented Mar 17, 2017

Hm this about Visual studio does not support VLAs (variable length array), see
http://stackoverflow.com/questions/20010716/gnu-compilers-vs-visual-studio-on-arrays-allocated-w-length-constant-w-in-a-sc

But actually we don't need VLA there. The compiler should know the size already. Could you try whether either this would work for you:

const size_t hexdig = sizeof(long) * 2;
char buffer[hexdig + 1];

or this

size_t hexdig = sizeof(long) * 2;
char buffer[sizeof(long) * 2 + 1];

Or the most stupid workaround like this

size_t hexdig = sizeof(long) * 2;
char buffer[17];

rudimeier added a commit that referenced this issue Mar 17, 2017

fix: issue #1, Visual Studio does not support VLAs
see #1

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>

rudimeier added a commit that referenced this issue Mar 17, 2017

fix: Visual Studio does not support VLAs (issue #1)
Stupid compileri, hopefully it's happy with "static int".

BTW we fix a warning: PyObject_Hash returns Py_hash_t nowadays.

see #1

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>

rudimeier added a commit that referenced this issue Mar 17, 2017

fix: Visual Studio does not support VLAs (issue #1)
Stupid compiler, hopefully it's happy with "static int".

BTW we fix a warning: PyObject_Hash returns Py_hash_t nowadays
since (python 3.2).

see #1

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
@petrushy

This comment has been minimized.

Show comment
Hide comment
@petrushy

petrushy Mar 20, 2017

Hi!
Thanks for the update - the fix above in fix-issue-1 branch seems to work,the compiler does not complain on that anymore.

However i do get a linker error
"LINK : fatal error LNK1561: entry point must be defined" but I guess that is not related to this bug.

Many thanks

petrushy commented Mar 20, 2017

Hi!
Thanks for the update - the fix above in fix-issue-1 branch seems to work,the compiler does not complain on that anymore.

However i do get a linker error
"LINK : fatal error LNK1561: entry point must be defined" but I guess that is not related to this bug.

Many thanks

@petrushy petrushy closed this Mar 20, 2017

@rudimeier

This comment has been minimized.

Show comment
Hide comment
@rudimeier

rudimeier Mar 20, 2017

Owner

Regarding the other linker error. Maybe the patch below could help. This is what @tommykoch was doing in his other port. Maybe the /DLL option causes MSVC to link a library which does not need a main() function (entry point).

commit 8505d20fbcd471c5cff669ec85b84c4fbb1a6138
Author: Ruediger Meier ruediger.meier@ga-group.nl
Date: Fri Mar 10 13:32:56 2017 +0100

from tom add win32 library path: /DLL (untested)
diff --git a/setup.py b/setup.py
index f047038..6824e44 100644
--- a/setup.py
+++ b/setup.py
@@ -147,7 +147,7 @@ LFLAGS = {
     'sunos5': ['-L%(sunos5)s/jre/lib/i386' %(JDK), '-ljava',
                '-L%(sunos5)s/jre/lib/i386/client' %(JDK), '-ljvm',
                '-R%(sunos5)s/jre/lib/i386:%(sunos5)s/jre/lib/i386/client' %(JDK)],
-    'win32': ['/LIBPATH:%(win32)s/lib' %(JDK), 'Ws2_32.lib', 'jvm.lib'],
+    'win32': ['/DLL', '/LIBPATH:%(win32)s/lib' %(JDK), 'Ws2_32.lib', 'jvm.lib'],
     'mingw32': ['-L%(mingw32)s/lib' %(JDK), '-ljvm'],
     'freebsd7': ['-L%(freebsd7)s/jre/lib/i386' %(JDK), '-ljava', '-lverify',
                  '-L%(freebsd7)s/jre/lib/i386/client' %(JDK), '-ljvm',
Owner

rudimeier commented Mar 20, 2017

Regarding the other linker error. Maybe the patch below could help. This is what @tommykoch was doing in his other port. Maybe the /DLL option causes MSVC to link a library which does not need a main() function (entry point).

commit 8505d20fbcd471c5cff669ec85b84c4fbb1a6138
Author: Ruediger Meier ruediger.meier@ga-group.nl
Date: Fri Mar 10 13:32:56 2017 +0100

from tom add win32 library path: /DLL (untested)
diff --git a/setup.py b/setup.py
index f047038..6824e44 100644
--- a/setup.py
+++ b/setup.py
@@ -147,7 +147,7 @@ LFLAGS = {
     'sunos5': ['-L%(sunos5)s/jre/lib/i386' %(JDK), '-ljava',
                '-L%(sunos5)s/jre/lib/i386/client' %(JDK), '-ljvm',
                '-R%(sunos5)s/jre/lib/i386:%(sunos5)s/jre/lib/i386/client' %(JDK)],
-    'win32': ['/LIBPATH:%(win32)s/lib' %(JDK), 'Ws2_32.lib', 'jvm.lib'],
+    'win32': ['/DLL', '/LIBPATH:%(win32)s/lib' %(JDK), 'Ws2_32.lib', 'jvm.lib'],
     'mingw32': ['-L%(mingw32)s/lib' %(JDK), '-ljvm'],
     'freebsd7': ['-L%(freebsd7)s/jre/lib/i386' %(JDK), '-ljava', '-lverify',
                  '-L%(freebsd7)s/jre/lib/i386/client' %(JDK), '-ljvm',

rudimeier added a commit that referenced this issue Mar 20, 2017

build: add win32 linker option /DLL
Maybe this fixes the linker error in issue #1
"LINK : fatal error LNK1561: entry point must be defined"

rudimeier added a commit that referenced this issue Mar 20, 2017

Merge branch 'fix-issue-1'
* fix-issue-1:
  build: add win32 linker option /DLL
  fix: Visual Studio does not support VLAs (issue #1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment