- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
We got this error if we use the (small) Newlib C library: -- start -- Error pure.o * In function `__cxa_pure_virtual': undefined reference to `fwrite' pact_sb line 0 -- end FYI: we do remove/comment all printf statements How can we get rid of this error? Any one helps? Regards, Kwok WongLink Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by kwokwong@Dec 29 2004, 10:51 AM hi all,
we got this error if we use the (small) newlib c library:
-- start --
error pure.o * in function `__cxa_pure_virtual': undefined reference to `fwrite' pact_sb line 0
-- end
fyi: we do remove/comment all printf statements
how can we get rid of this error?
any one helps?
regards,
kwok wong --- Quote End --- The reference is made in the file pure.cc: --start --# ifdef _GLIBCPP_HAVE_UNISTD_H# include <unistd.h># define writestr(str) write(2, str, sizeof(str) - 1)# ifdef __GNU_LIBRARY__ /* Avoid forcing the library's meaning of `write' on the user program by using the "internal" name (for use within the library). */ /*# define write(fd, buf, n) __write((fd), (buf), (n))*/# endif# else# include <cstdio># define writestr(str) std::fputs(str, stderr)# endif extern "C" void __cxa_pure_virtual (void) { writestr ("pure virtual method called\n"); std::terminate (); } -- end Who can tell what this funtions does and/or which ohter (libray) funtion requires this functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The function __cxa_pure_virtual() is a placeholder function inserted automatically by the compiler. It is used whenever you declare a pure virtual function in a base class (that is, a function that won't have an implementation provided:
class an_abstract_base_class
{
virtual void do_something() = 0;
}
Since you can't create instances of an_abstract_base_class, you shouldn't be able to call the non-existant function an_abstract_base_class::do_something(). The compiler still needs to create a vtable (virtual function dispatch table) for abstract classes (those with one or more pure virutal methods like an_abstract_base_class), so it has to put something in the vtable entries corresponding to pure virtual functions: it uses __cxa_pure_virtual(). In properly written code __cxa_pure_virtual() should never get called. If it does somehow get called it's a signal that something has gone seriously wrong with your code. So, to eliminate the undefined reference error you have two choices: Either remove all pure virtual functions from you project, or provide your own version of __cxa_pure_virtual() that doesn't use facilities which aren't available on your hardware platform (e.g. just go into an infinite loop flashing an LED).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply.
I'll look for all unimplemented pure virtual methods.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page