c++ - 如何使用静态库(windows phone 8)

标签 c++ windows-phone-8 visual-studio-2013

我无法在 Windows Phone 8.0 的 MSVC-2013 中获取与 .exe 应用程序链接的静态库。

我做了什么:

  1. 文件->新建->项目->DirectX 应用程序 (Windows Phone 8.0) -> 将其命名为“MyApp”。

    这个模板创建了很好的应用程序,编译和运行没有问题。

  2. 右击解决方案->添加->新建项目->静态库(Windows Phone 8.0)。我们称它为“MyLib”。

  3. 右键单击 MyApp -> Build Dependencies -> Project Dependencies -> Make it dependent on MyLib.

    仍然编译并运行。

  4. 转到 MyLib.h 并声明 int my_function(int x)

  5. 转到 MyLib.cpp 并定义 int my_function(int x) {return 0;}

  6. #include "MyLib.h" 在 MyApp 的 CubeRenderer.cpp 中。

  7. 在 CubeRenderer.cpp 的 CubeRenderer::CubeRenderer() 中添加 int y = my_function(6);

这会产生链接器错误。

error LNK2019: unresolved external symbol "int __cdecl my_function(int)" (?my_function@@YAHH@Z) 

MyApp依赖于MyLib,所以我不需要在Linker->Input->Addidtional Dependencies中设置。不管怎样,我试过了,还是报错。

我在 MyLib.lib 中搜索了 ?my_function@@YAHH@Z - 并在那里找到了 5 次。

也许我不能使用名为 Static Library (Windows Phone 8.0) 的模板,应该使用 DLL (Windows Phone 8.0)Windows Runtime Component (Windows Phone 8.0) )?

最佳答案

您需要将项目添加到项目引用才能进行此构建。您可以通过右键单击项目 Add->References 并单击 Add New Reference 并将 MyLib 添加到 MyApp 作为项目引用来添加它。

关于c++ - 如何使用静态库(windows phone 8),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24405117/

相关文章:

javascript - 关闭应用程序时在 Windows Phone 8.1 中处理 toast 通知

c# - 在 Windows Phone 8 中读取和写入列表到 IsolatedStorage

c# - "Enable Debugging of Unmanaged Code"在哪里可以在系统运行时编辑代码?

c++ - boost 互斥量和类成员访问

c++ - 文件挂载在哪里?

c++ - 为什么作用域枚举默认支持运算符 '<'?

windows-phone-8 - 资源未显示在设计器 View Visual Studio Windows Phone 应用程序中

visual-studio-2012 - 删除项目时的 Visual Studio 扩展冲突

node.js - Visual Studio 无法将 JavaScript 输出合并到一个文件中。我需要做更多的调整吗?

c++ - 为什么 C++ 析构函数会发生这种情况?