cnvogelg / machine68k

m68k machine emulator for Python based on Musashi
5 stars 1 forks source link

library fails to build when installing, error: "cannot export PyInit_machine68k: symbol not defined" #3

Closed ProxyPlayerHD closed 2 weeks ago

ProxyPlayerHD commented 1 month ago

I'm trying to run pip install machine68k in my MSYS2 setup because i need it for amitools, because i need that for the ADF Explorer. but it throws this error after trying to build the library. i'm using python 3.11.9 and GCC 14.1.0 and here's the complete output log:

$ pip3 install machine68k
Collecting machine68k
  Using cached machine68k-0.2.0.tar.gz (398 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: machine68k
  Building wheel for machine68k (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for machine68k (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [75 lines of output]
      use_cython: True
      cython version: 3.0.11
      running bdist_wheel
      running build
      running build_py
      running egg_info
      writing src/machine68k.egg-info/PKG-INFO
      writing dependency_links to src/machine68k.egg-info/dependency_links.txt
      writing top-level names to src/machine68k.egg-info/top_level.txt
      ERROR setuptools_scm._file_finders.git listing git files failed - pretending there aren't any
      reading manifest file 'src/machine68k.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'src/machine68k.egg-info/SOURCES.txt'
      creating build
      creating build/lib.mingw_x86_64-cpython-311
      creating build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/Makefile -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/history.txt -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68k.h -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68k_in.c -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kconf.h -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kcpu.c -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kcpu.h -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kdasm.c -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kfpu.c -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kmake.c -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/m68kmmu.h -> build/lib.mingw_x86_64-cpython-311/musashi
      copying src/musashi/readme.txt -> build/lib.mingw_x86_64-cpython-311/musashi
      creating build/lib.mingw_x86_64-cpython-311/win
      copying src/win/stdint.h -> build/lib.mingw_x86_64-cpython-311/win
      creating build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/README.txt -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/mamesf.h -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/milieu.h -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/softfloat-macros -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/softfloat-specialize -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/softfloat.c -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      copying src/musashi/softfloat/softfloat.h -> build/lib.mingw_x86_64-cpython-311/musashi/softfloat
      running build_ext
      running gen
      creating 'gen' dir
      building 'build/m68kmake' tool
      tool source: src/musashi/m68kmake.c
      tool object: build/src/musashi/m68kmake.o
      creating build/src
      creating build/src/musashi
      gcc -shared -O -Wall -c src/musashi/m68kmake.c -o build/src/musashi/m68kmake.o
      gcc -s build/src/musashi/m68kmake.o -o build/m68kmake.exe
      generating source files

          Musashi v4.60 68000, 68008, 68010, 68EC020, 68020, 68EC030, 68030, 68EC040, 68040 emulator
                  Copyright Karl Stenerud (kstenerud@gmail.com)

      Generated 1967 opcode handlers from 518 primitives
      building 'machine68k' extension
      creating build/temp.mingw_x86_64-cpython-311
      creating build/temp.mingw_x86_64-cpython-311/gen
      creating build/temp.mingw_x86_64-cpython-311/src
      creating build/temp.mingw_x86_64-cpython-311/src/musashi
      creating build/temp.mingw_x86_64-cpython-311/src/musashi/softfloat
      gcc -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 -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -IZ:/C_Stuff/MSYS64/mingw64/include/python3.11 -c gen/m68kops.c -o build/temp.mingw_x86_64-cpython-311/gen/m68kops.o
      gen/m68kops.c: In function 'm68ki_build_opcode_table':
      gen/m68kops.c:36709:13: warning: unused variable 'cycle_cost' [-Wunused-variable]
      36709 |         int cycle_cost;
            |             ^~~~~~~~~~
      gcc -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 -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -IZ:/C_Stuff/MSYS64/mingw64/include/python3.11 -c src/mem.c -o build/temp.mingw_x86_64-cpython-311/src/mem.o
      gcc -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 -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -IZ:/C_Stuff/MSYS64/mingw64/include/python3.11 -c src/musashi/m68kcpu.c -o build/temp.mingw_x86_64-cpython-311/src/musashi/m68kcpu.o
      gcc -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 -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -IZ:/C_Stuff/MSYS64/mingw64/include/python3.11 -c src/musashi/m68kdasm.c -o build/temp.mingw_x86_64-cpython-311/src/musashi/m68kdasm.o
      gcc -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 -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -IZ:/C_Stuff/MSYS64/mingw64/include/python3.11 -c src/musashi/softfloat/softfloat.c -o build/temp.mingw_x86_64-cpython-311/src/musashi/softfloat/softfloat.o
      gcc -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 -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -IZ:/C_Stuff/MSYS64/mingw64/include/python3.11 -c src/traps.c -o build/temp.mingw_x86_64-cpython-311/src/traps.o
      writing build/temp.mingw_x86_64-cpython-311/gen/machine68k.cp311-mingw_x86_64.def
      gcc -shared -Wl,--enable-auto-image-base -s build/temp.mingw_x86_64-cpython-311/gen/m68kops.o build/temp.mingw_x86_64-cpython-311/src/mem.o build/temp.mingw_x86_64-cpython-311/src/musashi/m68kcpu.o build/temp.mingw_x86_64-cpython-311/src/musashi/m68kdasm.o build/temp.mingw_x86_64-cpython-311/src/musashi/softfloat/softfloat.o build/temp.mingw_x86_64-cpython-311/src/traps.o build/temp.mingw_x86_64-cpython-311/gen/machine68k.cp311-mingw_x86_64.def -LZ:/C_Stuff/MSYS64/mingw64/lib -lpython3.11 -o build/lib.mingw_x86_64-cpython-311/machine68k.cp311-mingw_x86_64.pyd
      Z:/C_Stuff/MSYS64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot export PyInit_machine68k: symbol not defined
      collect2.exe: error: ld returned 1 exit status
      error: command 'Z:\\C_Stuff\\MSYS64\\mingw64\\bin/gcc.EXE' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for machine68k
Failed to build machine68k
ERROR: Could not build wheels for machine68k, which is required to install pyproject.toml-based projects

i have no idea what is going wrong. i cannot even find any mention of "PyInit_machine68k" within the source code, so it's likely supposed to be generated on the fly? but then why isn't it present?

Sembiance commented 3 weeks ago

I have also encountered this error. I wasn't installing via pip, instead I compile it from source with a custom Gentoo package.

The issue for me turned out to be the version of setuptools. When using 72.1.0 machine68k compiles just fine. When using 72.2.0 or 73.0.1 then machine68k doesn't compile correctly.

Attached are 2 logs from the compile step. On the works.txt 72.1.0 setuptools you can see these lines:

Compiling src/mach.pyx because it changed.
[1/1] Cythonizing src/mach.pyx
...
x86_64-pc-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -O2 -pipe -march=broadwell -maes -mrtm --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=46080 -fPIC -DMUSASHI_CNF=\"my_conf.h\" -Isrc -Isrc/musashi -Igen -I/usr/include/python3.12 -c src/mach.c -o /var/tmp/portage/dev-python/machine68k-0.2.0/work/machine68k-0.2.0-python3_12/temp.linux-x86_64-cpython-312/src/mach.o

In the fails.txt 73.0.1 setuptools, it doesn't have these lines, so it's not compiling those at all.

cnvogelg commented 3 weeks ago

I got the same error here, too.

A fix is pushed with bb15d5a35504ada3d149061415b0783134bf2384 and pushed a new release 0.3.0

Could you give it a try?

Sembiance commented 3 weeks ago

I can confirm that machine68k-0.3.0 correctly works now with setuptools-73.0.1 Thanks so much for the fix!