mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.95k stars 563 forks source link

building on MSYS2 MINGW64 #1168

Open RoDuth opened 1 year ago

RoDuth commented 1 year ago

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 commented 1 year ago

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