_declspec( dllimport )跟_declspec( dllexport )
__declspec( dllimport )和__declspec( dllexport )
别人写的一个String类,我在我的项目中引用这个头文件,debug 模式下,弹出 应用程序配置不正确,调了很久,没点思路,哪位大侠遇到过这样的问题!万分感谢
------解决方案--------------------
可能你没加库吧,
------解决方案--------------------
The dllexport and dllimport storage-class attributes are Microsoft-specific extensions to the C and C++ languages. They enable you to export and import functions, data, and objects to and from a DLL. These attributes explicitly define the DLL’s interface to its client, which can be the executable file or another DLL. Declaring functions as dllexport eliminates the need for a module-definition (.DEF) file, at least with respect to the specification of exported functions. Note that dllexport replaces the __export keyword.
你这个是用别人的,应该是将其作为输入库开看待,应该让__declspec( dllimport ) 起作用,(那个宏也定义的怪别扭的了)
------解决方案--------------------
加载库用,
你怎么加载的?
------解决方案--------------------
很明显调用不一致,txt打开.lib文件看看
------解决方案--------------------
最好的办法是 拿源码到工程中编译
再其次编译成静态库,静态库编译选项同exe。
只能用dll的话,那就将dll和exe的 运行库选项都该为动态连接。(不一定解决问题)
------解决方案--------------------
我猜别人的工程里面肯定是这样写的
#define XXXXXCore_EXPORTS;
#if defined XXXXXCore_EXPORTS
# define _XXXXXCoreExport __declspec( dllexport )
#else
# define _XXXXXXCoreExport __declspec( dllimport )
#endif
这样的话在他工程里面 _XXXXXCoreExport 实际上就是 __declspec( dllexport )
而 你工程中不会定义 XXXXXCore_EXPORTS的 所以你直接拿来用就行了 别做什么define定义 因为你没有定义XXXXXCore_EXPORTS, 那么预编译的时候 _XXXXXXCoreExport就是__declspec( dllimport )这个, 表示导入了
别人写的一个String类,我在我的项目中引用这个头文件,debug 模式下,弹出 应用程序配置不正确,调了很久,没点思路,哪位大侠遇到过这样的问题!万分感谢
#ifndef __String_h__
#define __String_h__
#include "XXXXXExport.h"
#include "XXXXXHeader.h"
namespace XXXXXCore
{
class String;
typedef std::list<String> StringList;
typedef StringList::iterator StringListIter;
typedef std::vector<String> StringVector;
typedef StringVector::iterator StringVectorIter;
typedef std::map<String,String> MapString;
typedef MapString::iterator MapStringIter;
class _XXXXXXExport String
{
public:
String(){}
String(std::string str):m_str(str){}
String(char * str):m_str(str){}
String(const char * str):m_str(str){}
String(const String &str):m_str(str.m_str){}
virtual ~String(){}
std::string str()const{ return m_str;}
bool empty()const{ return m_str.empty();}
long size(){ return m_str.size();}
std::string &str_ref(){ return m_str;}
void to_upper(){ boost::algorithm::to_upper(m_str);}
void to_lower(){ boost::algorithm::to_lower(m_str);}
void trim(){ boost::algorithm::trim(m_str);}
bool starts_with(const String &value){ return boost::algorithm::starts_with(m_str,value.m_str);}
bool ends_with(const String &value){ return boost::algorithm::ends_with(m_str,value.m_str);}
bool equals(const String &value){ return boost::algorithm::equals(m_str,value.m_str);}
StringVector split(String &separator);
bool contains(const String &value){ return boost::contains(m_str,value.m_str);}
bool operator==(const String &value)const { return value.m_str == m_str;}
bool operator!=(const String &value)const { return value.m_str != m_str;}
String operator+(const String &value)const { std::string temp = m_str; temp+= value.m_str;return temp;}
String &operator+=(const String &value){ m_str += value.m_str;return *this;}
bool operator<(const String &value)const { return m_str < value.m_str;}
protected:
std::string m_str;
};
static const String BLANK;
}
#endif
#ifndef __XXXXXXExport_h__
#define __XXXXXXExport_h__
#include "XXXXXHeader.h"
#if defined XXXXXCore_EXPORTS
# define _XXXXXCoreExport __declspec( dllexport )
#else
# define _XXXXXXCoreExport __declspec( dllimport )
#endif
class _XXXXXExport boost::noncopyable_::noncopyable;
#endif
------解决方案--------------------
可能你没加库吧,
------解决方案--------------------
The dllexport and dllimport storage-class attributes are Microsoft-specific extensions to the C and C++ languages. They enable you to export and import functions, data, and objects to and from a DLL. These attributes explicitly define the DLL’s interface to its client, which can be the executable file or another DLL. Declaring functions as dllexport eliminates the need for a module-definition (.DEF) file, at least with respect to the specification of exported functions. Note that dllexport replaces the __export keyword.
你这个是用别人的,应该是将其作为输入库开看待,应该让__declspec( dllimport ) 起作用,(那个宏也定义的怪别扭的了)
------解决方案--------------------
加载库用,
你怎么加载的?
------解决方案--------------------
很明显调用不一致,txt打开.lib文件看看
------解决方案--------------------
最好的办法是 拿源码到工程中编译
再其次编译成静态库,静态库编译选项同exe。
只能用dll的话,那就将dll和exe的 运行库选项都该为动态连接。(不一定解决问题)
------解决方案--------------------
我猜别人的工程里面肯定是这样写的
#define XXXXXCore_EXPORTS;
#if defined XXXXXCore_EXPORTS
# define _XXXXXCoreExport __declspec( dllexport )
#else
# define _XXXXXXCoreExport __declspec( dllimport )
#endif
这样的话在他工程里面 _XXXXXCoreExport 实际上就是 __declspec( dllexport )
而 你工程中不会定义 XXXXXCore_EXPORTS的 所以你直接拿来用就行了 别做什么define定义 因为你没有定义XXXXXCore_EXPORTS, 那么预编译的时候 _XXXXXXCoreExport就是__declspec( dllimport )这个, 表示导入了