0

I am new to programming with C++. So I am trying to inspect other's code to learn. I started inspecting a new prototype which has a function named myFcn. Its comment lines describe it requires mk.h, mk.lib and mk.dll files to be compiled. The project was successfully built. But when I go over the calling line of myFcn and press F12 (go to definition), the declaration prototype of myFcn appears and hitting again F12 does not bring me the body of the myFcn. I guess the function definition is in the mk.lib or mk.dll files. How can I find the body of the function?

EDIT 1: If I had several dll and lib files, could I recognize the file that myFcn was compiled in?

IndustProg
  • 627
  • 1
  • 13
  • 33
  • 2
    Depends, did you build the dlls yourself? If not there is a chance that the acutal source code is not on your computer. Otherwise go to the directoy where the source code lies and search for cpp files – TruckerCat Dec 10 '15 at 13:56
  • @R_Valdez No, I did not build it. There is only one cpp file in my directory. There are also 3 files, mk.h, mk.lib, mk.dll which I included them. – IndustProg Dec 10 '15 at 13:59
  • 2
    Then go to the website where you got the code from and check if there is the possibility to get the full source code. – TruckerCat Dec 10 '15 at 14:01
  • 2
    You do not have the sources (definitions), therefore you cannot go to definition. – zdf Dec 10 '15 at 14:02
  • @ZDF so where is the body of `myFcn`? in mk.lib? or in mk.dll? if yes, is there any way to read it from the files? – IndustProg Dec 10 '15 at 14:04
  • @NTS Read this to understand the diffrences between libs and dlls. http://stackoverflow.com/questions/913691/dll-and-lib-files-what-and-why The code is in bove, and you cant extract it. – TruckerCat Dec 10 '15 at 14:13
  • All you can do is get the disassembly and then try to understand it. – Banex Dec 10 '15 at 14:21

2 Answers2

1

The function body is likely to be compiled, if then you can't see the source code of it.

MujjinGun
  • 480
  • 3
  • 9
  • Please provide for me some information about its compilation. Is it compiled into mk.dll? or mk.lib? Sorry if my question was trivial. – IndustProg Dec 10 '15 at 14:09
  • @NTS look at this question. http://stackoverflow.com/questions/913691/dll-and-lib-files-what-and-why – MujjinGun Dec 10 '15 at 14:16
1

It seems that the function you are trying to use is compiled in the library which you use.

The purpose of this system is to let people use your functions without the need for them to edit them or understand their source code. This means that the author of the library has written the function, and compiled it into a library (.dll, .lib and .h).

By including the .h file in your project, and linking the .lib at compilation and the .dll at runtime, you can use this function without the need to ever see more than the header file.

If you wish to understand the code of this function, go to their website, and see if they provide the full source code.

Edit based on edit of question: As far as I know there is no direct way to see which header file links to which library. It is possible to view which functions are in a certain library. On Linux this is the 'nm' command for .a files (gcc libraries). For Windows some methods are described here: How to view DLL functions?.

Community
  • 1
  • 1
DrDonut
  • 864
  • 14
  • 26
  • The path became more clear for me. Thank you. How is myFcn called from mk.lib? only prototype declaration in mk.h is enough? – IndustProg Dec 10 '15 at 14:26
  • 1
    Yes, because when you compile your program, the compiler will look for the body of the function, and because you link the .lib file, the compiler will find it in there. – DrDonut Dec 10 '15 at 14:35
  • I updated my question by EDIT 1. Could you please consider it? – IndustProg Dec 11 '15 at 09:11