将静态库添加到同一解决方案中的项目 (Visual Studio 2012) [英] Adding a static library to a project in the same solution (Visual Studio 2012)

查看:33
本文介绍了将静态库添加到同一解决方案中的项目 (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:

  1. 通过转到引用...>添加新引用并选择我的库,添加了对静态库的引用
  2. 通过 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆