将静态库添加到同一解决方案中的项目 (Visual Studio 2012)

编程入门 行业动态 更新时间:2024-10-27 08:36:08
本文介绍了将静态库添加到同一解决方案中的项目 (Visual Studio 2012)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个将在项目中使用的静态库.该库编译良好并为其创建 *.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:

  • 通过转到引用...>添加新引用并选择我的库,添加了对静态库的引用
  • 通过 Configuration Properties>C/C++>General>Additional Include Directories 将源文件添加到包含目录的目录(我觉得这应该没有必要,因为它有点违背了创建库的目的)
  • 这些是 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)

    本文发布于:2023-11-01 23:35:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1550733.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:静态   解决方案   项目   Studio   Visual

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!