I had a C++ project which was running perfectly. Now I copied the project to another folder and added the project to a WPF application solution.
Now the C++ project is giving me lot of build errors. One of them is "System' : a namespace with this name does not exist".
Below are the lines which creates this error.
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
The above lines are in AssemblyInfo.cpp file. I don't have any experience of C++, so finding it difficult to remove the errors. Any help is appreciated. Below is another error which might be helpful for you to resolve the issue.
managed targeted code requires a '/clr' option
Thanks in advance.
Set Common Language RunTime Support to be "Common Language RunTime Support (/clr)" in 2 places in your project properties :
For Visual Studio before 2019:
Configuration Properties -> General
Configuration Properties -> C/C++ -> General
For Visual Studio 2019:
Configuration Properties -> Advanced -> C++/CLI Properties
Configuration Properties -> C/C++ -> General
Mif's answer was a little incomplete for me. If you still have the issue, you'd might want to check if you set the correct C++-version.
For me it specifically needed ISO C++17 because the VS default preset ISO C++14 (at least a preset in my version) does not support the required CLI-packages. Thus, still set the Runtime support to Common Language RunTime Support (/clr) and set the correct C++ Language Standard in the Configuration Properties -> General tab.
Note: As of now (October 2021) ISO C++20 is currently not supported in CLI and will also fail to find System - I only found the 17-version to be compatible.
Since its a little easer the visual way, here the screenshots. And also don't forget Yinon_90's hint to have the version as well as dependencies installed!
It was not enough for me when I just changed "Common Language RunTime Support (/ clr)".
I had to create the project in VS which would be a dedicated project for CLR:
If you cannot see this option, you should add it in the VS installer first:
Related
For some reason I cannot choose C++ language standard in Visual Studio. By saying that I mean next thing:
I can go to the properties and choose the language standard but Visual Studio doesnt see that. How did I came to that: I tried to include filesystem header with setting the C++17 standard set but then I saw that filesystem is not a member of std namespace:
First, I thought that it was not an C++17 standard so I double checked that. After me checking all the stuff again I decided to go to the header file and check the stuff going wrong. I saw that _HAS_CXX17 is disabled although in properties C++17 is set:
I have no additional libraries connected in properties and this version of Visual studio has to be working with all of that C++17 headers because I had to work with them and still can compile these projects I've been working on, but I can't switch standard on any project now. No library were installed during period it were working last time. I updated Visual studio recently but it didnt help althought on other PC everything is working perfectly.
Properties:
I am simply adding the answer from the comments above since this helped me as well. Credit goes to Ted Lyngmo.
When changing properties, make sure either that the properties editing window is set to all configurations, or at least matches your current configuration (i. e., if you are on Debug x64, make sure those are the properties you are editing for). But if you want the property to be applied for all configurations, select All configurations on the properties editor.
Snippet showing the properties editor below the configuration selector, in this case they don't match and it'll look like the property changes were ignored
I am new to WebRTC, and I started with installing the ready-to-use library package available at Sourcey.
Using VS2017 I created a simple "hello world" console application which includes one of the webrtc native API headers.
I added the additional include path (Project config > C++ > general > add. include) and link path (Project config > Linker > add. library path).
But I got a lot of compile errors: from them I dreived that the Windows platform was not recognised, and it tried to include Unix* Headers like instead. So first fix was to add WEBRTC_WIN to the preprocessor symbols.
Still I got many (1076) other errors, mostly dubious, e.g. complaining about '::' in std::numeric_limits<int>::max() .
Second fix: I added #define NOMINMAX in my source file. It seems that Windows usually defines macros min() and max() which corrupt the c++ code.
So now 2 errors, complaining about _vsnwprintf() function maybe being not safe. As it recommended I set _CRT_SECURE_NO_WARNINGS but had to do this in the project configuration, it was not enough to set it in the source file including!
Lack of documentation on these problems with the native WebRTC libs is really annoying! Also not in the forum Google discuss webrtc. More user experiences? Tipps?
Edit: I found a nice tutorial which discourages directly using Native API and instead recommends using QT Wrapper: Tutorial
I have some c++ projects where it consists of both managed and unmanaged c++ projects.
How do I identify which project is managed c++ and which project is unmanaged c++ type.
Along with above could someone brief me what exactly these managed and unmanaged c++ means.
Go to the project properties, General "block"
Project Defaults Section
Common Language Runtime Support option
If this option is not set to "No Common Language Runtime Support", then it is "managed" C++, which in any modern version of Visual Studio is C++/CLI (unless the setting is "Old Syntax", then it is the original managed C++ syntax).
References:
Managed Extensions for C++ (old syntax)
C++/CLI
Go to project properties -> C++ -> Command Line
If it contains /clr then the project is build under C++/CLI, otherwise it's "unmanaged".
I am trying to use the Console::SetCursorPosition(int, int) method. When I add the line using namespace System;, as shown in the C++ example from the preceding MSDN documentation, I get the error "Error: name must be a namespace name". I have been trying stuff for a couple hours now, but frustratingly without success. I have come across a ton of documentation for Visual Studio 2010 and 2012, but very little for 2013. The closest I have come is Lib Files as Linker Input. Steps 1-3 are easy enough, but step 4 is not clear to me: "Modify the Additional Dependencies property.". Looking at what is already there, it seems like I can just add a .lib file. But I don't have a System.lib.
So frustrated, so confused.
How can I use the System namespace in Visual Studio 2013 Update 4 for C++?
To formalize and expand on my comment, the Console class and generally the System namespace are part of the .NET framework.
In that context, the "C++" tab included in the MSDN documentation page of the Console::SetCursorPosition(int, int) method actually refers to the C++/CLI language. The C++/CLI language is distinct (although intentionally similar) from the C++ language. Correspondingly, the C++/CLI language contains various constructs which are not recognized by the C++ compiler toolset used when compiling Win32 projects.
In other words, to get rid of the "Error: name must be a namespace name" error, you would need to convert your Win32 C++ project to a CLR project. The easiest way to do that would be to create a new project, selecting one of the templates under "Visual C++" / "CLR":
The equivalent of .lib file depdendencies (relative to your Lib Files as Linker Input link) of Win32 projects for CLR project would be assembly references. You'd then typically add those assembly references with "Add References" under "Common Properties , References" project properties:
However, in your specific case you may very well find out that the System assembly reference is already included as part of the CLR project template.
You may want to check How to: Add or Remove References on MSDN for more details.
Finally, if you absolutely want to manually convert an existing Win32 project, you would need to set the "Common Language Runtime Support" project properties under "General" and the "C/C++ , General" tabs to one of /clr, /clr:pure, /clr:safe or /clr:oldSyntax (depending on your specific application requirements; if you're just toying around you might want to start with /clr) for all Configurations and Platforms as well as specify the targeted .Net framework version by directly editing the .vcxproj (as indicated in this answer). You would also still need to add assembly dependencies as with the new project approach above.
You have to set Common Language Runtime Support (/clr) in Configuration Properties - General:
And in Configuration Properties - C/C++ - General:
You are having a project of Win32 Console Application and and you are using .NET namespace. In Win32 Console Application only 4-5 namespace are there in standard library including std. Try using namespace std; at the top.
We just got a new developer and I'm trying to set him up with Dev Studio 2005 (The version we all use at this office), and we're running into a weird problem that I've never seen before.
I have some code that works perfectly on my system, and he can't seem to get it compiled. We've tracked the issue down to his copy of dev studio ignoring the preprocessor directives.
For example, in the project properties under C/C++|Preprocessor|Preprocessor Directives, I add DEFINE_ME. Which should translate to a /D"DEFINE_ME" for the compiler. And it does in my development environment, but it doesn't on his.
I verified that when he checks out the code from the source repository, that he has the same version of the code I do. And if I look in his Project Properties, all of the directives are there. For some reason they're just not getting passed down to the compiler.
Any Ideas?
I recently ran into the same symptom with VS2005. Ultimately I was able to resolve it by explicitly adding my preprocessor defines via the Command Line - Additional options dialog:
Configuration Properties -> C/C++ -> Command Line
When I added '/DPROPERTY' there it was recognized at compile time, whereas adding it under 'Preprocessor -> Preprocessor Definitions' did nothing. Oddly the Command Line dialog did show that Visual Studio was adding the property to the command line, albeit in the form '/D "PROPERTY"'.
Unfortunately schedule pressure being what it is I have not been able to dig into the issue deep enough to figure out what the underlying issue was/is, nor why it seems to work out of the box for some of our projects but not others. Nonetheless the workaround above is worth a shot if you're having this symptom.
Also, credit where credit is due: the idea came from this thread.
Make sure that the project configuration which is being built in the selected solution configuration is the same as the one you're configuring the properties for, and/or that you're configuring the properties for all project configurations. A common problem with new VS installations is that the current active solution configuration is system-specific, and may default to something not matching yours (eg: Release vs Debug).
You can see the project config in the build output, and/or check it in the Configuration Manager.