How do you set up VS to output a dll?

Hey guys, I'm stuck on week 5. I can follow along using the command line just fine but I prefer to do everything within VS. I just cannot at all figure out how to make handmade.cpp output a dll file. Setting /LD in the VS command line settings doesn't work. Any ideas?

Here's how my project is set up.


Edited by John Meyer on
1) Project > Properties

2) Configurations Properties > General > Configuration Type

change it from Application (.exe) to Dynamic Library (.dll)

BUT, you will be compiling both the the exe and dll code together, you need to split the two into two separate projects, to output a exe and a dll

Edited by ambiguous panda on
ambiguous.panda
1) Project > Properties

2) Configurations Properties > General > Configuration Type

change it from Application (.exe) to Dynamic Library (.dll)

BUT, you will be compiling both the the exe and dll code together, you need to split the two into two separate projects, to output a exe and a dll


So do I take handmade.cpp out of my current project and put it into a new project?
you can create two projects, but use a single directory, both projects will have the smae files but compile with different settings

or, if compiling from visual studio is the only thing your looking for, you can add your build.bat to the external tools list, and then run it with a hotkey, there is already a thread in this forum explaining how to do it.
I've been trying to keep both the build.bat, and a Visual Studio version going at the same time. I've been doing ok so far, the comments above about adding a DLL project above should be enough for you to get it going. One other tip might be to add a new project to your solution, and select the DLL template, and make sure to select the empty project option. Then just copy the handmade.cpp and handmade.h into it. That's what I did, and only had to fiddle with some fairly obvious things to get it to work then.

However, I'm currently struggling to get Visual Studio to compile the DLL project while the debugger is running. Without working out how to do that, all the cool stuff Casey is doing with the changes on the fly aren't going to work in VS if you want the debugger running as well, which Casey definitely did. Without the debugger you can just ask VS to rebuild your DLL project, and the running game picks it up fine.

Edited by Tom Montgomery on Reason: Cleared up an editing mistake.
Getting VS to compile the DLL project while debugging is annoying. One way to do it is to setup a simple .BAT script and use that as an external tool to compile while debugging.

I managed to get it working by using the following in a build_dll.bat saved in the directory of the solution.
1
2
3
4
5
6
7
@echo off

REM Setup vcvars if they are not defined
if not defined DevEnvDir (
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x64
)
call msbuild.exe /VERBOSITY:quiet _PATH_TO_PROJECT_FILE_.vcxproj


Then add the .BAT file as an external tools from
1
2
3
4
5
Tools -> External Tools -> Add
Title: Build DLL
Command: $(SolutionDir)build_dll.bat
Arguments: 
Initial directory: $(SolutionDir)

You can also select to Use Output window so it outputs to the output window.

For easier time running you can bind External Tools to hotkeys from
1
Options -> Keyboard -> Search for Tools.ExternalCommand


The numbering starts from 1 and goes up. You can move the External Tools up and down and simply bind one and move the build command onto the slot you bound.

Perhaps there's a better solution but so far this seems to work when you really want to compile and reload while running.
Thank you for your external tools setup that actually helped me a lot, and did saved some time.

And the other alternate way, as mentioned by montysan, is you run your program by compiling/building everything using "Start without Debugging" or CTRL+F5, and then you build your DLL twice (CTRL+SHIFT+B ) in Visual Studio, so that the second build will then be able to override the first build and allow the EXE to load the DLL that the second build was able to successfully complete.

Now, I should really sleep. It's been a long day.

Edited by Thompson Lee on