0

Basically, I have a cython code where i want to call C's inline assembly. I tried below:

cdef extern from *:
    """
    #include <stdio.h>
    void print_endln(){
       asm("nop");
    }
    """
    void print_endln() 

print_endln()

But I get below error:

ids.obj : error LNK2001: unresolved external symbol asm Location\iaa.cp39-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\link.exe' failed with exit code 1120

My OS is windows 10 x64, python version Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

I compile the code as python setup.py build_ext --inplace && python program.py

Is there something wrong I am doing?

hashy
  • 175
  • 10
  • 1
    MSVC doesn't recognize `asm` as a keyword for inline asm. Use a C compiler appropriate for the flavour of inline asm syntax you want to use. (e.g. clang, GCC, or ICC for this GNU C Basic asm. But see the update to the answer on your last question for GNU C extended asm which you need if you're going to do anything useful.) Or of course use MSVC `_asm{}` blocks, if you don't mind being limited to obsolete 32-bit code, and the general inefficiency of MSVC _asm. [What is the difference between 'asm', '\_\_asm' and '\_\_asm\_\_'?](https://stackoverflow.com/q/3323445) – Peter Cordes Jun 21 '21 at 21:20
  • 1
    Does this answer your question? [What is the difference between 'asm', '\_\_asm' and '\_\_asm\_\_'?](https://stackoverflow.com/questions/3323445/what-is-the-difference-between-asm-asm-and-asm) – Peter Cordes Jun 21 '21 at 21:20
  • 1
    (You'd have exactly the same problem if you tried to compile and link that function in a pure C program, independent of Cython, using MSVC. You can do that for testing purposes to rule out Cython problems. Of course, a C++ compiler would have rejected `asm(char *)` as an undeclared function; only C allows implicit declaration.) – Peter Cordes Jun 21 '21 at 21:41
  • @PeterCordes is there a way to force cython to use mingw gcc, I have VS GCC and MinGW gcc both installed. – hashy Jun 22 '21 at 00:08
  • Almost certainly; it needed a way to find MSVC in the first place, but I've never used Cython. – Peter Cordes Jun 22 '21 at 00:18
  • @hashy Python on Windows is now pretty picky about extension modules having to be built with the same compiler that Python was built with. In the past it was definitely possible to use MingW but I don't think it is any more. – DavidW Jun 22 '21 at 08:38

0 Answers0