引用另一个 Windows Phone 运行时组件项目中一个 Windows Phone 运行时组件项目中的C++类
Reference a C++ class from one Windows Phone Runtime Component project in another
我有两个Windows Phone运行时组件项目(Windows Phone Silverlight 8.1(,其中包含C++类:
- FooRuntimeComponent:
- 福班.cpp
- FooClass.h
- BarRuntimeComponent:
- 酒吧类.cpp
- BarClass.h
我想在 Bar 类中创建的 Foo 对象上调用方法。
噗
:#pragma once
namespace FooRuntimeComponent
{
public ref class FooClass sealed
{
public:
FooClass();
};
}
Foo类.cpp:
#include "FooClass.h"
using namespace FooRuntimeComponent;
using namespace Platform;
FooClass::FooClass()
{
}
酒吧类.cpp:
#include "BarClass.h"
#include "FooClass.h"
using namespace BarRuntimeComponent;
using namespace Platform;
using namespace FooRuntimeComponent;
BarClass::BarClass()
{
FooClass^ foo = ref new FooClass();
}
如果我尝试通过将 FooRuntimeComponent.lib 指定为额外的依赖项并提供指向 .lib 的路径来"传统"将 Foo 链接到 Bar,那么我会收到以下 Bar 编译错误:
error LNK2019: unresolved external symbol "public: __cdecl FooRuntimeComponent::FooClass::FooClass(void)" (??0FooClass@FooRuntimeComponent@@Q$AAA@XZ) referenced in function "public: __cdecl BarRuntimeComponent::BarClass::BarClass(void)" (??0BarClass@BarRuntimeComponent@@Q$AAA@XZ)
在 FooRuntimeComponent.lib 上运行 dumpbin.exe 会产生:
Microsoft (R) COFF/PE Dumper Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file FooRuntimeComponent.lib
File Type: LIBRARY
Summary
FF .debug$S
14 .idata$2
14 .idata$3
4 .idata$4
4 .idata$5
20 .idata$6
我确实注意到运行时组件生成一个 .winmd 文件。我尝试将此.winmd添加为对Bar项目的引用,但是后来出现以下错误:
error C2011: 'FooRuntimeComponent::FooClass' : 'class' type redefinition
error C2027: use of undefined type 'FooRuntimeComponent::FooClass'
error C2027: use of undefined type 'FooRuntimeComponent::FooClass'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2680: 'FooRuntimeComponent::FooClass ^' : invalid target type for dynamic_cast
error C2440: 'return' : cannot convert from 'FooRuntimeComponent::FooClass ^' to 'int'
我错过了什么吗?
在"解决方案资源管理器"中,右键单击BarRuntimeComponent (Windows Phone Silverlight 8.1)
项目项(不是解决方案(,然后选择"Add
> References...
"。单击Add New Reference...
按钮,然后找到FooRuntimeComponent
项目(如果 foo 项目与 bar 项目位于同一解决方案中,那么您将在窗口左侧的Solution
项下找到 foo 项目(。确保选中 foo 项目,然后单击"确定",然后再次单击"确定"。您现在应该能够在酒吧项目中使用FooClass
。这就是它的全部内容。
您可能首先需要撤消以前可能执行的任何其他引用(例如您手动链接的 .lib 文件(。同时从 BarClass.cpp 文件中删除#include "FooClass.h"
行。编译器从 .winmd 文件中获取类型。
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法在 CLion 中构建 C++ 项目
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 欧拉项目#8答案是大以获得有效答案
- 从链接列表c++中删除一个项目
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 既然存在危险,为什么项目要使用-I include开关
- 如何使用CMake将QtMultimedia组件集成到项目中?
- 如何将scintilla组件添加到QT创建者C 项目中
- 如何使用CMAKE中的组件配置项目
- C++运行时组件(通用 Windows)项目生成错误"LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'"
- Windows 通用 - 在项目中调用 C# 运行时组件时崩溃C++
- 如何将 Indy 组件添加到C++生成器项目
- 引用Windows应用商店应用程序项目中的C++WinRT组件
- 编译基于组件的大型C++项目
- 引用另一个 Windows Phone 运行时组件项目中一个 Windows Phone 运行时组件项目中的C++类
- 直接使用C++WinRT组件或C++XAML项目是否存在任何性能问题
- 如何从C/ c++项目中创建运行时组件