My code starts off like this:
#include "stdafx.h"
#include <string>
#using <mscorlib.dll>
#using <System.Data.dll>
#using <System.dll>
using namespace System;
using namespace System::Data::OleDb;
but ends up with the compile error "#using" requires C++/CLI mode
I had this problem initially and managed to solve this through following this post IntelliSense: "#using" requires C++/CLI to be enabled. Updated VS2017 to ver 15.3.0 yesterday and now it is broken again. Project Properties are as follows:
Any assistance would be greatly appreciated.
P.
I came across the same issue and figured out that the settings(Common Language Runtime Support) were set only for Release configuration. I suggest you to check for all the configurations in your solutions Release/Debug etc.. and set the CLR support option and it should work as expected.
You can also control this setting from within the code by putting this in your files
#pragma managed
First I would search your code to be sure this #pragma isn't being used to turn OFF managed building somewhere earlier (in some #include file, perhaps?). Then try putting it in this file>
I'm not sure if this will solve your problem but it should at least eliminate the worry that the file is not being build properly. And perhaps the error message might change to give you a better idea what the problem is
https://msdn.microsoft.com/en-us/library/0adb9zxe.aspx?f=255&MSPPError=-2147217396
C++ CLI Correct way to use #pragma managed / unmanaged
Related
I want to programmatically create a Windows shortcut (.lnk file) to a folder. To do this, I tried this code snippet. However, I get the compilation error C2371 'WebBrowser': redefinition; different basic types in C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\exdisp.h line 2367.
Is there a C++17 std::filesystem API for this? If not, how can I fix the compilation error from above? Even with cleaned up includes, the error persists:
#include <Windows.h>
#include <shlguid.h>
#include <shobjidl_core.h>
Using the mklink command yields:
The device does not support symbolic links.
So that doesn't work either, maybe because this is an external SSD.
What else could I try?
The first answer you linked to is the correct way. And it does not rely on WebBrowser at all. It will probably help to define some of the NO_XXX macros before including windows.h.
In my version of ShlGuid.h which is slightly older than yours, I see
#ifndef NO_SHDOCVW_GUIDS
#ifndef GUID_DEFS_ONLY
#include <exdisp.h>
#include <shldisp.h>
#endif
so you can use NO_SHDOCVW_GUIDS to excise the troublesome header that you weren't wanting anyway.
If you wanted support for WebBrowser and the kitchen sink, another fix might be moving #include <windows.h> after ShlGuid.h, as shown e.g. here: https://stackoverflow.com/a/73422757/103167
Links are something that differ a fair amount from filesystem to filesystem, so difficult to standardize. Shell links (.lnk files) are filesystem-independent, but only work on MS Windows (completely non-portable) which also is a strike against finding support in a standard API.
I coded in C++ on Visual Studio (Windows 10) and got this error:
#error The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft \
and will be REMOVED. It is superseded by the C++17 <filesystem> header providing std::filesystem. \
You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.
With this headers:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <filesystem>//If I will disable it nothing happens.
#include <experimental/filesystem> //If I will disable it happens another error.
namespace fs = std::experimental::filesystem;
using namespace std;
I've tried: #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING in the main cpp file. It didnt help.
So then I paste this code from here:
#ifdef __cpp_lib_filesystem
#include <filesystem>
using fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem
#include <experimental/filesystem>
using fs = std::experimental::filesystem;
#else
#error "no filesystem support ='("
#endif
Didn't helped too.
What is the easiest way to get out that error?
Add _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to Preprocessor definitions.
Project -> Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.
This solved the issue for me.
According to the link
C++17’s is supported. This is a completely new
implementation, incompatible with the previous std::experimental
version, necessitated by symlink support, bug fixes, and changes in
standard-required behavior. Currently, including provides
the new std::filesystem and the previous
std::experimental::filesystem, and including
provides only the old experimental implementation. The experimental
implementation will be REMOVED in the next ABI-breaking release of the
libraries.
MS abandoned 'experimental' in filesystem.
You could try to use #include <filesystem>instead of #include <experimental/filesystem> and the std::experimental::filesystem is slated for removal, this means you should use std::filesystem.
I had the same problem and then, when I removed the experimental filesystem and added:
#include <filesystem>
namespace fs = std::filesystem;
I would get the error:
namespace “std” has no member “filesystem”
The solution was to go to project properties and do as instructed in the link.
VS2017: E0135 namespace "std" has no member "filesystem"
Adding the define where necessary worked for me:
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 1;
ie.
#ifdef __cpp_lib_filesystem
#include <filesystem>
namespace fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 1;
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#error "no filesystem support ='("
#endif
I've been researching this same problem for weeks, and I'm using visual studio 2019 on an Unreal Engine 4 project. It's difficult to enable c++17 headers in visual studio and make them work. A lot of people online suggests using the boost library instead, but this is my attempt in using filesystem because I don't want to deal with trying to download / import external libraries, and so here's what I know...
** Before you start coding in visual studio, you should build / compile your project and see if Visual Studios needs anything set up; for me, I had to download / setup a free license with Incredibuild (there are tutorials online if someone needs to get this setup). Incredibuild is helpful and necessary to build projects in Visual Studio (at least if you're using Unreal Engine 4), but sometimes I get 1 or 2 "errors" in visual studio, but will compile in Unreal Engine 4 because those errors aren't actually errors (people say online that Incredibuild is weird, and wanted to mention that)**
1) How to enable c++17 Headers
When trying to #include which is a c++ version 17 header, it's necessary to enable c++17: Look inside the visual studio "solution explorer" to view the project files, and right-click the project itself and open "properties". Go to the "C/C++ language" tab and switch the version to c++17 (this is easy to find this online). Unless you're doing an Unreal Engine project because there is not a "C/C++ language" tab, so instead find the "NMake" tab and in the text-box to the right of "Addition Options" type in:
/std:c++17 OR /std:c++latest (Microsoft has a list I found online of others, but these are fine)
and visual studios will recognize as a header.
2) How NOT to get c++17 namespaces to work (things I've tried)
After the headers start working you can try to finally make a namespace variable:
namespace fs = std::filesystem; => ERROR: 'std does not have a namespace or class filesystem'
OR if you also #include you can try:
namespace fs = std::experimental::filesystem; OR namespace fs = std::experimental::filesystem::v1; => ERROR: 'we want you to define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING'
how does one fix these errors?
Online, I found that adding these lines of code to your ProjectName.Build.cs file (which can be found and edited after clicking on the file in "solution explorer") instead of the original declaration for PCHUsage:
PCHUsage = PCHUsageMode.NoSharedPCHs; PrivatePCHHeaderFile = "Folder.h"; CppStandard = CppStandardVersion.Cpp17;
this did get rid of the Errors when using std::filesystem BUT caused wayyyy more problems, and seemed harmful. After looking through other websites / possible solutions, it seems people online don't know how to actually use the filesystem library in visual studio, I've been looking for working code for weeks.
if you want to try and use the std::experimental::filesystem or std::experimental::filesystem::v1, I tried #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING, but no dice.
I'm in the same boat as you man, and it looks like you didn't get much help from the previous comments. If we can't find a solution / video tutorial online, I have a plan B. Maybe we could try and write a c++17 project using some different software, or maybe we could write a program using a different software that could be launched instead of enabling c++17 into Visual Studio; for example, if you wanted to list the files in a directory, make an executable file in your preferred other software, and launch that executable / feed it arguments from your visual studio project. That's the best I got man. I hope that sparks some creativity or whatever, but I think it's a lot more helpful than what I've seen online. Good luck to you! and I need that luck too
I am using visual studio 2012 with a clr library that needs to link to a native library.
My library which is using boost::future.
I am having this problem when I use future::then(F &&) function against the managed project:
Error 910 error LNK2022: metadata operation failed (8013119F) : A TypeRef exists which should, but does not, have a corresponding TypeDef: (dummy): (0x0100003e). D:\ClrProject\somefile.obj
I tried, as suggested in other questions, to make the dummy types in the library complete, since I cannot forward declare a nested struct from inside a template, as can be done with boost::thread::dummy struct.
This did not solve the problem.
My setup is the following:
Boost 1.55.
Using boost .dlls.
define BOOST_RESULT_OF_USE_DECLTYPE
define BOOST_THREAD_PROVIDES_FUTURE
define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
I am using these very defines on the dependent .dll as well, to make sure that all parts of the API are exposed correctly.
Solved.
#Hans Passant your suggestion was right. I just wasn't putting the #pragma the correct way.
I had to put the pragmas so that my headers are compiled as unmanaged code. Once that was done, it seems that template instantiations for my code were emitted as unmanaged. At that point, problems disappeared.
So what I did is something like this:
#pragma managed(push, off)
#include "MyHeaderWithFutures.h"
#pragma managed(pop)
void f() {
//
f = myObject.Something().then(...);
}
I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.
I want to use Directory.GetFiles to read files from a folder. From msdn website i found:
For c, i have include:
using System;
using System.IO;
For C++, i have include:
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
as header.
For the C++, after the line #using is added, the "fatal error C1190: managed targeted code requires a '/clr' option" appears. So i tried by adding /clr in the visual studio Properties\Linker\Command Line as i found it in other website, but i fail too.
I did it wrongly. So, How to handle error of "fatal error C1190: managed targeted code requires a '/clr' option"? How to "compile with the /clr flag"?
Because i am writing for OpenCv, i have include the following additional dependencies in order to use c and c++:
cv210d.lib
cxcore210d.lib
highgui210d.lib
cvaux210d.lib
Cannot work. What other requirements in order to use Directory.GetFiles?
I also cannot use foreach even i #include .
Is there something similar to use foreach and Directory.GetFiles which is necessary to be included in a project?
I am using Visual Studio 2008
Please help me. Tq
You need to create managed c++ CLI, this should include all the flags for you.
To set /clr from visual studio, go to porject properities->configurations properities->general set common language runtime support to /clr