octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Second time's a charm


From: Sebastien Loisel
Subject: Re: Second time's a charm
Date: Fri, 17 Feb 2006 11:38:16 +0100

On 2/17/06, David Bateman <address@hidden> 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=std::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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]