Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress output to cout from linked library

Tags:

c++

linux

linker

I need to link my C++ programs against a couple shared libraries which generate way too much output to std::cout and std::cerr rendering them both useless for my uses. I have access to the C++ source code of these libraries, but cannot modify them.

Is there a way to redirect their output to a different stream or suppress it when linked against my code? I would prefer a clean way in C++, but fearing that that would be impossible I will also be happy with dirty linker hacks. Also a "proxy libstdc++" would be fine as a last resort.

I am working with a GNU toolchain (g++, libtool, ld) under Linux.

like image 552
Benjamin Bannier Avatar asked Aug 26 '10 14:08

Benjamin Bannier


1 Answers

Apparently, freopen can do that.

like image 148
Sjoerd Avatar answered Oct 08 '22 19:10

Sjoerd