I'm trying to compile some code from a Windows API. It says that certain .lib and .h files must be included in the version of the Windows 7 SDK I am using. Visual Studio shows the .h files, but gives linker errors (L2019) when I try to build the project.
How can I check what version of the Win7 SDK I have, and how can I see if it includes the necessary .lib files?
Did you actually tell the linker that it should link the corresponding .lib file? The project templates only link the most popular .lib files, kernel32.lib, user32.lib etc. If you use an "unusual" API function then you must also tell the linker to link the import library.
Project + Properties, Linker, Input, Additional Dependencies. If you don't know what .lib is needed then look in the SDK documentation for the API function. The .lib file is listed at the bottom of the article.
Another thing you can do is use a #pragma in your source code to tell the linker to link with a .lib. For example:
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib") // NOTE: need to link this .lib to get shell functions
Possible solution: Go to "C:\Program Files\Microsoft SDKs\Windows" and see if there is a version installed (or if that path exists at all).
Related
Pulling out my hair on what should be a simple issue with using VC++ and being unable to access the default includes.
After installing Visual Studio 2015 RC, I can no longer build C/C++ projects. I receive "IntelliSense: cannot open source file '*.h'" errors for all the various standard library *.h files.
I confirmed that my files do exist in the default locations (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include), and if I right-click on my #include <cstdio> line in the editor I can choose "Open Document" and it even opens automatically in the editor.
My Include Directories string in the Project Settings is:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include;C:\Users\Kristopher\Libraries\Includes;$(VC_IncludePath);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);
Has anyone else run into this? I feel like I'm overlooking something simple.
Your IncludePath should not specify the Visual C++ and Windows SDK include paths directly. Instead, it should specify only the paths specific to your project and derive from the IncludePath defined in the common C++ MSBuild targets. E.g.,
<IncludePath>C:\Users\Kristopher\Libraries\Includes;$(IncludePath)</IncludePath>
To address your particular case: In Visual C++ 2015, the bulk of the C Runtime (CRT) has been refactored into a new Windows operating system component, the Universal CRT. Its headers and libraries are now in a different location and your project fails to include this include path into the IncludePath property. Specifically, you need to include $(UniversalCRT_IncludePath). For more details, see the article I wrote earlier this year, "Introducing the Universal CRT."
I have an application that uses windows.h but I am tasked with removing the calls to Windows functions.
I am using Visual Studio Express 2010 and when I delete the #include "windows.h" line the code is still able to compile and I can right click and "Go To Definition" for all the variables associate with the windows include file.
I removed $(WindowsSdkDir)include; from the VC++ Directories in the Configuration Properties page but that didn't seem to make a difference. I believed that could be the case because windows.h can be found at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windows.h on my computer.
How do I completely break this link so Visual Studio can give me errors for all calls to that library?
Use the /showIncludes command switch to search for indirect includes of windows.h
http://msdn.microsoft.com/en-us/library/hdkef6tk.aspx
I dont have visual studio 2008 installed.I am using 2012 and i rebuild this projects by cleaning.I checked the project settings and controlled the additional libraries and unfortunately I couldnt find any lib link has this name...in project just .h files of date_time are used but no lib linking. I configured new version of boost but STILL it wants this lib ? so is there any way I can solve this problem ?
With Visual Studio, boost use an auto linking system.
Special code in Boost header files detects your compiler options and
uses that information to encode the name of the correct library into
your object files; the linker selects the library with that name from
the directories you've told it to search.
date_time is one of boost modules that need a library (which is not header only).
So, you have to build them, using bjam (and --toolset=msvc-9.0), or retrieve them already built for your system.
Other option: disable auto linking. Just define
BOOST_DATE_TIME_NO_LIB
And link manually.
I am trying to use the M4RI package for C++. I downloaded the source for M4RI and ran the packaged VS project. It created m4ri.dll (no .lib files).
Now I want to "add" this dll file to a different VS2010 C++ project so I can use the M4RI library.
I already #include m4ri.h, but still get linking errors. How do I add this reference to the VS project?
Thanks in advance.
My solution:
I am not familiar with the differences between C and C++, but this seems to be the issue. To get the M4RI library to build, I had to explicitly tell it to compile with C++ (Properties->C/C++->Advanced->Compile As: "Compile as C++")
I'm not sure if this caused my problem, or if it is unrelated.
To be able to use the library, I had to modify "m4ri.h" to remove the #ifdef __cplusplus sections. As soon as those precompiler directives were removed, I was able to link to M4RI easily.
I would appreciate if someone could explain why this fixed the problem.
Thanks!
Linking errors can come from many things. Are your link errors related to m4ri? With dlls, you usually get a an export lib which should be included in your project.
I have a makefile project that builds and links a DLL, using the command-line cl.exe compiler, which is included in the VC++ Express (free) tool. I now want to convert that makefile project into a Visual Studio project.
The DLL is not actually C++; it's all written in C.
The DLL exports a small number of symbols, functions that are called by other programs that link to the DLL. I believe that in order to produce this DLL, I need to include an /EXPORT:Foo statement on the link command line, for each exported symbol.
How do I do the same in Visual Studio 2008? How do I specify the linker options to export a specific, small set of functions from the DLL?
See the first couple of subsections of Exporting from a DLL, which says,
You can export functions from a DLL
using two methods:
Create a module definition (.def) file
and use the .def file when building
the DLL. Use this approach if you want
to export functions from your DLL by
ordinal rather than by name.
Use the keyword __declspec(dllexport)
in the function's definition.
You will have to use the "Additional Options" in the linker "Command Line" property and add the options explicitly.
I think that most people use the __declspec(dllexport) attributes along with macros to make it more usable and to make the declspec a dllimport version in the headers for clients of the library.
or you can try:
cl /LD hellodll.cpp /link /EXPORT:func01 /EXPORT:func01
for functions that is not specified by "_declspec(dllexport)"
I don't see a GUI option for it, so you could just add it manually under Command Line under Linker in the project's Properties. I think most people use a DEF file for this, though.