Archived

This topic is now archived and is closed to further replies.

wah_on_2

what the warning mean?

Recommended Posts

Hi, i am writing utilities, but the compile produced warnings when i compile the following code. What does it mean? Why it occur? And how can i solve it? Thx a lot of. ------ Rebuild All started: Project: Utility, Configuration: Debug Win32 ------ Deleting intermediate files and output files for project ''Utility'', configuration ''Debug|Win32''. Compiling... Utility.cpp Exception.cpp h:\LongRunner\C++\Utility\Exception.h(14) : warning C4251: ''LongRunner::Utility::CException::m_ClassName'' : class ''std::basic_string<_Elem,_Traits,_Ax>'' needs to have dll-interface to be used by clients of class ''LongRunner::Utility::CException'' with [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ] h:\LongRunner\C++\Utility\Exception.h(15) : warning C4251: ''LongRunner::Utility::CException::m_MethodName'' : class ''std::basic_string<_Elem,_Traits,_Ax>'' needs to have dll-interface to be used by clients of class ''LongRunner::Utility::CException'' with [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ] h:\LongRunner\C++\Utility\Exception.h(16) : warning C4251: ''LongRunner::Utility::CException::m_Message'' : class ''std::basic_string<_Elem,_Traits,_Ax>'' needs to have dll-interface to be used by clients of class ''LongRunner::Utility::CException'' with [ _Elem=char, _Traits=std::char_traits, _Ax=std::allocator ] Generating Code... Linking... Creating library Debug/Utility.lib and object Debug/Utility.exp Build log was saved at "file://h:\LongRunner\C++\Utility\Debug\BuildLog.htm" Utility - 0 error(s), 3 warning(s) ---------------------- Done ---------------------- Rebuild All: 1 succeeded, 0 failed, 0 skipped
//UtilityStdhdr.h


#ifndef _Utilitystdhdr_H_
#define _Utilitystdhdr_H_

#include<string>
#include<vector>

namespace LongRunner
{
namespace Utility
{
#define DllExport __declspec(dllexport)
using namespace std;
}
}
#endif



//Exception.h


#ifndef _Exception_H_
#define _Exception_H_

#include "Utilitystdhdr.h"

namespace Longrunner
{
namespace Utility
{
	class DllExport CException
	{
	//data members

	protected:
		string  m_ClassName;
		string  m_MethodName;
		string	m_Message;


	//methods

	public:
		CException(const char *className, const char *methodName, const char *message);
		virtual ~CException(void);

		//property

		inline const char *ClassName(){		return m_ClassName.c_str();		};
		inline const char *MethodName(){	return m_MethodName.c_str();	};
		inline const char *Message(){		return m_Message.c_str();		};
		};
}
}
#endif

Share this post


Link to post
Share on other sites
if you have:


class NoDllInterface
{
...
};

__declspec(dllexport) class ExportedClass
{
NoDllInterface InstanceOfClass; // warning !!

}


The warning says that you export a class that has no DLL interface (the class itself is not exported). The following code solves this problem:


__declspec(dllexport) class DllInterface
{
...
};

__declspec(dllexport) class ExportedClass
{
DllInterface InstanceOfClass;
}

Share this post


Link to post
Share on other sites
Hi, I have question again.

I am confusing the output format of the utility classess.

I know i have 4 choices.
1: I just wrting the classes and if the other programs use the classes, just include the .cpp and .h files.
2: I write a static library and if the other program use the classes, just include the header file and link with the .lib
3: I create a dll file and export the function. If the other program use the classes, just use LoadLibrary() and GetProcAddres() to get the function pointer.
4: I create a dll file and if the other program use the classes, just include the header file and link with the lib. And run with the dll file.

However, i don''t know the benfits and the drawback of each one. (I just know i must re-compile the other programs when the utilities classes have small change(e.g. change variable name in a function) in the choice4 but choice3 need not.

Which one is better? Can explain its to me? Thx

Share this post


Link to post
Share on other sites