views:

41

answers:

1

So I have gone through this tutorial three times:

http://msdn.microsoft.com/en-us/library/1ez7dh12.aspx

Every time I get to the end and try to run the program, it says:

Error 1 fatal error C1083: Cannot open include file: 'MathFuncsDll.h': No such file or directory

Using a .dll was so simple in C#.

Could anyone explain to me, assuming I have a header file C:\bob.h and a corresponding dll C:\bob.dll, how I would use the functions described in the header file?

Could anyone also explain why, even if a header file is added to the header files folder with Add Existing Item, the header file cannot seem to be found?

Thank you

+2  A: 

The 'folders' in the solution are a grouping mechanism for managin the solution, and not related to 'finding' includes or libs when compiling or linking.

If all the code isn't in the same folder, or identified using references then you may want to add include directories - with VC this is typically located under project properties/configuration properties/C C++/General/Additional Include Directories. This sets on the compiler the -I option which is to specify a path to other locations for your header files.

Say you have

C:\A.h
C:\A.cpp
C:\Project1\B.h
C:\Project1\B.cpp

And B needs to use A. You could:

  1. Move A files into Project 1 folder and in B.h use #include "A.h"
  2. Change B.h to #include "../A.h"
  3. Add addition include directories of C:\ and use #include "A.h" or #include <A.h>

Meanwhile add A.cpp and B.cpp to the project will compile them in the location they are in the file system, the object file output should all be located in the intermediate directory and usable by the linker without further issue.

Greg Domjan
Thanks for your quick answer. I got a header and .cpp in another folder to work. I got the tutorial to work finally, too. But:Can you tell me the steps to use a dll I didn't create. For example, if I have a dll C:\Project\bob.dll and a header file C:\Project\bob.h, I have tried:1) Add bob.h to the project.2) #include "C:\Project\bob.h"3) under Configuration Properties > Debugging > Environment I have written PATH=C:\Project (from tutorial)This doesn't seem to work and gives me errors saying the functions in my dll can't be found.Thanks for helping me understand how this works.
Johnny
Johnny, Probably better to ask this new question separately. The following might get you started though http://stackoverflow.com/questions/1778111/whats-the-differences-between-dll-lib-h-files
Greg Domjan
So I found that if I add the bob.lib file I can use the functions I need. However, if I include bob.lib am I using the dll at all? Why does including the bob.lib fix the linking error, but including bob.dll does not? Thanks
Johnny
bob dll is needed at runtime. for VC a lib file resolves the dependancies and tells it how to use bob dll at runtime. Including the lib is what you should do.
Greg Domjan
thanks for your help. Nice to find helpful people on a computer forum for once!
Johnny