It is a bit complex to know how to install CppUnit and how to use it with Eclipse.
That's why I make this tutorial about CppUnit and Eclipse.
I hope it will be easy enough even for beginners, if not, do not hesitate to post a comment, I will help if I can.
This installation will be done on Windows OS, I am sure if you are a Linux addict or a Mac fan, this explanation will help you as well.
Of course, we need the source of the CppUnit framework.
No problem there, take it up from the official host website:
http://sourceforge.net/projects/cppunit/files/cppunit/
So extract all the files on the directory of your choice, for example, I will put them in this one:
C:\soft\libraries\cppunit-1.12.1
We need now to configure the framework.
At this point, you need at least a GNU tool for Windows, such as MinGW. If you don't have it, check on my website, and follow instructions.
If you installed MinGW without Make, you should also need the MSys, a brother of MinGW.
MSys contains the GNU Make tool.
So, open MinGW and go until the directory where you put CppUnit, in our case:
C:\soft\libraries\cppunit-1.12.1
Execute the following command:
./configure
Once it done, execute this second one:
make
To finish execute this last one:
make install
Don't be afraid, it may take at least 10 minutes for the 3 commands to be performed.
OK, if you don't have any error, CppUnit is now configured for your system.
That's a great step.
Open Eclipse then create a new C++ Project.
The Project name is MyCppUnitStaticLibrary, its type is an empty Static Library, and the Toolchain is MinGW GCC.
For example File > New > C++ Project > Static Library > Empty Project > MinGW GCC > Finish.
Really basic.
Open this project and create a new folder inside, such as myimports.
Right click this new folder and select Import > General > File System > Next.
In the From directory input, click Browse and enter the directory where you put the CppUnit source, in our case: C:\soft\libraries\cppunit-1.12.1\src\cppunit.
Click Select All > Finish.
It will import all files from src/cppunit into myimports.
OK, let's continue by right clicking the project then > Properties > C/C++ Build > Settings >Tool Settings > GCC C++ Compiler > Includes.
Click Add... on the right (a tiny icon with a green plus) to add a directory path.
In our case it will be: C:\soft\libraries\cppunit-1.12.1\include.
Click OK > OK.
Our project library is now ready to be built.
So let's do it.
Right click the project then > Build Project.
A new lib has been created in the Debug folder: libMyCppUnitStaticLibrary.a.
Let's continue.
Create a new C++ Project named MyNewProject.
File > New > C++ Project > Executable > Empty Project > MinGW GCC > Finish.
Right click MyNewProject > Properties > C++ Build > Settings > Tool Settings > GCC C++ Compiler > Includes.
On the right, click the tiny green icon on the Include paths (-I) panel and add this:
C:\soft\libraries\cppunit-1.12.1\include.
Click OK.
Let's continue.
MyNewProject > Properties > C++ Build > Settings > Tool Settings > MinGW C++ Linker > Libraries.
On the right there are two panes.
On the first, at top, Libraries (-l), click the green plus icon and add this: MyCppUnitStaticLibrary.
Indeed, in C++ we must not use the prefix lib and the .a extension.
The main reason is that the linker doesn't accept it.
In the second pane, at bottom, Library search path (-L), let's enter in which directory this lib is.
So let's add it, in my case it is: C:\dev\cpp\MyCppUnitStaticLibrary\Debug.
Click OK.
Here we are, let's test it!
In the cppunit sources that you have installed, there is a folder named examples:
C:\soft\libraries\cppunit-1.12.1\examples.
Open it and copy paste the money folder into your MyNewProject.
Build this project (rigth click > Build Project).
Once it done, right click again this project > Run As > Local C/C++ Application.
In the console we can see four full stops (....) with an OK and (4).
Just like that:
.... OK (4)
It means that your installation of CppUnit with Eclipse on Windows is completed!
You are now ready to use it.
Well done you've made it!
Comments
Anonymous (not verified)
Friday, February 24, 2012 - 6:20pm
Permalink
Thanks for the installation
Thanks for the installation tutorial.
It helps a lot.
I used Cygwin. The only difference for using cygwin is that you must use relative directory instead of absolute directory. "C:\dev\...." . need delete "C:\"
Mi-K
Friday, February 24, 2012 - 6:24pm
Permalink
Thank you for the Cygwin way.
Thank you for the Cygwin way of using Eclipse and CppUnit.
Jon (not verified)
Wednesday, March 14, 2012 - 5:52pm
Permalink
After building the project, I
After building the project, I get varoius errors complaining that it can't find certain header files:
../myimports/src/qttestrunner/MostRecentTests.h:10:21: warning: qstring.h: No such file or directory
Has anyone else come across these, or got a solution to it?
It would be much appreciated! This tutorial is great by the way.
Cheers
Anynomous (not verified)
Wednesday, March 18, 2015 - 8:58am
Permalink
'src/cppunit' not 'src'
'src/cppunit' not 'src'
drago (not verified)
Tuesday, September 25, 2012 - 6:52pm
Permalink
Thanks for the great
Thanks for the great explanation! I installed all from scratch, run it and with no mistakes! Great tutorial
jos77 (not verified)
Friday, December 21, 2012 - 9:08am
Permalink
Thank you very much.
Thank you very much.
It was hard when installing cppunit with MSYS , there was message " No rule to make targe '../../config/ac_create_prefix_config_h.m4' ..." , just problem of correct cppunit download.
Now money examples is ok. I should go next step, thanks again
Thank you very much (not verified)
Tuesday, January 8, 2013 - 1:10pm
Permalink
I suceeded thanks to your
I suceeded thanks to your tutorial. I'm greatful.
Nevertheless I've got some error messages when I ran the command "make" and the command 'make install".
Error message: 'failcom' isn't recognized as an internal command
'failcom' appears in the Makefile.
Despite that, I've got the right message on Eclipse, so it seems like it's working !
swalli (not verified)
Tuesday, October 20, 2015 - 9:32pm
Permalink
Thanks a bunch for the
Thanks a bunch for the tutorial! Most Helpful!
I installed using cygwin also and it worked great... until I got to the money example.
Upon building the example, I get an error in the makefile (pasted below). Has anyone else seen this?
Thanks!
Building target: MyNewProject.exe
Invoking: Cygwin C++ Linker
g++ -L"C:\Data\Projects\MyCppUnitStaticLibrary\Debug" -o "MyNewProject.exe" ./money/MoneyApp.o ./money/MoneyTest.o ./money/StdAfx.o -lMyCppUnitStaticLibrary.a
/usr/lib/gcc/i686-pc-cygwin/4.9.3/../../../../i686-pc-cygwin/bin/ld: cannot find -lMyCppUnitStaticLibrary.a
collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'MyNewProject.exe' failed
make: *** [MyNewProject.exe] Error 1
arlong (not verified)
Wednesday, December 30, 2015 - 7:55pm
Permalink
This is a great tutorial to
This is a great tutorial to start..
i followed each step, but after building the project
certain errors came like this
---undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'-----------
please help me to rectify and build the project
adem (not verified)
Saturday, July 29, 2017 - 11:24pm
Permalink
Thank you very much. This
Thank you very much. This post is very useful for me to execute cppunit.
Pravin Holkar (not verified)
Thursday, August 10, 2017 - 9:20am
Permalink
Thanks you very much.
Thanks you very much.
How I can build cppunit source in Linux on Eclipse.
Chris (not verified)
Thursday, August 24, 2017 - 7:20am
Permalink
I also want to thank you very
I also want to thank you very much. It took some time but now it should work :-)
To those guys that had the Problem with "cannot find -lMyCppUnitStaticLibrary.a" (I know it was 2015 but I had the same Problem). Make sure that the Project type of "MyCppUnitStaticLibrary" is an empty Static Library! (the very beginning of Step B). That was the mistake I did several times and wondered why libMyCppUnitStaticLibrary.a was not created. So best regards
Add new comment