我无法在 Windows Phone 8.0 的 MSVC-2013 中获取与 .exe 应用程序链接的静态库。
我做了什么:
文件->新建->项目->DirectX 应用程序 (Windows Phone 8.0) -> 将其命名为“MyApp”。
这个模板创建了很好的应用程序,编译和运行没有问题。
右击解决方案->添加->新建项目->静态库(Windows Phone 8.0)。我们称它为“MyLib”。
右键单击 MyApp -> Build Dependencies -> Project Dependencies -> Make it dependent on MyLib.
仍然编译并运行。
转到 MyLib.h 并声明
int my_function(int x)
。转到 MyLib.cpp 并定义
int my_function(int x) {return 0;}
。#include "MyLib.h"
在 MyApp 的 CubeRenderer.cpp 中。在 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/