Re: Second time's a charm
Sebastien Loisel <[email protected]> Fri, 17 Feb 2006 11:38:16 +0100
| Newsgroups | gmane.comp.gnu.octave.graphics,gmane.comp.gnu.octave.maintainers |
|---|---|
| Message-ID | <[email protected]> |
------=_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 <[email protected]> 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 <iostream> EXPORT void hello(void); //extern EXPORT std::ostream std::cout; don't work EXPORT std::ostream &get_cout(void); $ cat dll.cpp #include <iostream> #include "dll.h" EXPORT void hello(void) { std::cout<<"Hello"; } EXPORT std::ostream &get_cout(void) { return std::cout; } $ cat hello.cpp #include <iostream> #include <fstream> #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, <b class=3D"gmail_sendername">David Bateman</b> <<a href=3D"= mailto:[email protected]">[email protected]</a>> wrote= :<div><span class=3D"gmail_quote"></span><blockquote class=3D"gmail_quote" = style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8= ex; padding-left: 1ex;"> I don't know if I'll be able to help, but will try this weekend..<br><br>D.= </blockquote><div><br></div></div>Send me an email when you start and I'll = give you the most updated information. I have new leads for the cerr stuff: <br><br>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...) <br><br>2) I'm guessing there's some black magic way of doing it directly w= ith the unmodified dll, but I don't know.<br><br>3) The window popping up b= riefly can be fixed by replacing<br>-Wl,-subsystem,windows<br>with<br>-Wl,-= subsystem,console <br><br>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.<br><br>Sebastien Loisel<br><br>----<br><br>$ cat dll.h<br>#ifdef BUILD_= DLL <br>/* DLL export */<br>#define EXPORT __declspec(dllexport)<br>#else<br>/*= EXE import */<br>#define EXPORT __declspec(dllimport)<br>#endif<br>#includ= e <iostream><br>EXPORT void hello(void);<br>//extern EXPORT std::ostr= eam std::cout; don't work <br>EXPORT std::ostream &get_cout(void);<br>$ cat dll.cpp<br>#include &= lt;iostream><br>#include "dll.h"<br><br>EXPORT void hello(void= ) {<br> std::cout<<"Hello";<br>}<br>EXPORT std::ostre= am &get_cout(void) { return std::cout; } <br>$ cat hello.cpp<br>#include <iostream><br>#include <fstream>= ;<br>#include "dll.h"<br><br>int main () {<br> std::streamb= uf *stdbuf=3Dstd::cout.rdbuf();<br> std::ofstream out("foo.txt&q= uot;);<br> // std::cout.rdbuf(out.rdbuf()); <-- this doesn't work<br> = get_cout().rdbuf(out.rdbuf()); // <-- this works<br> hello();<br>&= nbsp; get_cout().rdbuf(stdbuf);<br> return 0;<br>}<br>$ cat build.sh<= br>#!/bin/sh<br>g++ -c=20 hello.cpp -o hello.o<br>g++ -c -DBUILD_DLL dll.cpp -o dll.o<br>g++ -shared = -o message.dll dll.o -Wl,--out-implib,libmessage.a<br>g++ -o hello.exe hell= o.o -L./ -lmessage<br><br> ------=_Part_17448_21360119.1140172696233--