Upon using PKEY_Device_FriendlyName, I'm getting the following errors:
Error 1 error LNK2001: unresolved external symbol _PKEY_Device_FriendlyName DefaultAudioDeviceCPP.obj
Error 2 fatal error LNK1120: 1 unresolved externals C:\Users\srobertson\Documents\Visual Studio 2005\Projects\DefaultAudioDeviceCPP\Debug\DefaultAudioDeviceCPP.exe
What's a very simple way to clear these errors? I'm including functiondiscovery.h and functiondiscoverykeys.h. Also the path in Project->Properties...->Configuration Properties->C/C++->General->Additional Include Directories is correct.
EDIT: One thing of interest is that the errors are mentioning: _PKEY_Device_FriendlyName, not PKEY_Device_FriendlyName. But I'm only using the latter in my program.
Old post, but hopefully this answer will save someone some time.
I was having the same problem with DEVPKEY properties - like DEVPKEY_Device_FriendlyName. I got a very similar link error. I stumbled upon the answer in comments here:
Referencing GUIDs
Basically, add an #include before the include for things like devpkey.h where the property keys are defined.
So, at the top of my file I have:
#include <setupapi.h>
#include <initguid.h> // Put this in to get rid of linker errors.
#include <devpkey.h> // Property keys defined here are now defined inline.
An updated solution that worked for me, as per the microsoft docs
#include <functiondiscoverykeys.h>
PKEY_Device_FriendlyName resides in uuid.lib library. So you need to add a line to your source code:
#pragma comment(lib, "uuid.lib")
Most often, you can check with MSDN which library you need to reference.
Related
I've been trying to set up a CPPUnitTest to test a C++ project. I've came across an error where I've got two rotating errors depending on how I try to solve my problem.
I've got two projects in a solution in Visual Studio. One is for testing, one is for the project itself. I'm having these errors whilst trying to reference the project in the testing project.
If I do this, I get a LNK2019 (unresolved external symbol) error any time I try to construct an object or call a function:
#pragma once
#ifndef REFERENCE_H
#define REFERENCE_H
#include "../Stuff/Thing.h"
#include "../Stuff/OtherThing.h"
#endif
However, if I do this, I get a LNK2005 (test2.obj: blahblahlblah is already defined in test1.obj) error since two of the tests reference it:
#pragma once
#ifndef REFERENCE_H
#define REFERENCE_H
#include "../Stuff/Thing.cpp"
#include "../Stuff/OtherThing.cpp"
#endif
Deleting one of the tests fixes the problem with the latter (.cpp) but obviously that's not very good.
I think I may have missed a step somewhere along the way but I'm not sure what it is. I did add the "project" project as a dependency to the test.
Does anyone have the solution to this?
I had a solution named fun.sln with a project called fun.vcxproj.
I created a whole bunch of name spaces ready to be used.
I made another project called no_more_fun.vcxproj.
I added the includes directory for fun.vcxproj to the configuration of no_more_fun.vcxproj.
I added this to no_more_fun.cpp
#include "candy.h"
void main(void)
{
candy::get();
return;
}
candy.h is in the default directory for fun.vcxproj(which was added to the config)
But I get...
LNK2001 unresolved external symbol "int __cdecl candy::get(unsigned long)" (?get#candy##YAHK#Z) .....
Visual Studio shows no error before compiling.
The "candy" namespace works fine in the "fun" project so idn...
Is there a guide or something so that i can understand how i can go about sharing code efficiently among different projects within ONE solution?
This is a linker error. You didn't get any error at compile time, because the compiler found the candy::get() method in candy.h header, but the implementation (which I suppose is in a candy.cpp file) is not found by the linker.
Just add candy.cpp too to no_more_fun.vcxproj.
ps. I didn't observe but in the error message you can see that the function waits a parameter.
call it like this:
unsigned long foo = 0;
candy::get(foo);
This is going to sounds stupid but...i just dragged the files in to visual studio so that the no_more_fun project had the "files" in its "directory" too.
wow... I shouldn't need to do that...Am I wrong?(sarcasm).
I have several global critical sections that need visibility across 3 or more classes defined in 3 or more .cpp files. They're defined in an h file as:
GlobalCS.h
#pragma once
#include "stdafx.h"
extern CRITICAL_SECTION g_cs1;
extern CRITICAL_SECTION g_cs2;
etc...
In a GlobalCS.cpp they are defined
#include "stdafx.h"
#include "GlobalCS.h"
CRITICAL_SECTION g_cs1;
CRITICAL_SECTION g_cs2;
Then in the cpp for the classes they need to work in they're included as
#include "stdafx.h"
#include "GlobalCS.h"
The linker is complaining giving unresolved external in the files where the critical sections are being used. I didn't expect this since the variables are defined as extern. What am I doing wrong or how do I get around this?
error LNK2001: unresolved external symbol "struct _RTL_CRITICAL_SECTION g_CS_SymbolStrPlotAccess" (?g_CS_SymbolStrPlotAccess##3U_RTL_CRITICAL_SECTION##A)
Not sure why you are getting the error. I tried the same thing in Visual Studio and in _tmain function I wrote the following:
int _tmain(int argc, _TCHAR* argv[])
{
//::g_cs1;
ZeroMemory(&g_cs1, sizeof(::g_cs1));
return 0;
}
And it built with no issues whatsoever.
Thank you all for your help. It always is helpful to have sanity checks. The issue was once again Visual Studio setup. Visual Studio will generate link errors if it doesn't like the way you have files added to your project. This is the second bug I've encountered that generated a link error based on the way the project was configured. If it's that important VS should either prevent you from modifying a project in a harmful way or provide a proper error message.
Anyway, the error is the same as this one:
LNK2019 Error under Visual Studio 2010
I had the GlobalCS.h and GlobalCS.cpp in the source directory. I prefer it this way because I find it makes finding files and code faster and in a large c++ project, just moving around the code base is a significant time waster. So much time could be saved writing c++ code if the IDE was designed to help find code faster. 2012 is A LOT better than 2010 so I'll give MSFT that but there could be a lot more features to that end (afterall VS has been around for almost 2 decades now)these types of persistent problems just get in the way of development. When I moved GlobalCS.h to the Header folder and cleaned the project and rebuilt, everything compiled as expected. The other similar error VS will throw at you is when the .h file is in the code directory (so #includes work) but not in the project. I got the same error messages when that happened and it took a good couple days to figure that one out. In a small project, it might not be as problematic but in big solution with multiple projects and dozens of files, it can be problematic.
I want to use WinHTTP to do some HTTP requests. Really basic stuff, but WinHTTP seems to be kind of complex compared to what I actually just want to do.
Well, I couldn't even get this example code from the msdn to work:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384270%28v=vs.85%29.aspx#code-snippet-1
What I tried is the following:
I created a new win32 console app with precomp header in VC++ 2010.
I added these includes:
#include <windows.h>
#include <winhttp.h>
and put the example code in the _tmain function.
When I try to compile it I get the following error:
WinHttpTestings.obj : error LNK2019: unresolved external symbol __imp__[FUNCTIONNAME]#4 referenced in function _wmain
For every WinHttp function called.
I hope you can help me out, sorry for being such a noob.
I have started with DirectX 11 and get these compilation errors:
Error 1 error LNK2019: unresolved external symbol wWinMain#16 referenced in function __tmainCRTStartup
Error 2 error LNK1120: 1 unresolved externals(I figure that this error is because of the error just above this one)
I have searched around for fixes to this problem for quite a while, yet I cannot find any fixes to this problem on this site or any other sites via google.
I am using Visual Studio 2012 and c++ for this project. To make my testing project I created an empty project via New Project->Visual C++->Empty Project.
I am using the standard compiler for this project.
This is my wWinMain header in my main.cpp file:
int wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
LPWSTR cmdLine, int cmdShow)
IntelliSense also keeps throwing up "4 IntelliSense: '#' not expected here" errors on some include lines at the start of the file, these lines: (EDIT: the errors keep disappearing and reappearing, repeatedly)
#include <Windows.h>
#include <memory>
#include "BlankDemo.h"
#include <tchar.h>
I put that in my post as I thought that this may be effected by, or have something to do with the error, it could just be the include files. BlankDemo.h is the header file for a test demo that just produces a blank DirectX 11 window.
All the code I have used is from a book on DirectX; as I am not used to DirectX yet, I have tried a number of fixes and none seem to get rid of this error, the fixes being:
Going to Properties->Configuration Properties->General->Character Set and changing that to "Use Unicode Character Set".
After changing the character set the error still remains.
Going to Properties->Linker->System and changing SubSystem to Windows (/SUBSYSTEM:WINDOWS).
I have also tried changing this to Console (/SUBSYSTEM:CONSOLE), neither of these changes seem to fix the problem.
I have also gone to Properties->Linker->Command Line and added /ENTRY:"wWinMainCRTStartup" to "Additional Options", this does not fix the problem either.
I have still left changes to the project as detailed above in the project. I have only put in the few lines of code as the errors seem to be about the code I have put in this post, also when I copy and paste the code, it does not seem to format correctly, but please tell me if you need to see more code.
EDIT: I have changed the function to int WINAPI __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
LPWSTR cmdLine, int cmdShow)
Even using __stdcall or WINAPI in the function name does not work it seems. At least, in the way I have used them, please tell me if this is incorrect.
Sorry guys, it seems that I made mistakes here, as in; I did not use Unicode to start off with, under Properties->Configuration Properties->General->Character Set. It seems that by using the Multi-Byte Character set to start off with, this confused Visual Studio 2012 into thinking that I was using the Multi-Byte Character set instead. This caused it to throw up the error, even though the entry point under Properties->Linker->Advanced was set to wWinMainCRTStartup. Makes sense, as the characters were not recognised properly.