« CGNP: My new lab | Main | Finding entry points when importing from a self-made DLL in C# »
December 23, 2006
building and using a DLL in C++ in VisualStudio 2005
As a professor, I have an uncanny ability to overlook details when I write code. I tend to look at the big picture, and that's a good thing most of the time when writing proposals, designing classes etc. I just finished building and using a DLL in C++ in VS 2005. It was a traumatic experience. Here's the details I overlooked. They were mostly on the importing side.
1. The __declspec(dllimport)int myInt(void); stuff has to appear (a) outside of enclosing namespaces (b) outside of class declarations because (a) putting it in a namespace will cause the linker to not find it and (b) you can't use __declspec (dllimport) within a managed class. The linker was dutifully telling me exactly that but it took me a while to figure out exactly what it meant.
2. You can list the libraries on which your stuff depends under... Project | Properties | Linker Input | Additional Dependencies. This would be where you list the .lib file that comes with your .dll file. It's just a simple text field that you type the name of your lib file into. That's a little odd, but the path will get worked out under the General item in the "Additional Library Directories" field where you do get to browse for a path.
3. The .dll needs to appear in the directory from which your project is executed. This was easy to figure out and solve, but bears mentioning.
4. The linker can be made to create verbose output under Linker | General | Show Progress and this output appears in the buildlog which can be linkto to from the output window (surprisingly). Just as an interesting datapoint: once I got the feedback loop closed by making the linker verbose, it took about 10 minutes to solve all the other problems. You can't fix what you can't see. True statement.
That's about it. Other than those little details, the C++ books, websites and MSFT documentation were all spot on. It may be clear at this point that I am somewhat clueless about VisualStudio as a project development tool. It's true. Although VS is much better than the Makefiles and command line tools that I know and "love", I still know how to do stuff in a Makefile and it takes time to figure out which sequence of mouse clicks are equivalent to 10 characters or less in a Makefile. Even worse, learning Makefiles is easy beacuse you just copy somebody else's. Learning VS click sequences is more painful because there's no flat text files to copy and modify.
Posted by jones at December 23, 2006 10:50 PM
Comments
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)