0

I've got a .c file that has Python.h in it and I want to compile it.

This is what I'm entering into the cmd line at the moment cl -IC:\[...]\Python35\include -IC:\[...]\Python35\libs TestFilePython.c

Which results in the error: LINK : fatal error LNK1104: cannot open file 'python35.lib'

I've found this which seems to be the perfect fit for my question, but I cannot figure out what LIBPATHs I should include. Could someone help me with that?

edit: Okay so I'm actually using cpp so setup.py looks like this:

from distutils.core import setup
from Cython.Build import cythonize

setup(ext_modules = cythonize(
           "TestFilePython.pyx",                 # our Cython source
           language="c++",             # generate C++ code
      ))

Running python setup.py build_ext --inplace results in a .cpp being created (.c before language option)

Now I'm trying to compile that .cpp. While searching I've just come across the idea that I need to include an embed option (this might solve the no entry point problem), still trying to see what I can do that.

TestFilePython.pyx is just: print("Hello World"), if asked I can also print the contents of cpp that is created.

Community
  • 1
  • 1
Nimitz14
  • 2,138
  • 5
  • 23
  • 39
  • 1
    Don't [I]include the import "libs". That directory gets added using `/link /LIBPATH:C:\[...]\Python35\libs`. Also, the linker options have to be listed after the source file(s). – Eryk Sun Jan 16 '16 at 12:56
  • `cl -IC:\Users\[...]\Python35\include TestFilePython.cpp /link /LIBPATH:C:\Users\[...]\Python35\libs` gives me error `entry point must be defined` – Nimitz14 Jan 16 '16 at 12:59
  • If you're building an executable you need a `main` or `wmain` function. If you're build a DLL/PYD use `cl /LD ...`. – Eryk Sun Jan 16 '16 at 13:05
  • I'm trying to get cython to work. i shouldnt need a main function... – Nimitz14 Jan 16 '16 at 13:10
  • @Nimitz14 Could you show us your code? – fuz Jan 16 '16 at 13:13
  • The cythonized TestFilePython.cpp file should have already been compiled and linked as TestFilePython.pyd. – Eryk Sun Jan 16 '16 at 13:24
  • yeah well that's not working, and trust me ive already asked lots of people and would prefer not to go down that rabbit hole. It should be possible to manually compile the .cpp file right. Just saw your dll comment, guess I'll try that angle. – Nimitz14 Jan 16 '16 at 13:28
  • Let's go down that rabbit hole just for a bit. Did you run Python in the directory that has the extension module "TestFilePython.pyd" and execute `import TestFilePython`? – Eryk Sun Jan 16 '16 at 13:31
  • Why is this tagged as C when you are trying to compile C++ code? – fuz Jan 16 '16 at 13:31
  • @eryksun when running setup.py it won't do the last step because for some reason msvs is not compiling, meaning a .pyd is never created. `don't know how to compile c/c++ code on platform 'nt' with 'msvs' compiler`, it does give me a .cpp file which is something i can work with. I'm on VS2015, so people tell me it should work, and I plan on reinstalling it at some point but before I do that I thought I'd try and find a way around. – Nimitz14 Jan 16 '16 at 13:37
  • What version of Visual Studio do you have installed? Building extensions for Python 3.5 requires Visual Studio 2015. On Windows 10, I just Cythonized an example "TestFilePython.pyx" and built TestFilePython.cp35-win_amd64.pyd in place. It worked fine. – Eryk Sun Jan 16 '16 at 13:39
  • 'msvs'? Start Python and check `import distutils.ccompiler;` `distutils.ccompiler.get_default_compiler()`. It should be 'msvc'. – Eryk Sun Jan 16 '16 at 13:53
  • that's what it is ;) – Nimitz14 Jan 16 '16 at 13:58
  • 'msvs' or 'msvc'? If it says 'msvs', remove 3.5 and redownload/reinstall 3.5.1. – Eryk Sun Jan 16 '16 at 14:05
  • damnit. i got my hopes up but it does say msvc :( i just checked trying to get .pyd from .pyx it does say 'msvs' (something weird is going on...) – Nimitz14 Jan 16 '16 at 14:09
  • OH MY GOD. it worked. just had to add `--compiler=msvc` at the end. i was always using msvs – Nimitz14 Jan 16 '16 at 14:14
  • thank you for your patience! – Nimitz14 Jan 16 '16 at 14:16

0 Answers0