Adding my DLL into a Visual Studio project in C++

て烟熏妆下的殇ゞ 提交于 2019-12-04 09:34:25

问题


I am working on a project that involves making a dynamic link library, so I want to test it in a console app in Visual Studio.

The DLL is also made in Visual Studio, it doesn't have much, just a few functions in it. I'm not sure if I'm just supposed to include the librarys header in the include directories panel in Properties, or do something else

A lot of people say I'm supposed to add its corresponding .lib file in the Library or Reference directory, but I'm not sure that VS generates a .lib file alongside the DLL. I'm using VS 2015.


回答1:


I don't have VS in front of me this very moment, but these should be the general steps to set it up:

Properties->Linker->Input: your.lib
Properties->Linker->Additional Library Directories: ../your/bin
Properties->General->Compiler->Additional Include Directories: ../your/include

To build your app, the DLL's API headers must be in the include for the compile-time, it's LIB files in the bin for the link-time. Once you have your app EXE, all you need is the DLL to be in the same folder as your EXE when it executes.

You might also want to add the dll project and the app project into a common solution in VS and add (right click) Project Dependency from the app to the dll. This ensures correct order of building, assuming you are going to build the dll at all.




回答2:


You can also do what I did.

  1. You can create a Libs directory inside of your Solution directory.
  2. You can then place your .DLL files inside of the Libs directory or some sub-directory inside of Libs

    • In my case, I added the entire SFML-2.3.2 directory in there, which included the source-code, .lib files, and .dll files.
    • I did link up what I could in the project properties, but I used Visual Studio's macros to fill in the path name to the Solution directory. Just in case I wanted to put this in version control and work on it from multiple machines.
  3. Then I opened up the Project's Property Page.

  4. Within the property page, I went to Build Events -> Post-Build Event -> Command Line
  5. Within the Command Line, you can add a copy command that will copy any needed files into the same directory as the executable that will need them.
    • In my case I used: copy "$(SolutionDir)Libs\SFML-2.3.2\bin\*" "$(TargetDir)"
    • I could have written multiple commands to copy just the individual files that I needed, but I had spent a good three hours trying to get SFML to work without actually installing it.


来源:https://stackoverflow.com/questions/31596315/adding-my-dll-into-a-visual-studio-project-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!