From graphics-request at octave dot org Fri Feb 17 04:40:02 2006 Subject: Re: Second time's a charm From: Sebastien Loisel To: David dot Bateman at motorola dot com Cc: octave maintainers mailing list , octave-graphics Date: Fri, 17 Feb 2006 11:38:16 +0100 ------=_Part_17448_21360119.1140172696233 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 2/17/06, David Bateman wrote: > > I don't know if I'll be able to help, but will try this weekend.. > > D. Send me an email when you start and I'll give you the most updated information. I have new leads for the cerr stuff: 1) This is apparently related to dynamic linkage. I'm attaching a sample program to this email that illustrates the problem. I've confirmed that adding a get_cerr() function to liboctave would solve the problem. (Well, I don't know what happens if several dll's are involved...) 2) I'm guessing there's some black magic way of doing it directly with the unmodified dll, but I don't know. 3) The window popping up briefly can be fixed by replacing -Wl,-subsystem,windows with -Wl,-subsystem,console This will force Windows to open a console for my app and keep it opened. I think I know how to fix this more elegantly, but that'll have to wait. Sebastien Loisel ---- $ cat dll.h #ifdef BUILD_DLL /* DLL export */ #define EXPORT __declspec(dllexport) #else /* EXE import */ #define EXPORT __declspec(dllimport) #endif #include EXPORT void hello(void); //extern EXPORT std::ostream std::cout; don't work EXPORT std::ostream &get_cout(void); $ cat dll.cpp #include #include "dll.h" EXPORT void hello(void) { std::cout<<"Hello"; } EXPORT std::ostream &get_cout(void) { return std::cout; } $ cat hello.cpp #include #include #include "dll.h" int main () { std::streambuf *stdbuf=3Dstd::cout.rdbuf(); std::ofstream out("foo.txt"); // std::cout.rdbuf(out.rdbuf()); <-- this doesn't work get_cout().rdbuf(out.rdbuf()); // <-- this works hello(); get_cout().rdbuf(stdbuf); return 0; } $ cat build.sh #!/bin/sh g++ -c hello.cpp -o hello.o g++ -c -DBUILD_DLL dll.cpp -o dll.o g++ -shared -o message.dll dll.o -Wl,--out-implib,libmessage.a g++ -o hello.exe hello.o -L./ -lmessage ------=_Part_17448_21360119.1140172696233 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 2/17/06, David Bateman <David dot Bateman@motorola dot com> wrote= :
I don't know if I'll be able to help, but will try this weekend..

D.=

Send me an email when you start and I'll = give you the most updated information. I have new leads for the cerr stuff:

1) This is apparently related to dynamic linkage. I'm attaching a s= ample program to this email that illustrates the problem. I've confirmed th= at adding a get_cerr() function to liboctave would solve the problem. (Well= , I don't know what happens if several dll's are involved...)

2) I'm guessing there's some black magic way of doing it directly w= ith the unmodified dll, but I don't know.

3) The window popping up b= riefly can be fixed by replacing
-Wl,-subsystem,windows
with
-Wl,-= subsystem,console

This will force Windows to open a console for my app and keep it op= ened. I think I know how to fix this more elegantly, but that'll have to wa= it.

Sebastien Loisel

----

$ cat dll.h
#ifdef BUILD_= DLL
/* DLL export */
#define EXPORT __declspec(dllexport)
#else
/*= EXE import */
#define EXPORT __declspec(dllimport)
#endif
#includ= e <iostream>
EXPORT void hello(void);
//extern EXPORT std::ostr= eam std::cout; don't work
EXPORT std::ostream &get_cout(void);
$ cat dll.cpp
#include &= lt;iostream>
#include "dll.h"

EXPORT void hello(void= ) {
  std::cout<<"Hello";
}
EXPORT std::ostre= am &get_cout(void) { return std::cout; }
$ cat hello.cpp
#include <iostream>
#include <fstream>= ;
#include "dll.h"

int main () {
  std::streamb= uf *stdbuf=3Dstd::cout.rdbuf();
  std::ofstream out("foo.txt&q= uot;);
  // std::cout.rdbuf(out.rdbuf()); <-- this doesn't work
  = get_cout().rdbuf(out.rdbuf()); // <-- this works
  hello();
&= nbsp; get_cout().rdbuf(stdbuf);
  return 0;
}
$ cat build.sh<= br>#!/bin/sh
g++ -c=20 hello.cpp -o hello.o
g++ -c -DBUILD_DLL dll.cpp -o dll.o
g++ -shared = -o message.dll dll.o -Wl,--out-implib,libmessage.a
g++ -o hello.exe hell= o.o -L./ -lmessage

------=_Part_17448_21360119.1140172696233--