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

building on MSYS2 MINGW64 #1168

Open
RoDuth opened this issue Feb 19, 2023 · 2 comments · May be fixed by #1169
Open

building on MSYS2 MINGW64 #1168

RoDuth opened this issue Feb 19, 2023 · 2 comments · May be fixed by #1169

Comments

@RoDuth
Copy link

RoDuth commented Feb 19, 2023

Can't seem to get build to work on mingw (from looking at other issues seems cygwin is working), I note some old references to MING32 in the source (e.g. in src/pyodbc.h) but it seems setup.py does not account for mingw. Hence the below error (with windows compiler flags).

$ python setup.py build
WARNING: '' not a valid package name; please use only .-separated package names in setup.py
running build
running build_py
running build_ext
building 'pyodbc' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-
D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -DPYODBC_VERSION=4.0.36b17 -IC:/msys64/mingw64/include/python3.10 -c src/buffer.cpp -o build/temp.mingw_x86_64-3.10/src/buffer.o /Wall /wd4514 /wd4820 /wd4668 /wd4711 /wd
4100 /wd4127 /wd4191 /d2FH4-
gcc.exe: fatal error: cannot specify '-o' with '-c', '-S' or '-E' with multiple files
compilation terminated.
error: command 'C:\\msys64\\mingw64\\bin/gcc.exe' failed with exit code 1
@RoDuth
Copy link
Author

RoDuth commented Feb 19, 2023

Having a bit of a stab in the dark with setup.py

-import sys, os, re, shlex
+import sys, os, re, shlex, sysconfig

...

         except ValueError:
             pass

-    if os.name == 'nt':
+    if 'mingw' in sysconfig.get_platform():
+        # Windows mingw
+        settings['extra_compile_args'].extend([
+            '-Wno-write-strings',
+            '-Wno-deprecated-declarations',
+        ])
+        settings['libraries'].append('odbc32')
+
+    elif os.name == 'nt':
         settings['extra_compile_args'].extend([
             '/Wall',

I get a little further:

$ python setup.py build
WARNING: '' not a valid package name; please use only .-separated package names in setup.py
running build
running build_py
running build_ext
building 'pyodbc' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-
D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -DPYODBC_VERSION=4.0.36b17 -IC:/msys64/mingw64/include/python3.10 -c src/buffer.cpp -o build/temp.mingw_x86_64-3.10/src/buffer.o -Wno-write-strings -Wno-deprecated-declar
ations
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-
D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -DPYODBC_VERSION=4.0.36b17 -IC:/msys64/mingw64/include/python3.10 -c src/cnxninfo.cpp -o build/temp.mingw_x86_64-3.10/src/cnxninfo.o -Wno-write-strings -Wno-deprecated-de
clarations
In file included from src/cnxninfo.cpp:8:
src/wrapper.h: In destructor 'RegKey::~RegKey()':
src/wrapper.h:114:13: error: 'RegCloseKey' was not declared in this scope
  114 |             RegCloseKey(hkey);
      |             ^~~~~~~~~~~
error: command 'C:\\msys64\\mingw64\\bin/gcc.exe' failed with exit code 1

RoDuth added a commit to RoDuth/pyodbc that referenced this issue Feb 20, 2023
@RoDuth RoDuth linked a pull request Feb 20, 2023 that will close this issue
RoDuth added a commit to RoDuth/pyodbc that referenced this issue Dec 16, 2024
RoDuth added a commit to RoDuth/pyodbc that referenced this issue Dec 17, 2024
RoDuth added a commit to RoDuth/pyodbc that referenced this issue Dec 17, 2024
RoDuth added a commit to RoDuth/pyodbc that referenced this issue Dec 19, 2024
@RoDuth
Copy link
Author

RoDuth commented Dec 23, 2024

For future reference...

Out of curiosity I thought I'd check Cygwin, it appears pyodbc does not install in Cygwin as it currently stands. There seems to be 2 possible workarounds:
1)
Avoid the reference to SQL_OV_ODBC3_80 here:

defaultVersion = (SQLPOINTER)SQL_OV_ODBC3_80;

e.g. something like this would work:

+   #ifdef SQL_OV_ODBC3_80
    PyObject* odbcversion = PyObject_GetAttrString(pModule, "odbcversion");
    if (PyUnicode_CompareWithASCIIString(odbcversion, "3.8") == 0)
        {
            defaultVersion = (SQLPOINTER)SQL_OV_ODBC3_80;
        }
    }
    Py_DECREF(odbcversion);
+   #endif

Seems Cygwin as supplied has a header file that defines SQL_OV_ODBC3 but not SQL_OV_ODBC3_80. (MSYS2 is the same).
2)
Install unixODBC... makes more sense but is not trivial as, unlike MSYS2, it is not supplied by any Cygwin package and will have to be built from source (you'll need to install autoconf, automake, gcc, etc, Cygwin packages and it will take a while. unixODBC source contains README.CYGWIN which explains the process but I believe I also had to use autoheader).
Then remove these lines:

pyodbc/src/pyodbc.h

Lines 48 to 50 in 12fe42e

#ifdef __CYGWIN__
#include <windows.h>
#endif

to avoid error: /usr/include/w32api/wtypesbase.h:101:15: note: previous declaration as ‘typedef unsigned int ULONG’

I did not test either approach beyond checking pyodbc.drivers() returned as expected. I do not have a use case myself so will let sleeping dogs lie but thought it worth recording somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant