由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - how to export a class in a namespace in DLL?
相关主题
调用win32 DLL的问题我老版问我
求助:一个Visual C++ 9.0下编译OpenGL code的问题C++ 两个project enum value名冲突
c++设计一问:如何动态地调用不同的算法的dll ?how to resolve this problem?
C++菜问: 怎么这样也可以?function declaration
How to compile multiple c files into one obj file?一个VC++ .net里编译C程序的问题
C# 里用JAVA APIC++ template question with friend ostream
动态连接库问题: 继承一个DLL导出的类问一个windows下编译openGL code的问题
Windows下多个DLL之间memory allocation问题c++ does not check const for extern variable?
相关话题的讨论汇总
话题: economics话题: namespace话题: dll话题: dcl
进入Programming版参与讨论
1 (共1页)
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.

1 (共1页)
进入Programming版参与讨论
相关主题
c++ does not check const for extern variable?How to compile multiple c files into one obj file?
Visual C++ 高手帮忙,一个Link ErrorC# 里用JAVA API
一个读用户输入的小问题动态连接库问题: 继承一个DLL导出的类
顺便问一个CreateFile问题 (转载)Windows下多个DLL之间memory allocation问题
调用win32 DLL的问题我老版问我
求助:一个Visual C++ 9.0下编译OpenGL code的问题C++ 两个project enum value名冲突
c++设计一问:如何动态地调用不同的算法的dll ?how to resolve this problem?
C++菜问: 怎么这样也可以?function declaration
相关话题的讨论汇总
话题: economics话题: namespace话题: dll话题: dcl