I've tested the following code in a console application, and it compiles just fine. However, when I copy it to a header to include in a larger project, I get 77 link errors, all related to boost.

If I comment out the line in red, everything compiles just fine without any errors.

#include <iostream>
#include <fstream>

// include headers that implement a archive in simple text format
#include <boost/regex.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>

	class LinRegData
	{
		friend class boost::serialization::access;
		// When the class Archive corresponds to an output archive, the
		// & operator is defined similar to <<.  Likewise, when the class Archive
		// is a type of input archive the & operator is defined similar to >>.
		template<class Archive>
		void serialize(Archive & ar, const unsigned int version)
		{
			ar & BofVC;
		}
	public:
		LinRegData(){}
		~LinRegData(){}

		double BofVC;

		void PrintSelf()
		{
			// create and open a character archive for output
			std::ofstream ofs("C:\\Users\\J\\Documents\\notes\\TradeParams.dat");

			// save data to archive
			{
				boost::archive::text_oarchive oa(ofs);
				// write class instance to archive
				oa << *this;
				// archive and stream closed when destructors are called
			}
		}
	};

In both projects I have entered the boost directory under "Addition Include Directories" and added the boost library folder under "Additional Library Directories."

Any help would be greatly appreciated. I don't really know where to start.

The first of 77 errors reads " error LNK2019: unresolved external symbol "protected: __cdecl boost::archive::detail::basic_oserializer::basic_oserializer(class boost::serialization::extended_type_info const &)" (??0basic_oserializer@detail@archive@boost@@IEAA@AEBVextended_type_info@serialization@3@@Z) referenced in function "public: __cdecl boost::archive::detail::oserializer<class boost::archive::text_oarchive,class Params::LinRegData>::oserializer<class boost::archive::text_oarchive,class Params::LinRegData>(void)" (??0?$oserializer@Vtext_oarchive@archive@boost@@VLinRegData@Params@@@detail@archive@boost@@QEAA@XZ)"

Recommended Answers

All 3 Replies

add the serialization library to the linking, directly. Not just under library directories, but also as a library to be linked. Find the boost_serialization library (either libboost_serialization_..a or boost_serialization...lib).

Boost has some automatic linking of some required libraries, but this system only works for some compilers (e.g. MSVC) but not for others (e.g. GCC). So, the code might automatically get the required library when compiled under one compiler, but it will not do that on another, in which case you have specify, manually, the libraries to be linked, this is the case for GCC (including MinGW/Cygwin).

When asking such a question, you should always specify the operating system, the compiler, and the build system (IDE), and any relevant compilation options.

Right. I knew to list that information. Sorry. I'm using Win7, VS2010, cl.exe. I'm working entirely from the IDE.

As far as I know I can only link to a library directory from VS as opposed to the actual library file (I just tried to do so).

I realize this isn't a c++ specific question as it involves the IDE / compiler, but thank you for any help you can offer.

Not to sound counter-productive but there is an installer available for boost, if you're using Windows I would say it's definitely worth checking out. It takes a long time to download the files but, you get the pre-built .DLLs and .LIBs for multiple compilers, target platforms, and runtimes.

After you install it, (it installs to program files folder by default) you just add:
project-> include directory "C:\Program Files (x86)\boost\boost_1_47"
lib directory "C:\Program Files (x86)\boost\boost_1_47\lib"

and then it probably statically links by default, and normally when I want to dynamically link I define the proper macro like: #define BOOST_THREAD_USE_DLL https://svn.boost.org/trac/boost/ticket/4921
Or In the header file: <boost/config/user.hpp> #define BOOST_ALL_DYN_LINK here's the installer link:
http://www.boostpro.com/download/

Overall I have found this way of obtaining and using the boost library to be by far the best.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.