Hi, I'm writing some code that prints to std::ostream. However, it seems that all of the LLVM objects can only print to llvm::raw_ostream, so I can't do this: void write(std::ostream &out) { ... for (BasicBlock::iterator i = block->begin(), e = block->end(); i ! = e; ++i) { Instruction *instruction = i; out << *instruction << std::endl; ... } ... } I tried working around this problem using the raw_os_ostream adapter: #include <llvm/Support/raw_os_ostream.h> ... raw_os_ostream raw_out(out); raw_out << *instruction << std::endl; It compiles fine, but opt gives a runtime error when trying to load the pass: Symbol not found: __ZTVN4llvm14raw_os_ostreamE Any thoughts on why this is happening? And is there a workaround that doesn't involve raw_os_ostream? Thanks, Trevor
On Apr 1, 2010, at 3:52 PM, Trevor Harmon wrote:> Hi, > > I'm writing some code that prints to std::ostream. However, it seems > that all of the LLVM objects can only print to llvm::raw_ostream, so I > can't do this: > > void write(std::ostream &out) { > ... > for (BasicBlock::iterator i = block->begin(), e = block->end(); i ! > = e; ++i) { > Instruction *instruction = i; > out << *instruction << std::endl; > ... > } > ... > } > > I tried working around this problem using the raw_os_ostream adapter: > > #include <llvm/Support/raw_os_ostream.h> > ... > raw_os_ostream raw_out(out); > raw_out << *instruction << std::endl; > > It compiles fine, but opt gives a runtime error when trying to load > the pass: > > Symbol not found: __ZTVN4llvm14raw_os_ostreamE > > Any thoughts on why this is happening? And is there a workaround that > doesn't involve raw_os_ostream? Thanks,It's hard to say: __ZTVN4llvm14raw_os_ostreamE is the vtable for raw_os_ostream. This should be provided by lib/Support/raw_os_ostream.cpp. Perhaps you're not linking in that .o file for some reason. A workaround would be to use raw_ostream in your code instead of ostream :) -Chris
On Apr 1, 2010, at 3:58 PM, Chris Lattner wrote:> It's hard to say: __ZTVN4llvm14raw_os_ostreamE is the vtable for > raw_os_ostream. This should be provided by lib/Support/ > raw_os_ostream.cpp. Perhaps you're not linking in that .o file for > some reason.raw_os_ostream is definitely linked into Debug/lib/libLLVMSupport.a in my LLVM build. (Confirmed with otool.) I'm using the 2.7 release branch from a couple weeks ago. Just for kicks, I added some code to my pass that creates a circular_raw_ostream object, and it runs without errors. I wonder what's different about raw_os_ostream... Any other possibilities? Trevor
Possibly Parallel Threads
- [LLVMdev] raw_os_ostream: symbol not found
- [LLVMdev] raw_os_ostream: symbol not found
- [LLVMdev] Use printing methods of third-party libraries that use std::ostream
- [LLVMdev] Use printing methods of third-party libraries that use std::ostream
- [LLVMdev] [PATCH] Circular Buffered Debug Stream