m***x 发帖数: 492 | 1 Using VS2010, a class can be exported from DLL. the client can access it
without problem. when put it into a namespace, the client program has link
error: unsolved external objs...
Any idea? thanks
the dll header file is:
#pragma once
#ifndef ECONOMICS_API_DCL
#ifdef ECONOMICS_EXPORTS
#define ECONOMICS_API_DCL __declspec(dllexport)
#else
#define ECONOMICS_API_DCL __declspec(dllimport)
#endif
#endif
namespace Economics
{
class ECONOMICS_API_DCL InterestRate
{
public:
InterestRate(void);
~InterestRate(void);
};
}
the client code is :
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
Economics::InterestRate mRate;
return 0;
}
error is:
Error 2 error LNK2019: unresolved external symbol "__declspec(
dllimport) public: __thiscall Economics::InterestRate::InterestRate(void)" (
__imp_??0InterestRate@Economics@@QAE@XZ) referenced in function _wmain E:
\Litn\VS2010\Financial Analystics\Test\Test.obj Test |
b***i 发帖数: 3043 | 2 #include "interestrate.h"
using namespace Economics;
设置你的include 路径,能够正确找到interestrate.h
【在 m***x 的大作中提到】 : Using VS2010, a class can be exported from DLL. the client can access it : without problem. when put it into a namespace, the client program has link : error: unsolved external objs... : Any idea? thanks : the dll header file is: : #pragma once : #ifndef ECONOMICS_API_DCL : #ifdef ECONOMICS_EXPORTS : #define ECONOMICS_API_DCL __declspec(dllexport) : #else
|
m***x 发帖数: 492 | 3 not this issue.
when add the project to the reference of client, there is no problem.
【在 b***i 的大作中提到】 : #include "interestrate.h" : using namespace Economics; : 设置你的include 路径,能够正确找到interestrate.h
|
b***i 发帖数: 3043 | 4 if you don't add the reference, you couldn't build even without using
namespace.
You said, it compiled without namespace, so you already added the reference.
【在 m***x 的大作中提到】 : not this issue. : when add the project to the reference of client, there is no problem.
|
m***x 发帖数: 492 | 5 without adding dll project as reference, the client compiled andrun well
without namespace.
if i deliver the dll, the client has no way to add project reference. that
is concern.
dont know what trick vs2010 made when
adding project reference.
reference.
【在 b***i 的大作中提到】 : if you don't add the reference, you couldn't build even without using : namespace. : You said, it compiled without namespace, so you already added the reference.
|
a9 发帖数: 21638 | 6 ....
【在 m***x 的大作中提到】 : without adding dll project as reference, the client compiled andrun well : without namespace. : if i deliver the dll, the client has no way to add project reference. that : is concern. : dont know what trick vs2010 made when : adding project reference. : : reference.
|
b***i 发帖数: 3043 | 7 我猜,你不加reference可以编译是因为你没有显式写构造函数。但是不写构造函数,有没有namespace没什么不同,同样可以编译运行,用好include, using namespace就行。你如果写了构造函数,尽管没有namesapce,没有reference仍然会报同样的错。
加了reference(当然应该要加),就可以有正常的构造函数,而这种情况,有没有namespace也没什么大的不同,用好include, using namespace就行。
写visual studio的dll, 必须(或者说,推荐)把所有事情都做对,参考
http://www.mitbbs.com/article_t/Programming/31216231.html
【在 m***x 的大作中提到】 : without adding dll project as reference, the client compiled andrun well : without namespace. : if i deliver the dll, the client has no way to add project reference. that : is concern. : dont know what trick vs2010 made when : adding project reference. : : reference.
|