如何在我的项目中使用库? [英] How to use libs in my project ?

查看:115
本文介绍了如何在我的项目中使用库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个vs2005 win32控制台项目,并将一个静态库导入到我的项目中.

1.在库中,定义了一个类"CTST",库名是"ctst.lib";
2.它的头文件是Ctst.h;
3.我按如下方式使用它:

I created a vs2005 win32 console project, and a static library was imported to my project.

1. In the lib, a class ''CTST'' had been definded,lib name is ''ctst.lib'';
2. It''s head file is Ctst.h;
3. I use it like below:

//before this, I have already imported the libary to the project.
#include "Ctst.h" //just for including CTST type declaration:
CTST* newTst = new CTST();//call construction

if(newTst->Fun1())//call a funtion in CTST,Fun1 returns boolean
{
    printf("hello Fun1 1111\n ");
}

if(!newTst->Fun1() || newTst->Fun1())//Fun1 returns boolean type value
{
    printf("hello 2222 \n ");
}
//... Other use of the libary.

delete newTst;


4.当我进入上面的代码时,我发现它可以被编译,但是我无法进入库中的任何代码,并且在我的项目中ctst.lib中使用的功能根本没有效果.

5.打印如下:
你好2222

6.我陷入了这个问题,对我来说有什么解决办法吗?


4. When I stepped into the code above, I found that it can be compiled, but not able for me to step into any code in the libary, and funtions used in ctst.lib in my project had no effect at all.

5. It prints like below:
hello 2222

6. I was locked into this problem, Is there any solutions for me ?
Thanks in advance!

推荐答案

请检查您是否同时在DEBUG配置中编译了主程序和库.

看来您的Fun1函数正在返回false.解释输出.
Please check that you compiled both, your main program and the library in DEBUG configuration.

It looks like your Fun1 function is returning false. That explains the output.


if(newTst->Fun1())//call a funtion in CTST,Fun1 returns boolean
    {
        printf("hello Fun1 1111\n ");
    }
 
    if(!newTst->Fun1() || newTst->Fun1())//Fun1 returns boolean type value
    {
        printf("hello 2222 \n ");
    }



从第一个if语句开始,很明显newTst-> Fun1()返回false,因此仅在下一个if语句成功并且结果如您所说的那样打印



From the first if statement, it is obvious that newTst->Fun1() returns false, so only in the next if statement succeeded and the result is printed as stated by you


这篇关于如何在我的项目中使用库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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