Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:15+00:00 2026-05-26T02:41:15+00:00

I am learning CppUnit, and my code coredumped when calling TestRunner::run(). That’s line 34

  • 0

I am learning CppUnit, and my code coredumped when calling TestRunner::run(). That’s line 34 in the below code. I can not see anything wrong. It is almost identical to the sample code in the CppUnit cookbook.

#include <iostream>  
#include <cppunit/TestCaller.h>  
#include <cppunit/TestSuite.h>  
#include <cppunit/ui/text/TestRunner.h>  
using namespace std;  

//class MyFixture: public CppUnit::TestFixture {  
class MyFixture{  
public:  
   MyFixture() {cout<<"MyFixture:: ctor()"<<endl;}  
   ~MyFixture() {cout<<"MyFixture:: dtor()"<<endl;}  
   void setUp() {cout<<"MyFixture::Setup()"<<endl;}  
   void tearDown() {cout<<"MyFixture::tearDown()"<<endl;}  
   void testFunc1() {cout<<"MyFixture::testFunc1()"<<endl; m=1; CPPUNIT_ASSERT(m==1);}  
   void testFunc2() {cout<<"MyFixture::testFunc2()"<<endl; m=2;}  
   int m;  
   static CppUnit::TestSuite * CreateSuite();  
};  

CppUnit::TestSuite * MyFixture::CreateSuite()  
{  
   CppUnit::TestSuite * suite = new CppUnit::TestSuite("My TestSuite for MyFixture");  
   suite->addTest(new CppUnit::TestCaller<MyFixture>("MyFixture::testFunc1", &MyFixture::testFunc1));  
   suite->addTest(new CppUnit::TestCaller<MyFixture>("MyFixture::testFunc2", &MyFixture::testFunc2));  
}  

int main()  
{  
   cout<<"point 1000"<<endl;  
   CppUnit::TextUi::TestRunner runner;  
   runner.addTest(MyFixture::CreateSuite());  
   cout<<"point 7000"<<endl;  
/*Line34*/   runner.run();  


   cout<<"point 8000"<<endl;  
}  

The output:

  cppunit$ ./test_runner   
  point 1000  
  MyFixture:: ctor()  
  MyFixture:: ctor()  
  point 7000  
  Segmentation fault (core dumped)  

The stack trace:

(gdb)bt  
-0  0x00733cc9 in CppUnit::TestRunner::WrappingSuite::run(CppUnit::TestResult*) ()  
   from /usr/lib/libcppunit-1.12.so.1  
-1  0x0073170a in CppUnit::TestResult::runTest(CppUnit::Test*) () from /usr/lib/libcppunit-1.12.so.1  
-2  0x00733af0 in CppUnit::TestRunner::run(CppUnit::TestResult&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/libcppunit-1.12.so.1  
-3  0x00736d2b in CppUnit::TextTestRunner::run(CppUnit::TestResult&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/libcppunit-1.12.so.1  
-4  0x00736da2 in CppUnit::TextTestRunner::run(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, bool, bool) () from /usr/lib/libcppunit-1.12.so.1  
-5  0x080494dd in main () at test_runner.cpp:34  

The compile line: g++ -g -o -Wall test_runner test_runner.cpp -lcppunit
It compile successfully without any warning.
If I turned on “-Wall”, it gave error:

......
(.data+0x4): multiple definition of `__dso_handle'  
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/crtbegin.o:(.data+0x0): first defined here  
test_runner: In function `_init':  
(.init+0x0): multiple definition of `_init'  
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crti.o:(.init+0x0): first defined here  
/tmp/ccgzqvu9.o: In function `MyFixture::CreateSuite()':  
/home/fzhao/temp/cppunit/test_runner.cpp:22: multiple definition of `MyFixture::CreateSuite()'  
test_runner:/home/fzhao/temp/cppunit/test_runner.cpp:22: first defined here  
/tmp/ccgzqvu9.o: In function `main':  
/home/fzhao/temp/cppunit/test_runner.cpp:29: multiple definition of `main'  
test_runner:/home/fzhao/temp/cppunit/test_runner.cpp:29: first defined here  
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'  
test_runner:(.dtors+0x4): first defined here  
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.  
/usr/bin/ld: error in test_runner(.eh_frame); no .eh_frame_hdr table will be created.  
collect2: ld returned 1 exit status  
make: *** [test_runner] Error 1  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:41:15+00:00Added an answer on May 26, 2026 at 2:41 am

    Given that the signature for the function is:

    CppUnit::TestSuite * MyFixture::CreateSuite()
    

    shouldn’t you be returning something (suite would be my first guess)?

    By not returning anything, the line:

    runner.addTest(MyFixture::CreateSuite());
    

    is going to add a very dodgy pointer to your runner.


    And the reason you’re probably getting those errors when you insert -Wall is because:

    g++ -g -o -Wall test_runner test_runner.cpp -lcppunit
           \______/ \___________________________________/
    

    will try to output your executable to the file -Wall by linking together test_runner, test_runner.cpp and the cppunit library. Perhaps you meant to type:

    g++ -g -Wall -o test_runner test_runner.cpp -lcppunit
                 \____________/ \_______________________/
    

    (I’m assuming here that the compile line you gave was the one where the errors occurred since it actually has -Wall in it ).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning GIT. I tried committing a group of files, below you can see where
learning about loops (still a beginner) in VB.net. I have got the below code
Learning Objective-C and reading sample code, I notice that objects are usually created using
Learning a lot in my few years of programming that the best projects are
Learning CasperJS Trying to understand why the following is not displaying my results in
Learning C++ and see the class laid out like this: class CRectangle { int
Learning java server technologies, trying to clarify some things. There are few technologies that
learning html/css here. I can't seem to understand how to tweak this drop down
After learning how to correctly unset a node , I noticed that using PHP's
For learning purposes, I'm looking for open source Rails projects that exemplify idiomatic usage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.