我正在尝试创建一个将在项目中使用的静态库.该库编译良好并为其创建 *.lib 文件.为了测试我的代码,我在同一个解决方案中添加了另一个项目.当我尝试构建测试项目时,出现以下错误.
I'm trying to create a static library that I will be using in a project. The library compiles fine and creates the *.lib file for it. To test my code, I added another project to the same solution. When I try to build the test project I get the following errors.
错误 LNK1120:4 个无法解析的外部
error LNK1120: 4 unresolved externals
错误 LNK2019: 未解析的外部符号 "public: __thiscall >matrix::~matrix(void)" (??1?$matrix@M@@QAE@XZ) 在函数 _main 中引用
error LNK2019: unresolved external symbol "public: __thiscall >matrix::~matrix(void)" (??1?$matrix@M@@QAE@XZ) referenced in function _main
错误 LNK2019:未解析的外部符号 "public: __thiscall >matrix::matrix>(int,int)" (??0?$matrix@M@@QAE@HH@Z) 在函数 >_main C:\ 中引用Users\Ryan\Documents\Spring 2013\ECE >4007\PointCloudLib\matrix_test\matrix_test.obj matrix_test
error LNK2019: unresolved external symbol "public: __thiscall >matrix::matrix>(int,int)" (??0?$matrix@M@@QAE@HH@Z) referenced in function >_main C:\Users\Ryan\Documents\Spring 2013\ECE >4007\PointCloudLib\matrix_test\matrix_test.obj matrix_test
错误 LNK2019:未解析的外部符号 "public: bool __thiscall >matrix::set(int,int,float)" (?set@?$matrix@M@@QAE_NHHM@Z) 在函数 >_main 中引用
error LNK2019: unresolved external symbol "public: bool __thiscall >matrix::set(int,int,float)" (?set@?$matrix@M@@QAE_NHHM@Z) referenced in function >_main
错误 LNK2019:未解析的外部符号public: static void __cdecl >matrix::print(class matrix const &)" (?print@?$matrix@M@@SAXABV1@@Z) >在函数_main中引用
error LNK2019: unresolved external symbol "public: static void __cdecl >matrix::print(class matrix const &)" (?print@?$matrix@M@@SAXABV1@@Z) >referenced in function _main
要在我的代码中使用该库,我执行了以下步骤:
To use the library in my code I performed the following steps:
这些是 Microsoft 的 msdn 站点上列出的有关创建您自己的静态库的步骤,而其他人似乎认为这是解决问题的方法.
Those are the steps listed on Microsoft's msdn site about creating your own static libraries and it seems to be what other people are saying is the solution to the problem.
我还需要做些什么才能在我的项目中使用该库?
Is there something else I need to do to use the library in my project?
此外,这是我用来测试库的代码:
Also, here is the code I'm using to test the library:
#pragma once #include "stdafx.h" #include <iostream> #include "matrix.h" #define PI 3.14 #define matrix_f matrix<float> int main() { matrix_f m(3,4); for(int i = 0; i < 3; i++) for(int j = 0; j < 4; j++) m.set(i,j,PI/((i+1)*(j+1))); matrix_f::print(m); } 推荐答案需要添加对要找到静态库的库目录的引用:
You need to add the reference to the library directory where the static library is to be found:
更多推荐
将静态库添加到同一解决方案中的项目 (Visual Studio 2012)
发布评论