VC++ Project: unresolved external symbol HidD_GetHidGuid - visual-c++

I'm trying to build a project (for ARM) to facilitate the communication over an HID device. Here are the details of what I have:
PC with Windows 7
Visual Studio 2011 Developer Preview
WDK
A microsoft library function FindKnownHidDevices() makes a call to HidD_GetHidGuid() in my project. However, Linker doesn't like this and complains:
*error LNK2019: unresolved external symbol HidD_GetHidGuid referenced in function "unsigned char __cdecl FindKnownHidDevices*
I already have all of following workarounds in my project with no success so far:
Include hid.lib & SetupAPI.lib in Linker -> Input -> Additional Dependencings under configuration manager of VS 2011
Include hidsdi.h under "VC++ Directories -> Include Directories" in Configuration Manager of VS 2011
Include hidsdi.h in the .h version of .c file which makes a call to the function HidD_GetHidGuid() using extern "C"
What might I be missing?

If the code compiles OK, then the compiler is finding the correct header files. As the linker is failing, this suggests that it cannot find the specified .lib files.
Have you downloaded and installed the WoA SDK? The required lib files may not actually be in the linker folder for ARM targets (they're not in the default installation for Studio 11 Developer Preview).

Related

Problem compiling exiv2 code in VS 2022: Undefined Reference/symbol error

I have some code in Linux that uses exiv2 to read the metadata of a folder full of photos, depending on requirements it can reconstruct missing metadata, and stamp a logo as well as lat/long onto the photos. I'm trying to port it into windows visual studio so that I can make a GUI and let other people use it.
I downloaded the MSVS source code for exiv2, I've added the include folder and lib folders both in the include line and the linker line in the project properties dialogue. When I try to compile I get an undefined reference error whenever an EXIV2 object is called.
I'm guessing I have some sort of linking or library building issue. I built it on linux using g++ and had no problems. If I weren't trying to make a GUI I'd probably just get a windows version of g++ to compile with.
This is one of the error messages I'm getting.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::_List_iterator<class std::_List_val<struct std::_List_simple_types > > __thiscall Exiv2::ExifData::begin(void)" (_imp?begin#ExifData#Exiv2##QAE?AV?$_List_iterator#V?$_List_val#U?$_List_simple_types#VExifdatum#Exiv2###std###std###std##XZ) referenced in function "int __cdecl uptake(class std::vector<struct EANphoto,class std::allocator > &,char *,char *)" (?uptake##YAHAAV?$vector#UEANphoto##V?$allocator#UEANphoto###std###std##PAD1#Z) CAPconsole C:\Users\ [redacted] \source\repos\CAPconsole\CAPconsole.obj 1
I've tried adding include files for both the "include" and the "lib" folders to both the include line and to the linker. I also tried to compile the sample program that came with Exiv2, and I get the same error,so I'm guessing it's a VS setting issue.
So, the way to do this is as follow:
In "Properties" … "C/C++" … "General" … "Additional Include Directories", add the include and lib folders, and do the same in
"Linker" … "Additional Library Directories".
Finally, in "Linker" … "Command Line" … "Additional Options", write in "exiv2.lib".

I can't understand why it has error LNK2019 "unresolvant external symbols"

I follow the insturction to compile glpk on windows, then I got glpk_4_52.lib and glpk_4_52.dll. In my VC 2010 project, I include head file
#include "glpk.h"
and I include glpk_4_52.lib in "additional library directory".
But after compiling it still shows:
error LNK2019, "unresolvant external symbols", _glp_create_prob, referenced in _main
and similar others.
Could anyone knows what the problem is here? Thanks!d
"Additional library directory" is not the right way to add a lib file to the link.
Either,
Add glpk_4_52.lib in Configuration Properties -> Linker -> Input -> Additional Dependencies
or
Make the glpk project a dependency of your EXE project, if they are in the same solution, bu using "Project Dependencies" and make sure that Configuration Properties -> Linker -> General -> Link library dependencies is set to Yes
I am able to reproduce your problem by using the H and LIB version 4_52 from the precompiled package on SourceForge, by forcing the calling convention of my EXE to __stdcall (/Gz) (In C++->Adanced).
You should use __cdecl (/Gd) instead!

OpenNI 2 and Visual Studio 2012

I just downloaded OpenNI 2 SDK (www.openni.org) and I am trying to setup a project in Visual Studio 2012.
What I did:
Create a new C++ Win32 Console Application Project
Go to Project>MyProject Properties and, in Configuration Properties>VC++ Directories...
Added C:\Program Files (x86)\OpenNI2\Redist\; to Executable Directories
Added C:\Program Files (x86)\OpenNI2\Include\; to Include Directories
Added C:\Program Files (x86)\OpenNI2\Redist\; to Reference Directories
Added C:\Program Files (x86)\OpenNI2\Lib\; to Library Directories
But when I try to build I have the following unresolved symbol error (where ConsoleApplication1 is my project's name)
Error 1 error LNK2019: unresolved external symbol
__imp__oniInitialize referenced in function
"public: static enum openni::Status __cdecl openni::OpenNI::initialize(void)"
(?initialize#OpenNI#openni##SA?AW4Status#2#XZ)
c:\Users\MyPC\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj
ConsoleApplication1
I know this linking error is saying that the linker can't find some libraries but I thought what I just did was enough.
I also tried the 64 bit version, creating a 64 bit project, but I have the same errors.
I couldn't find satisfying documentation on this topic.
I'm sure I'm missing something silly. Can you please give some advice on this?
Also you should do the below steps:
0-In the C/C++ section, under the "General" node, select
"Additional Include Directories"
and add
"$(OPENNI2_INCLUDE)" (if you use the 32-bit version) or
"$(OPENNI2_INCLUDE64)" (if you use the 64-bit version).
These are environment variables that point to the location of the OpenNI Include directory. (The defaults are :
C:\Program Files\OpenNI2\Include or
C:\Program Files (x86)\OpenNI2\Include)
1-In the Linker section, under the "General" node, select
"Additional Library Directories"
and add
"$(OPENNI2_LIB)" (if you use the 32-bit version) or
"$(OPENNI2_LIB64)" (if you use the 64-bit version).
These are environment variables that point to the location of the OpenNI Lib directory. (The defaults are:
C:\Program Files\OpenNI2\Lib or
C:\Program Files (x86)\OpenNI2\Lib)
2-In the Linker section, under the input node, select
"Additional Dependencies"
and add
OpenNI2.lib or OpenNI2.lib
3-Ensure that you add the Additional Include and Library directories to both your Release and Debug configurations.
4-Copy all the files from OpenNI's redist directory (see environment variable "$(OPENNI2_REDIST)" or "$(OPENNI2_REDIST64)") to your working directory. (The defaults are
C:\Program Files\OpenNI2\Redist or
C:\Program Files (x86)\OpenNI2\Redist).
Be aware that when you run from command line, the working directory is the directory where the executable can be found, and where you run from Visual Studio the default directory is where the project file (.vcproj, .vcxproj) can be found.
you also need to point to the actual library file: openni2.lib
If you add all of options (Include, Lib, ...) to your project setting and again get this error, maybe your project platform is Win32 and you want to use OpenNI x64
In this case, you must change the platform to x64 (Project properties at the top of the page)
If you don't have x64 option, make a new one ;)

Compiling mex files with C++ through matlab: header files are not accessible

I need to compile a mex file which is written in C++ (VS 2008) with Matlab 2009. If I compile with VS 2008 directly, it seems Matlab is not compatible and the error is:
//Invalid MEX-file
So I tried to comile with Matlab directly using MEX function. In "mex -setup" I chose
//Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2009a\sys\lcc
to compile with Matlab, but it only compile C and not C++ and my codes are in C++.
Then I chose
//Microsoft Visual C++ 2008 SP1 in C:\Programme\Microsoft Visual Studio 9.0
to compile with VS 2008 from Matlab. For a simple test C++ file it worked. The mex file was perfect. Then I added some header files and a function to call a class in one of the header files. I added "Aria" header files to my project and the above error comes.
//Aria website where you can find header files: (http://robots.mobilerobots.com/wiki/ARIA)
Header files are in the same directory as main program, all the lib files are defined in VC++ project. In "Additional library directories" I added their path again. When I build my project through VC++, there is no error. But when I try to use MEX from Matlab, this error happens. (the name of C++ file is "test")
//
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
...
test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void _cdecl Aria::init(enum Aria::SigHandleMethod,bool,bool)" (_imp_?init#Aria##SAXW4SigHandleMethod#1#_N1#Z) referenced in function _main
test.mexw32 : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Link of 'test.mexw32' failed.
??? Error using ==> mex at 218
Unable to complete successfully.
//
To test the project, I wrote a small class in one of that header files and used that class in C++ file, and it worked! I do not know why other classes do not work. They are linked to each other and they are about 140 .h files.
Has anyone any idea why this happens?
Why there is no error when I build, release and debug project in the VC++, but when I try to compile MEX file with Matlab, this error?
All the header files and necessary libs needs to be compiled.
//mex name.cpp name.h name.lib
Here, WinMM.Lib, WSock32.Lib and AdvAPI32.Lib.

pragma and including headers/libraries

VS C++ 2008
I am just working through a DirectX tutorial.
In the source code had this line:
#pragma comment (lib, "d3d9.lib")
When I compiled everything linked ok.
However, I commented out this line and tried to include the header and library myself under properties, like this:
C/C++ - General
Additional include directories: "C:\Program Files\Microsoft DirectX SDK (August 2009)\Include"
Linker - General
Additional library directories: "C:\Program Files\Microsoft DirectX SDK (August 2009)\Lib\x64"
Linker - Input: d3d9.lib
However, I got this linker error:
1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9#4 referenced in function _initD3D
However, when I just use the pragma I didn't get any linker errors. Only when I try and include them with the properties as above.
What is the real difference in using pragma and including the header/libraries using the properites?
Many thanks,
at first, #pragma comment(lib) is just linker configuration
at second, the SDK should be in path, so dont set additional library directories (you may override it with wrong version), just add d3d9.lib to linker's input.
As far as I know, there is no difference. pragma lib simply says to the linker to look for a specific library by name.
Also, since the path is not specified in the pragma, the linker relies on the current lib paths for your project. Try not add any path to your linker options (by default DX SDK adds paths to any visual studio installed, directly modifying the global visual studio paths. See Tools/Options/Projects and Solutions/VC++ Directories/Show Directories for Library files)
Some things to check:
you are indeed building for x64
your path is really pointing to the DX SDK (it is installed to Program Files(x86) if you are on x64)
verify if there are not other linker warnings

Resources