Linking Libraw to VS project

I was able to compile the Libraw .lib, .dll, and examples programs successfully. I've tested the sample programs and they work. However, now I'm trying to link the library into a Visual Studio 2013 project I'm working on and can't figure out why it's not working.
Under Linker->Input->Additional Dependencies, I've added the path to the lib/libraw.lib file. At the top of my code I've also added a #include <libraw.h> and in C/C++->General->Additional Include Directories I've added the path to the LibRaw-0.16.2/libraw folder.
But when I try to compile it can't find the definitions for the functions I'm trying to use:

Error	1	error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl LibRaw::LibRaw(unsigned int)" (__imp_??0LibRaw@@QEAA@I@Z) referenced in function "int __cdecl runDepthFromFocus(int,char * * const)" (?runDepthFromFocus@@YAHHQEAPEAD@Z)	C:\Users\Matteo\Desktop\GSFF_MV_Build\src\matteo\depthFromFocus.obj	Matteo
Error	2	error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl LibRaw::open_file(wchar_t const *,__int64)" (__imp_?open_file@LibRaw@@QEAAHPEB_W_J@Z) referenced in function "int __cdecl runDepthFromFocus(int,char * * const)" (?runDepthFromFocus@@YAHHQEAPEAD@Z)	C:\Users\Matteo\Desktop\GSFF_MV_Build\src\matteo\depthFromFocus.obj	Matteo
Error	3	error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl LibRaw::dcraw_ppm_tiff_writer(char const *)" (__imp_?dcraw_ppm_tiff_writer@LibRaw@@QEAAHPEBD@Z) referenced in function "int __cdecl runDepthFromFocus(int,char * * const)" (?runDepthFromFocus@@YAHHQEAPEAD@Z)	C:\Users\Matteo\Desktop\GSFF_MV_Build\src\matteo\depthFromFocus.obj	Matteo
Error	4	error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl LibRaw::~LibRaw(void)" (__imp_??1LibRaw@@UEAA@XZ) referenced in function "int __cdecl runDepthFromFocus(int,char * * const)" (?runDepthFromFocus@@YAHHQEAPEAD@Z)	C:\Users\Matteo\Desktop\GSFF_MV_Build\src\matteo\depthFromFocus.obj	Matteo
Error	5	error LNK1120: 4 unresolved externals	C:\Users\Matteo\Desktop\GSFF_MV_Build\src\matteo\RelWithDebInfo\Matteo.exe	1	1	Matteo

Forums: 

That should say I've added a

That should say I've added a #include < libraw.h > without the spaces but I guess it thought I was trying to add some kind of HTML tag

Please check, that you've

Please check, that you've build DLL correctly:
- you need to add /DLIBRAW_BUILDLIB to compiler flags when you compile DLL parts
- and do not add this flag if you compile user code that uses libraw.

The trick is within libraw_types.h:

#ifdef WIN32
#ifdef LIBRAW_NODLL
# define DllDef
#else
# ifdef LIBRAW_BUILDLIB
#    define DllDef   __declspec( dllexport )
# else
#    define DllDef   __declspec( dllimport )
# endif
#endif
#else
#  define DllDef
#endif

So, when you compile DLL, all needed functions are marked as dllexport

-- Alex Tutubalin @LibRaw LLC

So I tried compiling by

So I tried compiling by running "nmake /DLIBRAW_BUILDLIB -f Makefile.msvc" but it said "NMAKE: fatal error U1065: invalid option 'W' Stop."
I'm probably putting that flag in the wrong spot, but I tried to hack around it by swapping the dllimport and dllexport in libraw_types.h, so that it uses dllexport if I don't define that flag, which is what I'm trying to do anyway.
Doing that, I start compiling by running "nmake -f Makefile.msvc" but I get a bunch of errors (it won't let me post all of them because it thinks it's spam, but they all generally look like the following):

libraw_datastream.obj : error LNK2019: unresolved external symbol "__declspec(dl
limport) const LibRaw_windows_datastream::`vftable'" (__imp_??_7LibRaw_windows_d
atastream@@6B@) referenced in function "public: __thiscall LibRaw_windows_datast
ream::LibRaw_windows_datastream(void *)" (??0LibRaw_windows_datastream@@QAE@PAX@
Z)
libraw_c_api.obj : error LNK2019: unresolved external symbol "__declspec(dllimpo
rt) public: int __thiscall LibRaw::COLOR(int,int)" (__imp_?COLOR@LibRaw@@QAEHHH@
Z) referenced in function _libraw_COLOR
demosaic_packs.obj : error LNK2001: unresolved external symbol "__declspec(dllim
port) public: int __thiscall LibRaw::COLOR(int,int)" (__imp_?COLOR@LibRaw@@QAEHH
H@Z)
bin\libraw.dll : fatal error LNK1120: 29 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0
\VC\BIN\cl.EXE"' : return code '0x2'

You do not need to pass

You do not need to pass anything to Makefile.msvc, all flags are set OK within this Makefile

-- Alex Tutubalin @LibRaw LLC

If you build LibRaw within

If you build LibRaw within your project, you need to set this define for compiler.

If you build LibRaw using supplied Makefile.msvc (as starting point), all things are already set-up.
Just tested with VisualStudio 2013 (it complains about /arch:SSE2, because this option is default now, but compiles LibRaw and examples OK)

-- Alex Tutubalin @LibRaw LLC

I was just trying to build

I was just trying to build LibRaw with the supplied makefile and then link the created "libraw.lib" or "libraw_static.lib" to my project. So it should already be compiled, just being read by my project when it calls the functions. Is this not an appropriate way to include the source code? It has to be compiled within my code?

You're able to build samples,

You're able to build samples, right?

Samples are build by very simple command (assuming DLL has build before):
cl $(COPT) /Feoutputfilename.exe sample-source.cpp lib\libraw.dll

You may need to adjust COPT variable (in Makefile.msvc) accoriding to your project build flags (runtime library, exception handling).

-- Alex Tutubalin @LibRaw LLC

Also, you do not need to swap

Also, you do not need to swap dllimport/export in libraw_types.h

-- Alex Tutubalin @LibRaw LLC

I've recently faced the same

I've recently faced the same problem and the reason was the following:
VS2017's option "Treat WChar_t As Built-in Type" was "No" (/Zc:wchar_t-)
By default, it's usually On.
But maybe, when I generated configurations for Target Machine: X64 from x86 by copying, it's got off? I don't know. If the settings are copied, the Zc has been Off even for X86?

Anyway, being Off, the function signatures got generated as unsigned short const * i.e. @@@UEAAHPEBG@Z instead of wchar_t const * which is @@UEAAHPEB_W@Z and the linker can't find them.