I'm trying to compile the program on 6.06 ubuntu, cppunit-1.12.0. I'm getting this error message:
/usr/local/include/cppunit/TestResult.h:118: error: invalid use of undefined type ‘struct std::string’
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stringfwd.h:56: error: declaration of ‘struct std::string’
What can this be?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What program are you trying to compile? Are you just installing cppunit or have you written a test suite that you are compiling? If the later, please provide some source code. Also, what is the command you are using to compile?
Layne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Every *.cc file compiles, with the code g++ -g -c filename.cc. Then I try to compile all of them with this code: "g++ -I/usr/local/include -l cppunit <list of .cc files> -ldl". I have also added this line into .bash_pfoile: export LD_LIBRARY_PATH=:/usr/local/lib:". I am rthinking it's either this line that's incorrect, or I have messed up the installation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't understand why you are getting this error and I am not currently at a computer where I can test it out. I still have one suggestion: learn to use make. This is a command-line tool that typically comes with most versions of Unix and Linux. It helps to manage compiling and linking your code when you have multiple .cpp and .h files. You create a makefile that describes how to compile each individual .cpp file and how to create a final executable. There is plenty of information on the web and you can look at the man pages on your system for help as well.
In the meantime, I'll see if I can recreate your error messages when I am on a machine where I can compile your code.
Layne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to compile the program on 6.06 ubuntu, cppunit-1.12.0. I'm getting this error message:
/usr/local/include/cppunit/TestResult.h:118: error: invalid use of undefined type ‘struct std::string’
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stringfwd.h:56: error: declaration of ‘struct std::string’
What can this be?
What program are you trying to compile? Are you just installing cppunit or have you written a test suite that you are compiling? If the later, please provide some source code. Also, what is the command you are using to compile?
Layne
I have written a test suite. Here are the codes that I'm trying to compile:
//*****Course.h*******//
#ifndef COURSE_H
#define COURSE_H
#include <string>
using namespace std;
class Course {
private:
string title;
int enrollment;
string courseNumber;
public:
void readTitle();
void readEnrollment();
void readCourseNumber();
void setTitle( string );
void setEnrollment( int );
void setCourseNumber( string );
string getTitle();
int getEnrollment();
string getCourseNumber();
void printData();
};
#endif
//*******************************//
//********Course.cc*************//
#include <iostream>
#include <string>
using namespace std;
#include "Course.h"
void Course::readTitle() {
string temp;
getline( cin, temp );
setTitle( temp );
}
void Course::readEnrollment() {
int foo;
cin >> foo;
setEnrollment( foo );
}
void Course::readCourseNumber() {
string temp;
getline( cin, temp );
setCourseNumber( temp );
}
void Course::setTitle( string x ) {
title = x;
}
void Course::setEnrollment( int i ) {
enrollment = i;
}
void Course::setCourseNumber( string x ) {
courseNumber = x;
}
string Course::getTitle() {
return title;
}
int Course::getEnrollment() {
return enrollment;
}
string Course::getCourseNumber() {
return courseNumber;
}
void Course::printData() {
cout << "Not yet implemented" << endl;
}
//***********************************************//
//**********CourseTest.h************************//
#ifndef COURSETEST_H
#define COURSETEST_H
using namespace std;
#include <cppunit/extensions/HelperMacros.h>
#include <string>
#include "Course.h"
class CourseTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( CourseTest );
CPPUNIT_TEST( testSetTitle );
CPPUNIT_TEST( testSetTitle2 );
CPPUNIT_TEST_SUITE_END();
private:
Course *c1;
string title;
protected:
public:
void setUp() {
c1 = new Course();
title = "This is a multi-word title"; }
void tearDown() {
delete c1;
}
void testSetTitle() {
c1->setTitle( title );
CPPUNIT_ASSERT( title == c1->getTitle() );
}
void testSetTitle2() {
c1->setTitle( title );
CPPUNIT_ASSERT( title == "should fail" );
}
};
#endif
//***************************************************//
//*********************TestMain.cc*******************//
#include "cppunit/TextTestResult.h"
#include "cppunit/TestSuite.h"
#include <iostream>
using namespace std;
#include "CourseTest.h"
int main( int argc, char* argv[] ) {
CppUnit::TestSuite suite;
suite.addTest( CourseTest::suite() );
CppUnit::TextTestResult res;
suite.run( &res );
cout << res << std::endl;
return 0;
}
//*********************************************//
Every *.cc file compiles, with the code g++ -g -c filename.cc. Then I try to compile all of them with this code: "g++ -I/usr/local/include -l cppunit <list of .cc files> -ldl". I have also added this line into .bash_pfoile: export LD_LIBRARY_PATH=:/usr/local/lib:". I am rthinking it's either this line that's incorrect, or I have messed up the installation.
I don't understand why you are getting this error and I am not currently at a computer where I can test it out. I still have one suggestion: learn to use make. This is a command-line tool that typically comes with most versions of Unix and Linux. It helps to manage compiling and linking your code when you have multiple .cpp and .h files. You create a makefile that describes how to compile each individual .cpp file and how to create a final executable. There is plenty of information on the web and you can look at the man pages on your system for help as well.
In the meantime, I'll see if I can recreate your error messages when I am on a machine where I can compile your code.
Layne