0

I am currently using PyCUDD, which is a SWIG-generated Python wrapper for the C package CUDD. I'm currently trying to get CUDD to print some debug information from inside the C code, but any printfs inside the C code don't seem to be producing any output - putting them in the .i files for SWIG produces output, putting them in the C code does not. I'm not sure if this is some property of SWIG specifically or of compiling the C code to a shared object library.

(Particularly frustrating is that I know that I have had this problem and gotten it working before, but I can't seem to find anything searching for the problem now, and I apparently forgot to leave notes on that one thing.)

2 Answers2

0

I think problem is that Launched program closes (or redirects original stdout handler/descriptor to somewhere) stdout, so Library cannot gets Handler/descriptor. So I tried to recover devices and reopen.

In linux, console device is located at /dev/stdout (it is symbolic link to specific devices or file located in fd 1 at launched time), so reopen this file and recover file descriptor.

int fd = open("/dev/stdout", O_RDONLY);
if(fd != -1)
    dup2(fd,1);

In Windows, AllocConsole tries to create new Console if current process does not have console. This is for the case when PyCUDD(Or any program) uses custom console. And freopen makes writable to our allocated console, so printf will work for new console.

AllocConsole();
freopen("CONOUT$", "w", stdout);
j31d0
  • 141
  • 5
  • Explanation? This seems like a fix for when stdout is a fake file handle or not connected to a console, but I'm not sure why this would fix the OP's problem without some explanation. Does PyCUDD or SWIG do something that would cause this problem? – ShadowRanger Jan 02 '18 at 18:14
  • I updated my answer for explanation. Thank you for advice. – j31d0 Jan 02 '18 at 18:27
0

I still forget what my problem was before. However, I have found that what was causing my problem here was a linker issue - the linker was looking at an old version of the library, which did not have my changes.

  • 1
    Please use comment section for your valuable feedback related to the question and use answer section to provide detailed solutions for the asked question. Thanks – Suhaib Janjua Feb 07 '18 at 19:56