Newbie help for Visual C++ project references - c++

I know next to nothing about C++, except that I have a missing to take someone else's C++ library and wrap it for use by C#. I found a few posts about how to do it, and I'm making my way there, bit by bit. But I've hit a wall at this point.
According to this post I'm supposed to create a new managed C++ project. This I have done, and I added a reference to the project I'm supposed to be wrapping. So my code looks like this:
#include "stdafx.h"
#include "DrmWrapper.h"
#include "../OtherLibrary/drm/adept/src/adept_provider.h"
DrmWrapper::DrmWrapper(dpdrm::DRMProcessorClient * client, dpdev::Device * device)
{
adept::DRMProviderImpl * provider = new adept::DRMProviderImpl();
drm_processor_ = provider->createDRMProcessor(client, device);
}
unsigned DrmWrapper::initSignInWorkflow(unsigned workflows, const dp::String& authProvider, const dp::String& username,
const dp::String& password)
{
return drm_processor_->initSignInWorkflow(workflows, authProvider, username, password);
}
All looks good. But when I try compile my wrapper project, I get an error:
d:\src\drm-wrapper\OtherLibrary\drm\adept\src\adept_provider.h(26): fatal error C1083: Cannot open include file: 'dp_all.h': No such file or directory
Eh...whut? I'm not trying to compile the adept library. That already built fine by itself. I just want to compile my own wrapper project. And the dp_all.h file does exist, in the same folder as adept_provider.h.
Clearly there's some paradigm shift I'm not making from C# to C++; it seems like the code is being rebuilt as if the referenced project's source file were in my project folder.
What's the secret switch to get this working?

You should add ../OtherLibrary/drm/adept/src as one of the places where your project looks for header files (in C++/General/Additional Include Directories).
You should change #include "../OtherLibrary/drm/adept/src/adept_provider.h" to #include "adept_provider.h".
What's happening is that the compiler is looking for dp_all.h relative to your project not to the other project. Compilation is not totally separate in C++, headers files are shared between projects and are recompiled in each project where they are used.

Related

Visual C++ : XGBoost does not work when called from a DLL

I have a requirement to use XGBoost within a Visual C++ project DLL.
I have been able to download and build the XGBoost source using VC++ and CMake.
When I include the XGBoost code in a test console application, it works fine.
However, when I try to replicate what I've done with the console application in a DLL project, it won't compile.
I am struggling to even use a basic XGBoost type within the project.
I suspect the problem is my ignorance with DLL projects and would appreciate your help.
Here's what's happening in my DLL project:
When I use the following include as the very first line in a cpp class file, it compiles:
#include <xgboost\c_api.h>
With it compiling, if I try to use a simple type defined in this include file, the build fails with the following message:
...\dll_test\xgb_driver.cpp(20): error C2065: 'BoosterHandle': undeclared identifier
This is the line that causes the error:
BoosterHandle my_handle;
"BoosterHandle" is in fact defined in <xgboost\c_api.h>
When I put the include below any other include, I get the following error messages:
1>c:\tools\src\xgboost\include\xgboost\c_api.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\tools\src\xgboost\include\xgboost\c_api.h(29): error C2146: syntax error: missing ';' before identifier 'bst_ulong'
Below is a little more information on what I did to get XGBoost working with a console app and how I created the DLL project.
=-=-=-=-=-=
Here's what I did to use XGBoost with a console. Everything about it seems to work. I've tested the model predictions, and they are
consistent with what I'm seeing in R.
Using the documentation found here:
https://xgboost.readthedocs.io/en/latest/build.html
I downloaded the XGBoost source and built it using CMake and Visual Studio 2015.
Under Project > Linker > Input > Additional Dependencies,
I added the xgboost.lib file
Under Project > Linker > General > Additional Library Directories
I added a reference to ...\xgboost\build\Release
Under Project > VC++ Directories > Include Directories
I added the path to ...\xgboost\rabit\include and ...\xgboost\include
I put the xgboost.dll in the directory where the .exe is generated.
From here, it was smooth sailing.
=-=-=-=-=-=
Here's what I've done to create a Visual C++ DLL Project:
After choosing File > New > Project, I select an ATL DLL Project (this is part of the project requirement).
For the XGBoost include to the project, I repeated steps 1-5 above, but placed the xgboost.dll file where the
project DLL would be generated.
Here is the source for the header file for the simple class I have created:
#pragma once
class XGB_Driver
{
public:
XGB_Driver();
~XGB_Driver();
float callXGB(float sample_input);
};
Here is the source for the simple cpp file:
#include <xgboost/c_api.h>
#include "stdafx.h"
#include "XGB_Driver.h"
XGB_Driver::XGB_Driver()
{
}
XGB_Driver::~XGB_Driver()
{
}
float XGB_Driver::callXGB(float simple_input) {
BoosterHandle my_handle;
return(0);
}
Why this doesn't work for the ATL DLL project, but does for the console app really has me banging my head against the keyboard.
Your help would be very much appreciated.
Best,
Dave
With the help of CristiFati, I believe this question has been answered.
For whatever reason, it seems that using XGBoost with C++ in a DLL project requires additional includes above and beyond what is required for using it in a console application.
I am currently building the DLL project with the addition of:
#include <cstdint>

Why does "cout" keep giving me error C1083?

I was using Visual C++ 6.0 just now, and I keep getting this error:
fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
My code is just a simple hello world program.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"Hello World.";
return 1;
}
Then I went and checked my INCLUDE folder and found a file called STREAMBF, but the compiler was looking for STREAMBUF. Notice that the file that is present is missing the U, between the B and the F. This was from a good copy of VC++6.0, directly from the actual CD, not a pirated copy. So there should be all the files needed. But it appears that a file is missing! Is this MS being stupid again, and yet making another big mistake, and forgetting to include an important file on their CDs? I'd hate to think that every single CD for VC++6.0 that was pressed that came out of MS factories had this problem. And I know that it is a missing file, not just a misnamed file, as renaming STREAMBF to STREAMBUF just led to more errors.
Anybody know where I can find a copy of the file STREAMBUF? Or am I just overlooking something here? Is this exact error a known problem with running old copies of VC++ on modern OS's like Windows 7? Is it possible that the only reason that it's looking for STREAMBUF is that this is a newer file associated with Win7, and that if it was running in a different environment (an older OS), it would actually be looking for the correct file, STREAMBF? Can somebody help me here?
Your installation is either broken, deprecated or interpretes your code in wrong way.
You should only use older compiles if you are trying to build project developed entirely for this version.
Try to compile same code with new compiler, if you want to use VS then you should look for Visual Studio Express 2013.
Your code does not have any errors.
Modify your program to, you should be able to see it okay.
#include <iostream.h>
using namespace std;
int main()
{
cout<<"Hello World.";
return 1;
}
However,
your compiler is pretty old. You need to an upgrade.
There are C++ compilers for Windows from Microsoft Express Visual Studios Link and Info VS2013 to
some other non-Microsoft like GCC for Windows.
If you don't have installation access there are some portable c++ compilers.
Finally there are some online compilers for simple test. web based online compilers.
For my win 10 installation of VC 6.0, I had the same problem ... fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
Replacing with <iostream.h> does not solve the problem.
I have checked the header file installation folder (Program files\VS98\VC98\INCLUDE). For some (unknown) reason, some file names have been changed during installation. Restoring the original name has solved the problem, in my case, in example:
Turn STREAMBF into STREAMBUF, STDXCEPT into STDEXCEPT, XCEPTION into EXCEPTION, FCTIONAL into FUNCTIONAL.
Notice: other header file names might be wrong. I have listed above the file names wrong in my installation.
I hope this may help.

C++ Problems with #include <anyfile.h> when trying to compile a gstreamer app

I didn't find anything like this when I searched for it. I'm trying to make a simple gstreamer app based on code I found in another stack overflow thread. Whenever I try to compile it by going to the directory with command prompt and entering cl cppgstreamer.cc. Initially, the only include was #include <gstreamermm.h>, which gives me
cppgstreamer.cc(1) : fatal error C1083: Cannot open include file: 'gstreamermm.h
': No such file or directory
Even when I put cppgstreamer.cc into the same directory as gstreamermm.h. I then tried changing the include to
#include "C:\Users\MY_NAME\Documents\gstreamer c++\gstreamermm-0.10.10.2\gstreamer\gstreamermm.h"
with MY_NAME being replaced by my name.
This seems to work, but then it tries to do the includes in the gstreamermm.h, and they are in #include <file.h> form, so I get another fatal error C1083,except this time with init.h, or when I changed that, error.h. And they have dependencies. Is there a way that I can get my compiler to like the #include <file.h> syntax? I really don't want to go through the file and change every #include <file.h> to #include "file.h".
Sorry if this is a dumb question. I'm new to C++, although I've worked with C in the past.
I am using Microsoft Visual C++ Express 2010. Any help would be appreciated. Thanks!
You need to add the directory containing gstreamermm.h to include path. I don't have visual c++ here to check, but it's in somewhere in project properties under C/C++ .

Having trouble embedding Lua for Windows install into C++ program

This is the first question I have found myself not being able to get to the bottom of using my normal googling/stack overflowing/youtubing routine.
I am trying to compile a minimal Lua program inside of a C++ environment just to ensure my environment is ready to development. The Lua language will be later used for User Interface programming for my C++ game.
First some basic information on my environment:
Windows 7 64-bit
Visual studio 2010
Lua for Windows 5.1 (latest build I could download from google code)
Here is the code I am trying to compile:
// UserInt.cpp : Defines the entry point for the console application.
//
#pragma comment(lib,"lua5.1.dll")
#include "stdafx.h"
#ifndef __LUA_INC_H__
#define __LUA_INC_H__
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
int _tmain(int argc, _TCHAR* argv[])
{
lua_State * ls = luaL_newstate();
return 0;
}
#endif // __LUA_INC_H__
Here is the Error I am getting:
1>UserInt.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _wmain
1>c:\users\deank\documents\visual studio 2010\Projects\UserInt\Debug\UserInt.exe : fatal error LNK1120: 1 unresolved externals
Things I have tried:
I have read about lua_open()(and several other functions) no longer being used so I tried the newstate function instead. I get the same error. This was more of a sanity check than anything. I am using 5.1 and not 5.2 so I do not think this really matters.
I have also read this thread Cannot link a minimal Lua program but it does not seem to help me because I am not running the same environment as that OP. I am on a simple windows 7 and visual studio environment.
The top pragma comment line was something I saw in yet another thread. I get the same error with or without it.
I have gone into my visual studio C++ directories area and added the lua include to the includes and the lua lib to the libraries.
So it seems like my program is seeing the .h and seeing the symbol. But for some reason it is not getting the .cpp implementation for the functions. This is why I was hoping including that .dll directly would help fix the problem, but it hasn't.
So, I feel like I have exhausted all of my options solving this on my own. I hope someone is able to help me move forward here. Lua looks like an awesome language to script in and I would like to get my environment squared away for development.
I hope it is just some silly error on my part. I believe I have provided as much information as I can. If you need more specifics I will update with info if I can provide it.
Edit1
Tried the solution in this Can't build lua a project with lua in VS2010, library issue suspected
That did not work either.
You'll need to have the library (.LIB) file and add that to VS. Use Project > Properties and go to Linker > Input and add the full .lib filename to the "Additional Dependencies" line. Note that the .LIB is different from the .DLL.
Personally, I prefer adding the source code to my project, over referencing the dynamic link library. The following procedure will let you do as such.
Download the source code ( http://www.lua.org/ftp/ ), uncompress it.
In Visual Studio, choose File > New > Project and choose Visual C++, Win32, "Win32 Console Application".
In your project in Visual Studio, add all the source code, except luac.c. Also delete the main() function out of the file that VS created for you. This is usually given the name of the project you specified with the .cpp file extension. You could just remove this file all-together from the project.
Build and Run.
This is the Lua console

Loading a COM DLL

I just started using QT. Right now I need to transfer some code I have on a Visual C++ project to QT.
The only thing the project does at the moment is open photoshop and set the visible flag to false (it will be used for automation, so a lot of things will be added later).
What I do is, I import 2 photoshop dlls (NOTE: I don’t have .h or .lib for them, just the .dll files)
The method I’m using to import these dlls is through import libid, since all the other methods I tried didn’t work. They are COM objects, btw.
This is my VC++ code:
//library ID of Photoshop.dll
#import "libid:E891EE9A-D0AE-4cb4-8871-F92C0109F18E"
//library ID of PhotoshopTypeLibrary.dll
#import "libid:4B0AB3E1-80F1-11CF-86B4-444553540000"
int main()
{
Photoshop::_ApplicationPtr app( __uuidof(Photoshop::Application));
app->Visible = false;
return 0;
}
Now, QT gives me some warnings and errors on the import lines:
warning: #import is a deprecated GCC extension
error: libid:E891EE9A-D0AE-4cb4-8871-F92C0109F18E: No such file or directory
And then, after that, it says (obviously) that “Photoshop” is not declared.
Now, I searched and the closest solution I found was to include the .tlh files that were created on my VC++ project, but when I did that, I got more than 1 thousand errors and warnings, so that obviously didn’t work.
Can someone please tell me what to do here? I’m seriously stuck!