Hi!
I'm trying to learn python and have encountered some strange behaviour. I am experimenting with ctypes and a self-made (very simple) DLL.
This is Python script I'm trying to run:
from ctypes import *
myLib = CDLL("libDlltest")
myLib.hello()
myLib.goodbye()
print 'I am a line'
myLib.goodbye()
I've configured eclipse according to build the library according to this guide, and when it didn't work I built it in cygwin with gcc.
hello() and goodbye() are implemented as
EXPORT void hello(void) {
printf ("Hello\n");
}
EXPORT void goodbye(void) {
puts ("Goodbye");
}
(Where EXPORT is a macro that you can read more about in the above guide)
Nevertheless, it starts getting weird when the output I get from the program is:
I am a line
Hello
Goodbye
Goodbye
In case you didn't notice, the printouts are not in the correct order. The text printed from the library functions appears after or right before the program finishes executing, and the text printed by the python 'print' appears first, despite being called second.
I can't imagine this being the intended behaviour. I'm probably the one doing something wrong here anyway, so:
- What could I be doing wrong?
- Is there any way to explain this behaviour?