473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Making Python extension DLL available to a C++ program

Bulldog
Is there anyway to make the functions defined in a python extension DLL directly available to a C++ program without having to embed that python interpreter in that C++ program?

TIA
Jan 25 '07 #1
5 1399
Motoma
3,237 Expert 2GB
Is there anyway to make the functions defined in a python extension DLL directly available to a C++ program without having to embed that python interpreter in that C++ program?

TIA
Yes.
You will need to tell your linker to link against the associated .lib file.
Jan 25 '07 #2
Motoma
3,237 Expert 2GB
If that isn't an option (i.e. you don't have a lib file) you can link at run-time:
Using Run-Time Dynamic Linking.
Jan 25 '07 #3
Yes.
You will need to tell your linker to link against the associated .lib file.
I am fine with linking to the extension module's .lib file. The problem I have now is that the extension module example in the python doc ( I am using 2.2.3) only exports (using a .def file) the initexample function, not the 'useful' function example.foo(). Below is the source code for the example in the example_nt directory. so from the interpreter I can import the moduel example (example.ll) just fine and call the foo function (example.foo()), but from a c++ app, example and foo aren't visible. Any ideas?

**********************************************
Expand|Select|Wrap|Line Numbers
  1. #include "Python.h"
  2.  
  3. static PyObject *
  4. ex_foo(PyObject *self, PyObject *args)
  5. {
  6.     printf("Hello, world\n");
  7.     Py_INCREF(Py_None);
  8.     return Py_None;
  9. }
  10.  
  11. static PyMethodDef example_methods[] = {
  12.     {"foo", ex_foo, 1, "foo() doc string"},
  13.     {NULL, NULL}
  14. };
  15.  
  16. void
  17. initexample(void)
  18. {
  19.     Py_InitModule("example", example_methods);
  20. }
**********************************************
Jan 26 '07 #4
Motoma
3,237 Expert 2GB
I am fine with linking to the extension module's .lib file. The problem I have now is that the extension module example in the python doc ( I am using 2.2.3) only exports (using a .def file) the initexample function, not the 'useful' function example.foo(). Below is the source code for the example in the example_nt directory. so from the interpreter I can import the moduel example (example.ll) just fine and call the foo function (example.foo()), but from a c++ app, example and foo aren't visible. Any ideas?

**********************************************
#include "Python.h"

static PyObject *
ex_foo(PyObject *self, PyObject *args)
{
printf("Hello, world\n");
Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef example_methods[] = {
{"foo", ex_foo, 1, "foo() doc string"},
{NULL, NULL}
};

void
initexample(void)
{
Py_InitModule("example", example_methods);
}

**********************************************
Sorry, this is beyond my current scope of knowledge, I will catch up on my reading and see if I can help you.
Jan 26 '07 #5
Sorry, this is beyond my current scope of knowledge, I will catch up on my reading and see if I can help you.
I am still interested in finding out how to do this but I figured out that using an extension module would NOT solve my problem. So I am back to square one. The reason is that the foo() function in the example from my previous post is C++ (Duh...) and any calls to python would have to be from an embedded interpreter, which is what I am trying to avoid. I guess I can try to discuss that in another thread.
Jan 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
85
by: masood.iqbal | last post by:
I know that this topic may inflame the "C language Taleban", but is there any prospect of some of the neat features of C++ getting incorporated in C? No I am not talking out the OO stuff. I am...
32
by: siggi | last post by:
@Ben Sizer Hi Ben, in January I received your message re Pygame and Python 2.5: As a Python (and programming ) newbie allow me a - certainly naive - question:
20
by: Mr.SpOOn | last post by:
Hi, I need a structure to represent a set of integers. I also need to perform on this set some basic set operations, such as adding or removing elements, joining with other sets and checking for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.