OpenNI 2 and Visual Studio 2012 - 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 ;)

Related

Custom media effect in Win10 Universal App

I'm developing an Universal Windows App that uses the camera and I need to create a custom effect for the camera. The app is written in C# and the effect is a C++ DLL that uses Media Foundation and an IDL to define a custom WinRT component.
I already successfully do this several times on Windows 8.1 with the following trick documented here, or here.
I now want to port this on Windows 10 UWP. I'm aware there is a known issue on Windows 10 which make the compiler fail with the error "Failed to load a dependency file. Windows.winmd" (see here). But even with that fix, I'm not able to successfully build the component.
Here is the IDL:
import "Windows.Media.idl";
#include <sdkddkver.h>
namespace MyEffect
{
[version(NTDDI_WIN10), activatable(NTDDI_WIN10)]
runtimeclass MyEffect
{
[default] interface Windows.Media.IMediaExtension;
}
}
The MIDL command line (formatted for better readability):
/env win32 /h "MyEffect_h.h" /W1 /char signed /enum_class
/tlb "$(OutDir)\MyEffect.tlb" /ns_prefix
/metadata_dir "$(WindowsSDK_MetadataFoundationPath)"
/nologo /winrt
/winmd "$(OutDir)\MyEffect.winmd"
This command succeeds. Then I add the following custom build step:
mdmerge -metadata_dir “<metadata_dir>”
-i “$(OutDir).”
-o “$(OutDir)merged”
-partial
-v
and this command fails always with different errors according to the following :
If I put $(WindowsSDK_MetadataFoundationPath), which resolves to c:\Program Files (x86)\Windows Kits\10\References\windows.foundation.foundationcontract\1.0.0.0, or $(WindowsSDK_MetadataPath), which resolves to c:\Program Files (x86)\Windows Kits\10\References it returns the error:
MDMERGE : error MDM2002: The type "Windows.Media.IMediaExtension" defined in file <...>\MyEffect.winmd was referenced by type MyEffect.MyEffect but could not be found.
If I put $(TargetPlatformSdkMetadataLocation), which resolves to c:\Program Files (x86)\Windows Kits\10\References\CommonConfiguration\Neutral, it returns the error:
MDMERGE : error MDM2012: Error 3 has occured while enumerating files in C:\Program Files (x86)\Windows Kits\10\References\CommonConfiguration\Neutral\*.winmd.
Does anyone figured out how to compile a custom Windows Media effect for UWP ?
Setting -metadata_dir to "C:\Program Files (x86)\Windows Kits\10\UnionMetadata" worked for me.

how to compile in vc++ without .dsw workspace file?

I downloaded a source code from codeproject.com
In the zip file only .cpp files and .hpp files were present but no .dsw (vc++ work space) file.
how to compile the files in vc++.
source code link: http://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-and-Write-to-Microsoft
As far as I know, vc++ requires a dsw. That said, you can easily create one by creating a project + workspace and add import all the files into the project.
Unless the code requires special compile options (unlikely if it comes without a project file), this should work fine.
When you compile in VisualC++ cl.exe is executed in order to compile a s program.
So a way to compile that does not require dsw file might be running compilation in command line. This is an example for a source file main.cpp:
call vsvars32.bat && cl /MD /Od /EHsc /GR /Zi /Oy- main.cpp
On my computer the full path to vsvars32.bat is
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat
dsw is an ancient format, and is replaced by .sln and .vcxproj files. What I would suggest would be File -> New -> Project from existing code, browse to the directory with the cpp/hpp files and let Visual Studio create the project with default compiler switches - so you won't have to run cl.exe from the command line as suggested here.
That being said, the chances of circa-2006 c++ code to work on IDEs 4 versions later are small. You will almost certainly have to understand and fix the code - or find a more recent one that does what you need.

Build boost.thread - lib file not found

I am trying to build the boost.thread library for Visual Studio 9.0. I used bjam to build the lib-files:
bjam toolset=msvc-9.0 variant=release threading=multi link=shared
The compilation succeeded and I got plenty of .lib and .dll files under boost/stage/lib.
Then I added include path and the above lib path to Visual Studio 9.0.
But when I try to compile some program, I always get the following error:
libboost_thread-vc90-mt-s-1_49.lib cannot be opened.
The lib file created by the build has slightly another name:
boost_thread-vc90-mt-1_49.lib
I tried to rename my file to match the expected name, but Visual Studio still cannot find the file.
It seems that the filename beeing seaarched depends on the project option "C/C++ / Code generation / runtime library". I need the option "Multithreaded /MT".
What am I doing wrong?
Thank you in advance.
You're trying to link statically with CRT, but dynamically - with Boost. This is not a good idea, but if you insist, you should define BOOST_ALL_DYN_LINK macro.
Better option would be to select /MD in your project options, or to set "link=static" when building boost.

VC++ Project: unresolved external symbol HidD_GetHidGuid

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).

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