Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio fails to compile psutil #81

Closed
giampaolo opened this issue May 23, 2014 · 10 comments
Closed

Visual Studio fails to compile psutil #81

giampaolo opened this issue May 23, 2014 · 10 comments

Comments

@giampaolo
Copy link
Owner

From charless...@gmail.com on March 15, 2010 15:50:26

If you try to compile psutil, specifically _psutil_mswindows.c in visual
studio, (or through python's setup.py with visual C++ cl), you will get
this error 
syntax error : missing ';' before 'type'
followed by a bunch of no type definitions.

The problem is that when visual studio compiles C it wants all variables to
be declared at the top of all functions, and the line
struct module_state *st = GETSTATE(module);
violates this rule.

Moving the declaration of st to the top of the function fixes the problem.

Original issue: http://code.google.com/p/psutil/issues/detail?id=81

@giampaolo
Copy link
Owner Author

From charless...@gmail.com on March 15, 2010 08:11:58

Also the python module init function (init_psutil_mswindows) should be declared 
PyMODINIT_FUNC
init_psutil_mswindows(void)
So that the function is exported and import sees it.  I am guessing you somehow set
this on the command like with setup.py but I am building _psutil in visual studio and
this is the expected definition.

Thanks

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on March 16, 2010 06:39:54

Thanks for the report, we'll look into it - can you provide more details about your
build platform (version of Windows, Python, and Visual Studio)?

P.S. I'm assume you know this already but we do have pre-built binaries for Windows
on all platforms/python versions available in the downloads section. You shouldn't
need to build from source unless you're wanting to play with code changes or
something along those lines. And if you are making modifications, we'd love to hear
of anything creative you do with psutil :-)

Status: Accepted
Labels: OpSys-Windows

@giampaolo
Copy link
Owner Author

From charless...@gmail.com on March 16, 2010 07:10:15

I am using windows 7 with visual studio 2010 rc.  Python version 2.7 a3.
I am trying to keep my project self contained and easy to use which has come down to
compiling needed libraries and dependencies with my own makefiles and solution.  In
my environment I cannot guarantee that the machines I want to run my project on will
have the latest python, psutil, win32api, etc.

I have not started actually using psutil but I am planning on integrating it into an
automated test environment to monitor the system for irregularities.  High memory
usage, 100% cpu, etc.  If my trials look promising I am going to go full scale with
it and I will be needing AIX, VOS, HP-UX, and Solaris implementations so I might have
more to contribute in the future :)

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on March 19, 2010 18:34:21

Is this being built then as a project in Visual Studio? I don't have that version of
Visual Studio available unfortunately, and we use setup.py to do all our builds, so
I'm not sure if I'll be able to duplicate it. We can declare all the variables at the
top of the functions at least. I actually tried to keep all the code that way
throughout the module to avoid problems with older compilers and ones not following
the C99 spec (i.e. visual studio), but some of the newer code that's been contributed
is probably a little less strict about it.

I'm not sure about changing the init_psutil_mswindows definition - we had to change
some of that code to be Python 3 friendly so I don't want to mess with anything there
until we can test and verify that it doesn't break our Python 3.x builds too. If we
can confirm that then we'll go ahead and make that change as well in SVN so it'll be
fixed for the next release. 

-Jay

@giampaolo
Copy link
Owner Author

From charless...@gmail.com on March 19, 2010 19:15:59

I am building it as a project in visual studio.  If you have access to a windows
machine you can download the latest visual studio for free actually.  Its a release
candidate at the moment, I can supply the project file if need be but it also fails
setup.py
Setup.py will try to compile using the available compiler which in my environment is
visual studio, and since visual studio does not compile it setup.py fails as well.

About the module init function, there are some example modules that build in both
versions, the one I have right off hand is win32api which defines a
PYWIN_MODULE_INIT_FUNC define based on the PY_VERSION_HEX from Python.h

win32api is not the nicest code in the world though, but its the best example i have
off hand.  The declarations are in PyWinTypes.h

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on March 19, 2010 19:21:40

If you like you can try building with the latest SVN, I resolved several warnings and
the issue with the struct declaration. The only thing I didn't touch yet was the
module init function declaration, I'll talk that over with Giampaolo when I get a
chance since he did the testing on Python 3.x for Windows.

@giampaolo
Copy link
Owner Author

From shinnerspete on May 20, 2010 09:48:34

This patch resolves the build errors and warnings with MSVC8.

Attachment: msvcfixes.diff

@giampaolo
Copy link
Owner Author

From g.rodola on October 02, 2010 10:44:45

This should now be fixed as r649 .

Status: WaitingForReview
Labels: Milestone-0.2.0

@giampaolo
Copy link
Owner Author

From g.rodola on October 11, 2010 13:42:06

Closing this out as fixed ( r673 ).

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:52:21

Updated csets after the SVN -> Mercurial migration: r649 == revision 0f7fb76cde5e r673 == revision 2e1c2f0ab543

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant