Problems embedding Python

P

Psymaster

I've tried running scripts from the embedded interpreter but it doesn't
work. If I try the same scripts as strings to interpret it works. Here
is my program:

#include <stdio.h>
#include "Python.h"

int main(int argc, char *argv[])
{
FILE *script = fopen("c:/c.py", "r");

Py_Initialize();
PyRun_SimpleFile(script, "c.py");
Py_Finalize();

return 0;
}


c.py contains just a simple print statement.

This compiles and links under MSVC 6 but when run crashes. Any help?
 
J

Joe Francia

Psymaster said:
I've tried running scripts from the embedded interpreter but it doesn't
work. If I try the same scripts as strings to interpret it works. Here
is my program:

#include <stdio.h>
#include "Python.h"

int main(int argc, char *argv[])
{
FILE *script = fopen("c:/c.py", "r");

Py_Initialize();
PyRun_SimpleFile(script, "c.py");
Py_Finalize();

return 0;
}


c.py contains just a simple print statement.

This compiles and links under MSVC 6 but when run crashes. Any help?

Maybe escape your backslash? :

FILE *script = fopen("c:/c.py", "r");
------------------------^
 
M

Mark Hammond

Psymaster said:
I've tried running scripts from the embedded interpreter but it doesn't
work. If I try the same scripts as strings to interpret it works. Here
is my program: ....
> This compiles and links under MSVC 6 but when run crashes. Any help?

You are almost certainly not linking with the correct CRTL. You *must*
use the /MD compiler option for release builds, or /MDd for debug builds.

Mark.
 
P

Psymaster

You are almost certainly not linking with the correct CRTL. You
*must* use the /MD compiler option for release builds, or /MDd for
debug builds.

What's a CRTL? Hiw do I pass these options to the compiler? I've
already said that if I pass the contents of the file as strings and
execute them with PyRun_SimpleString() it works fine. Also, I know the
file is loaded because I can read it from my program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,631
Members
45,338
Latest member
41Pearline46

Latest Threads

Top