1

I'm having trouble converting a .c file to a .dll file with VSCode. I think the problem is that MinGW is not able to compile on x64.

OSError: [WinError 193] %1 is not a valid Win32 application

Any ideas?

#include <stdio.h>
#include <stdlib.h>

double TourLength(int* tour, int tourlength, double** d) {
  tour[tourlength+1] = tour[0];
  double L = 0;
  int i, j, k;
  for (k = 0; k < tourlength; k++) {
    i = tour[k];
    j = tour[k + 1];
    L += d[i][j];
  }
  return L;
}

The idea is to use this code in python with the aim of improving its compilation speed.

  • 1
    need to see what compile & link commands you are using. – pm100 Mar 16 '23 at 17:55
  • If you're interested in speeding up some Python via DLLs, I'd suggest Cython. Cython has good support for numpy style arrays, as well. – dirck Mar 16 '23 at 18:03
  • That's a pretty far tangent from the question. Question is: 1) how to compile C code to a DLL in VSCode. 2) Use that DLL from python. – Paul Dempsey Mar 16 '23 at 18:37
  • MinGW can definitely *run* on x86_64, since even if you have a win32-only version, 64-bit Windows can run Win32 programs. But it would be really surprising for you to have gotten your hands on a version that can't build for x86_64. I'd guess instead that your VSCode contains some malformed build configuration. – John Bollinger Mar 16 '23 at 19:06
  • 1
    If you are using vscode, stop. Forget that it exists. Learn to compile C programs from the command line. – n. m. could be an AI Mar 16 '23 at 20:24
  • [\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example). Please also add your *Python* code and (as others already mentioned) compile and link commands (that build your *.dll*). What *Python* are you running? ([\[SO\]: How do I determine if my python shell is executing in 32bit or 64bit mode on OS X? (@CristiFati's answer)](https://stackoverflow.com/a/50053286/4788546)). – CristiFati Mar 18 '23 at 22:53

0 Answers0