有没有人让C ++ .NET库工作? [英] Has ANYONE gotten C++ .NET libraries to work?

查看:51
本文介绍了有没有人让C ++ .NET库工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio .NET 2003,我创建了一个新项目 - > C ++ - >类

库(.NET)。


即时我包含一个C ++头文件,例如:


#include< string>


或我能想到的任何其他标准C ++标题,项目不会构建:


链接...

链接:错误LNK2020:未解析的令牌(0A000006)_CxxThrowException

链接:错误LNK2020:未解析的令牌(0A000017)删除

LINK :致命错误LNK1120:2个未解决的外部因素

我已经完成了大量的互联网搜索,发现许多其他人已经遇到了这个确切的问题,但没有找到解决方案。我尝试过的

建议解决方案:

- 将Project Properties中的Runtime Library选项更改为

"多线程调试DLL"来自多线程调试。这没有用。

- 明确添加LIBCPMTD.LIB。没有帮助;我假设这已经自动完成了




我没有托管C ++控制台和windows的这些问题

应用程序。那些似乎很好。但托管的C ++类库似乎只是简单地被破坏了。


这看起来像是一个非常大的公然错误。我甚至找不到官方

已知错误在Microsoft的网站上输入信息。我找到了一个知识库

文章,它松散地描述了2002版Visual * / $
Studio的这个错误,但文章建议它将在后续版本中修复。 />
版本(例如我正在使用的2003)。


最终我的目标是将现有的C ++代码包装在.NET库中

界面。所有代码都将在Managed C ++编译器下编译。

With Visual Studio .NET 2003, I create a new project -> C++ -> Class
library (.NET).

The instant I include a C++ header file such as:

#include <string>

or any other standard C++ header I can think of, the project won''t build:

Linking...
LINK : error LNK2020: unresolved token (0A000006) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000017) delete
LINK : fatal error LNK1120: 2 unresolved externals
I''ve done lots of Internet searches and found many others who have
encountered this exact problem but none have found a solution. Among
suggested solutions that I''ve tried:
- Changing the Runtime Library option in Project Properties to
"Multi-threaded Debug DLL" from "Multi-threaded Debug". This didn''t help.
- Explicitly adding LIBCPMTD.LIB. Didn''t help; I assume this is done
automatically.

I don''t have these problems with Managed C++ console and windows
applications. Those seem fine. But Managed C++ class libraries seem to
be simply broken.

This seems like a very large blatant bug. I can''t even find official
"known bug" type info on Microsoft''s site. I''ve found a knowledge base
article that loosely describes this bug for the 2002 version of Visual
Studio but the article suggests that it would be fixed in subsequent
versions (such as 2003 which I''m using).

Ultimately my goal is to wrap existing C++ code in a .NET library
interface. All the code will compile under the Managed C++ compiler.

推荐答案

是的,我能够复制你的问题。修复它非常简单,所有我需要做的就是移动#include< string>在包括stdafx.h和其他程序之前,在
程序的最顶层。试试这个并告诉我们

如果它现在可以为你编译。


mosimu


Tommy Vercetti ;写道:
Yes, I was able to duplicate your problem. It was very simple to fix it, all
I had to do was move the #include <string> line to the very top of the
program, before including stdafx.h and the others. Try this and let us know
if it now compiles for you.

mosimu

"Tommy Vercetti" wrote:
使用Visual Studio .NET 2003,我创建了一个新项目 - > C ++ - >类
库(.NET)。

即时我包含一个C ++头文件,例如:

#include< string>

链接......
链接:错误LNK2020:未解析的令牌(0A000006)_CxxThrowException
链接:错误LNK2020:未解析的令牌(0A000017)删除
链接:致命错误LNK1120:2未解析的外部

我已经进行了大量的互联网搜索,发现许多其他人有
遇到了这个确切的问题但没有找到解决方案。我尝试过的
建议解决方案之一:
- 将Project Properties中的Runtime Library选项更改为
Multi-threaded Debug DLL。来自多线程调试。这没有用。
- 明确添加LIBCPMTD.LIB。没有帮助;我认为这是自动完成的。

我没有托管C ++控制台和windows
应用程序的这些问题。那些似乎很好。但托管的C ++类库似乎只是被打破了。

这似乎是一个非常大的明显错误。我甚至找不到官方的已知错误。在Microsoft的网站上输入信息。我找到了一篇知识库文章,它松散地描述了2002版Visual /> Studio的这个bug,但文章建议它将在随后的
版本中修复(例如2003年我正在使用。

最终我的目标是将现有的C ++代码包装在.NET库界面中。所有代码都将在Managed C ++编译器下编译。
With Visual Studio .NET 2003, I create a new project -> C++ -> Class
library (.NET).

The instant I include a C++ header file such as:

#include <string>

or any other standard C++ header I can think of, the project won''t build:

Linking...
LINK : error LNK2020: unresolved token (0A000006) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000017) delete
LINK : fatal error LNK1120: 2 unresolved externals
I''ve done lots of Internet searches and found many others who have
encountered this exact problem but none have found a solution. Among
suggested solutions that I''ve tried:
- Changing the Runtime Library option in Project Properties to
"Multi-threaded Debug DLL" from "Multi-threaded Debug". This didn''t help.
- Explicitly adding LIBCPMTD.LIB. Didn''t help; I assume this is done
automatically.

I don''t have these problems with Managed C++ console and windows
applications. Those seem fine. But Managed C++ class libraries seem to
be simply broken.

This seems like a very large blatant bug. I can''t even find official
"known bug" type info on Microsoft''s site. I''ve found a knowledge base
article that loosely describes this bug for the 2002 version of Visual
Studio but the article suggests that it would be fixed in subsequent
versions (such as 2003 which I''m using).

Ultimately my goal is to wrap existing C++ code in a .NET library
interface. All the code will compile under the Managed C++ compiler.



mosimu写道:
是的,我能够复制你的问题。修复它非常简单,我所要做的就是移动#include< string>在包括stdafx.h和其他人之前,排在程序的最顶端。试试
这个,让我们知道它现在是否适合你。


如果使用预编译头文件,这只会通过在#includestdafx.h之前插入

来掩盖问题。你的测试中使用了std :: string

的情况吗?


Jeff Flinn

mosimu

Tommy Vercetti写道:
Yes, I was able to duplicate your problem. It was very simple to fix
it, all I had to do was move the #include <string> line to the very
top of the program, before including stdafx.h and the others. Try
this and let us know if it now compiles for you.
If using precompiled headers, this merely masks the problem by ingoring
anything before the #include "stdafx.h". Was std::string used in your test
case?

Jeff Flinn

mosimu

"Tommy Vercetti" wrote:
使用Visual Studio .NET 2003,我创建了一个新项目 - > C ++ - >类
库(.NET)。

即时我包含一个C ++头文件,例如:

#include< string>

链接......
链接:错误LNK2020:未解析的令牌(0A000006) )_CxxThrowException
链接:错误LNK2020:未解析的令牌(0A000017)删除
链接:致命错误LNK1120:2未解析的外部

我已经完成了大量的互联网搜索并发现了很多其他人已经遇到了这个确切的问题,但没有人找到解决方案。我尝试过的
建议解决方案之一:
- 将Project Properties中的Runtime Library选项更改为
Multi-threaded Debug DLL。来自多线程调试。这没有帮助。 - 明确添加LIBCPMTD.LIB。没有帮助;我认为这是自动完成的。

我没有托管C ++控制台和windows
应用程序的这些问题。那些似乎很好。但托管C ++类库似乎只是被打破了。

这似乎是一个非常大的明显错误。我甚至找不到官方的已知错误。在Microsoft的网站上输入信息。我找到了一篇知识基础文章,它松散地描述了2002版Visual / Visual Studio的这个bug,但文章建议它将在
后续版本中修复(例如2003年我正在使用。

最终我的目标是将现有的C ++代码包装在.NET库界面中。所有代码都将在Managed C ++编译器下编译。
With Visual Studio .NET 2003, I create a new project -> C++ -> Class
library (.NET).

The instant I include a C++ header file such as:

#include <string>

or any other standard C++ header I can think of, the project won''t
build:

Linking...
LINK : error LNK2020: unresolved token (0A000006) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000017) delete
LINK : fatal error LNK1120: 2 unresolved externals
I''ve done lots of Internet searches and found many others who have
encountered this exact problem but none have found a solution. Among
suggested solutions that I''ve tried:
- Changing the Runtime Library option in Project Properties to
"Multi-threaded Debug DLL" from "Multi-threaded Debug". This didn''t
help. - Explicitly adding LIBCPMTD.LIB. Didn''t help; I assume this
is done automatically.

I don''t have these problems with Managed C++ console and windows
applications. Those seem fine. But Managed C++ class libraries seem
to be simply broken.

This seems like a very large blatant bug. I can''t even find official
"known bug" type info on Microsoft''s site. I''ve found a knowledge
base article that loosely describes this bug for the 2002 version of
Visual Studio but the article suggests that it would be fixed in
subsequent versions (such as 2003 which I''m using).

Ultimately my goal is to wrap existing C++ code in a .NET library
interface. All the code will compile under the Managed C++ compiler.



Jeff,你是绝对正确的;移动包括在stdafx.h之前

只是忽略它们所以它并没有真正修复任何东西。


昨天撕掉我的头发之后,我相信我已经确定了问题:

http://support.microsoft.com/default...b;en-us;814472


这是混合DLL加载问题并且显然与使用托管(.NET)DLL和非托管(常规C ++)DLL的

相关联,这些DLL具有相同的DLL项目




对于这个问题,这是一个非常混乱的名称。这听起来像是一些模糊的具体问题,但事实并非如此; *所有* MC ++类库项目

将符合此描述。除了非常罕见的例外,所有MC ++项目

使用.NET运行时(这是一个托管DLL)和常规C ++


如果你按照该页面上的步骤列表,你可以解决

构建错误,但是有更多问题。听起来像

全局/静态变量初始化并不是100%正常运行。我还没有b $ b得到我所有的代码编译,但这听起来并不好。我使用的代码很好地使用了静态变量。


微软说明他们将这些错误遗留下来以便

人们意识到其他不太明显的运行时问题。我正在寻找

前进。


这是我讨厌的编程的一部分。对不起发泄。希望这个

帮助其他人在同一条船上。


Jeff F写道:
Jeff, you are absolutely right; moving includes before the stdafx.h will
just ignore them so it''s not really fixing anything.

After ripping my hair out all yesterday, I believe I''ve identified the
issue:

http://support.microsoft.com/default...b;en-us;814472

This is the "Mixed DLL Loading Problem" and is apparently related to
using both managed (.NET) DLLs and unmanaged (regular C++) DLLs withing
the same DLL project.

That is a very confusing name for this problem. It sounds like some
obscure specific issue but it''s not; *ALL* MC++ class library projects
will fit this description. With very rare exception, all MC++ projects
use the .NET runtime (which is a managed DLL) and the regular C++
runtime (which is an unmanaged DLL).

If you follow the list of steps on that page, you can get around the
build errors however there are more problems. It sounds like the
global/static variable initialization isn''t 100% functional. I haven''t
got all my code compiling yet, but that doesn''t sound good. The code I''m
using makes plenty of use of static variables.

The Microsoft note says that they left these errors in place so that
people are aware of the other less obvious runtime problems. I''m looking
forward to it.

This is the part of programming that I hate. Sorry to vent. Hope this
helps out others in the same boat.

Jeff F wrote:
mosimu写道:
mosimu wrote:
是的,我能够复制你的问题。修复它非常简单,我所要做的就是移动#include< string>在包括stdafx.h和其他人之前,排在程序的最顶端。试试这个,让我们知道它现在是否为你编译。
Yes, I was able to duplicate your problem. It was very simple to fix
it, all I had to do was move the #include <string> line to the very
top of the program, before including stdafx.h and the others. Try
this and let us know if it now compiles for you.



如果使用预编译头文件,这只会通过在#include之前插入任何内容来掩盖问题" stdafx.h中" ;.你的测试中使用了std :: string吗?

Jeff Flinn


If using precompiled headers, this merely masks the problem by ingoring
anything before the #include "stdafx.h". Was std::string used in your test
case?

Jeff Flinn



这篇关于有没有人让C ++ .NET库工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆