Boost Unit Testing Macros on Visual Studio 2005/Visual C++ 8.0

I'm reading this article (http://www.ibm.com/developerworks/aix/library/au-ctools1_boost/?S_TACT=105AGY20&S_CMP=HP) on the Boost Unit Testing Framework. However I'm having a bit of trouble with the first example, my guess is that they left something out (something that would be obvious to hardcore C++ coders) as IBM often does in their articles. Another possibility is that my Visual Studio 2005 C++ compiler is just too old for the example. #define _MYSTRING #define BOOST_TEST_MODULE stringtest #include <boost/test/unit_test.hpp> #include "stdafx.h" //#include "mystring.h" BOOST_AUTO_TEST_SUITE (stringtest) // name of the test suite is stringtest BOOST_AUTO_TEST_CASE (test1) { /* mystring s; BOOST_CHECK(s.size() == 0); */ BOOST_CHECK(0 == 0); } BOOST_AUTO_TEST_CASE(test2) { /* mystring s; s.setbuffer("hello world"); BOOST_REQUIRE_EQUAL('h', s[0]); // basic test */ BOOST_CHECK(0 == 0); } BOOST_AUTO_TEST_SUITE_END( ) To me the BOOST_AUTO_TEST_SUITE and BOOST_AUTO_TEST_CASE lines look a little suspect (especially since they don't have quotes around the arguments, and they are undeclared identifiers...but this probably means they are macros and I'm not certain I understand the concept or if that is available in VC++ 8.0)... Is there any reason why this code won't work? Bellow are the errors I'm receiving: 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(7) : error C2065: 'stringtest' : undeclared identifier 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C2146: syntax error : missing ';' before identifier 'BOOST_AUTO_TEST_CASE' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C2065: 'test1' : undeclared identifier 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(10) : error C2448: 'BOOST_AUTO_TEST_CASE' : function-style initializer appears to be a function definition 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(18) : error C2065: 'test2' : undeclared identifier 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(19) : error C2448: 'BOOST_AUTO_TEST_CASE' : function-style initializer appears to be a function definition 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(29) : fatal error C1004: unexpected end-of-file found

AMDG Andrew Leer wrote:
I'm reading this article (http://www.ibm.com/developerworks/aix/library/au-ctools1_boost/?S_TACT=105AGY20&S_CMP=HP) on the Boost Unit Testing Framework.
However I'm having a bit of trouble with the first example, my guess is that they left something out (something that would be obvious to hardcore C++ coders) as IBM often does in their articles. Another possibility is that my Visual Studio 2005 C++ compiler is just too old for the example.
This should work with recent versions of Boost. However, with older versions you may need #include <boost/test/test_tools.hpp>
#define _MYSTRING #define BOOST_TEST_MODULE stringtest #include <boost/test/unit_test.hpp> #include "stdafx.h" //#include "mystring.h"
BOOST_AUTO_TEST_SUITE (stringtest) // name of the test suite is stringtest
In Christ, Steven Watanabe

AMDG Gennadiy Rozental wrote:
Andrew Leer <leeand00 <at> gmail.com> writes:
BOOST_AUTO_TEST_SUITE (stringtest) // name of the test suite is stringtest
There should not be space between macro name and (.
Whitespace doesn't matter. It's only required that the preprocessing token after the macro name be a (. In Christ Steven Watanabe

I received another reply on this, but it still doesn't completely fix the error http://stackoverflow.com/questions/1876444/boost-unit-testing-and-visual-stu... I didn't know this but you have to have #include "stdafx.h" as the first line in the file. Now I'm getting another error however... 1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc80-mt-gd-1_40.lib' I really don't understand the error however because I have the aforementioned file in my C:\Program Files (x86)\boost\boost_1_40\lib directory (unless this warrants including it in the build somehow (...I have a java background...I'm a bit new to professional C++ that uses libraries...) Thanks, Andrew On Wed, Dec 9, 2009 at 5:04 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Gennadiy Rozental wrote:
Andrew Leer <leeand00 <at> gmail.com> writes:
BOOST_AUTO_TEST_SUITE (stringtest) // name of the test suite is stringtest
There should not be space between macro name and (.
Whitespace doesn't matter. It's only required that the preprocessing token after the macro name be a (.
In Christ Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Okay figured it out, went to this post: http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-... And added the library. Thank you, Andrew On Wed, Dec 9, 2009 at 5:36 PM, Andrew J. Leer <leeand00@hotmail.com> wrote:
I received another reply on this, but it still doesn't completely fix the error
http://stackoverflow.com/questions/1876444/boost-unit-testing-and-visual-stu...
I didn't know this but you have to have #include "stdafx.h" as the first line in the file.
Now I'm getting another error however...
1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc80-mt-gd-1_40.lib'
I really don't understand the error however because I have the aforementioned file in my C:\Program Files (x86)\boost\boost_1_40\lib directory (unless this warrants including it in the build somehow (...I have a java background...I'm a bit new to professional C++ that uses libraries...)
Thanks, Andrew
On Wed, Dec 9, 2009 at 5:04 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Gennadiy Rozental wrote:
Andrew Leer <leeand00 <at> gmail.com> writes:
BOOST_AUTO_TEST_SUITE (stringtest) // name of the test suite is stringtest
There should not be space between macro name and (.
Whitespace doesn't matter. It's only required that the preprocessing token after the macro name be a (.
In Christ Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Andrew J. Leer wrote:
Okay figured it out, went to this post:
http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-...
And added the library.
You should just let auto-linking do it's job. In Christ, Steven Watanabe

Eh, What's auto linking? :-D Andrew On Wed, Dec 9, 2009 at 5:48 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Andrew J. Leer wrote:
Okay figured it out, went to this post:
http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-...
And added the library.
You should just let auto-linking do it's job.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

no seriously, I don't know what that is... On Wed, Dec 9, 2009 at 5:50 PM, Andrew J. Leer <leeand00@hotmail.com> wrote:
Eh,
What's auto linking?
:-D
Andrew
On Wed, Dec 9, 2009 at 5:48 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Andrew J. Leer wrote:
Okay figured it out, went to this post:
http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-...
And added the library.
You should just let auto-linking do it's job.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Andrew J. Leer wrote:
Eh,
What's auto linking?
Notice your original error: 1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc80-mt-gd-1_40.lib' The Boost.Test library has already told the compiler that it needs this library. You just need to add the directory containing it to the linker's search path. In Christ, Steven Watanabe

Right. I added it using the selected answer here: http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-... However...I wasn't entirely sure if what I was doing was the autolinking that you spoke of, and that sir it what I wanted to ask you about. Thanks again Steve, Andrew J. Leer On Wed, Dec 9, 2009 at 5:57 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Andrew J. Leer wrote:
Eh,
What's auto linking?
Notice your original error:
1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc80-mt-gd-1_40.lib'
The Boost.Test library has already told the compiler that it needs this library. You just need to add the directory containing it to the linker's search path.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Andrew J. Leer wrote:
Right. I added it using the selected answer here:
http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-...
However...I wasn't entirely sure if what I was doing was the autolinking that you spoke of, and that sir it what I wanted to ask you about.
As far as I can tell, none of the answers there use auto-linking. If you have to specify libboost_unit_test_framework-vc80-... anywhere you aren't using autolinking. If you modify the library path in (Tools->Options->Projects and Solutions->VC++ directories) then linking should just work for any Boost library with any build settings. In Christ, Steven Watanabe

MSVC has a pragma-statement which causes the linker to atomatically link the lib. Boost Test (as well as other boost libs, which are not only header based) make use of this feature. Dependent on retrieved compiler settings they calculate the name of the library to be linked and pass it to the pragma-statement smth. like: #pragma comment(lib, "lib-boost-test-whatever") This causes the linker to atomatically link that library, the only prerequisite is that it needs to find the path, where this lib can be located. That's why you need to set Library Search Directory for VC. Additioanlly, you can set this path globally in VC or locally only project based. I usually do it locally and use the BOOST_ROOT environment variable. That allows me to change the envvar and switch the path without changing the VC project file (which might be under source control). Regards, Ovanes On Thu, Dec 10, 2009 at 2:44 PM, Andrew J. Leer <leeand00@hotmail.com>wrote:
Right. I added it using the selected answer here:
http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-...
However...I wasn't entirely sure if what I was doing was the autolinking that you spoke of, and that sir it what I wanted to ask you about.
Thanks again Steve, Andrew J. Leer
On Wed, Dec 9, 2009 at 5:57 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Andrew J. Leer wrote:
Eh,
What's auto linking?
Notice your original error:
1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc80-mt-gd-1_40.lib'
The Boost.Test library has already told the compiler that it needs this library. You just need to add the directory containing it to the linker's search path.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Andrew J. Leer wrote:
I received another reply on this, but it still doesn't completely fix the error
http://stackoverflow.com/questions/1876444/boost-unit-testing-and-visual-stu...
I didn't know this but you have to have #include "stdafx.h" as the first line in the file.
Now I'm getting another error however...
1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc80-mt-gd-1_40.lib'
I really don't understand the error however because I have the aforementioned file in my C:\Program Files (x86)\boost\boost_1_40\lib directory (unless this warrants including it in the build somehow (...I have a java background...I'm a bit new to professional C++ that uses libraries...)
You need to add the directory to your linker path. (Tools->Options->Projects and Solutions->VC++ directories) In Christ, Steven Watanabe
participants (5)
-
Andrew J. Leer
-
Andrew Leer
-
Gennadiy Rozental
-
Ovanes Markarian
-
Steven Watanabe