首页 > 编程语言 > 详细

Got Stucked in C++ Static Library Loading.. for some time

时间:2016-04-19 17:17:13      阅读:273      评论:0      收藏:0      [点我收藏+]

I used to load library using 1 single .dll file, so when I happen to do method calling between 2 projects in a solution, I got puzzled..

In the solution, doing method calling between projects is constant, so as far as I can see, the dynamic calling method is onerous. It‘s also not Okay to call method from the other project directly, that will invoke the unresolved external link error(2001,1014,2011, etc..) during link.

Eventually I found that static calling is the remedy. In this way, you can avoid doing onerous calling that dynamic calling might cause. But the shortcoming is to attach a .lib with the release, making the size larger. Most times .lib files are small in size.

dynamic calling in x86 programs:

1 //method definition in .dll: type Func(type1 t1, type2 t2);
2 typedef type (*F)(type1,type2);
3 HINSTANCE hInst = new LoadLibrary(".dll");
4 F f = GetProcAddress(
5         hInst,
6         "Func"
7 };
8 //method name never coincides.

static calling:

1 //statically calling method
2 //First, specify the additional c/c++ include directory where func.h is in C/C++ general from project properties.
3 //Second, if needed, specify the func2.lib file directory in link general from project properties
4 //func.h
5 #include "func2.h"//this file contains the function definition
6 #pragma comment(lib, "func2.lib")//.lib file contains info about method addresses in .dll file
7 func2();//method calling

 

Got Stucked in C++ Static Library Loading.. for some time

原文:http://www.cnblogs.com/sansna/p/5408636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!