error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012 - c++

I had a project running in Visual Studio 2010. Now I am using Visual Studio 2012.
Now I am getting below error while building the project.
I have looked into Google and SO as well. But no where I got any solution.
c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(562): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(574): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(579): error C2065: 'errno' : undeclared identifier
I have tried with including stdlib.h into the sting header file but still I am getting this same error.
Any help appreciated.

There could be several possible reasons for this problem. The
first thing you should do is to create a one line source:
#include <string>
and nothing else, and try to compile it. If this doesn't
compile, there is a problem with your installation, and you
should reinstall it. Then, just to be sure, delete everything
in your source tree except the actual sources, project files and
solution, and rebuild. There may be some old files laying
around which are somehow causing the problem. I doubt it, but
this is something you should do anyway, any time you upgrade
a compiler, or even just install a patch. (If you've got
everything under source code control, which you should, the
simplest solution is just to delete everything, and do a new,
clean checkout.)
If these measures don't solve the problem (and somehow,
I suspect they won't), there's a problem in your code base
somewhere. errno is required to be a macro by the standard;
to get the error message you cite, the macro must be undefined.
<string> includes (indirectly) a file which defines it. Given
this, the only cause I can think of is that an earlier include
file has already included a file which defines errno, and then
#undefed it. To verify this, put your #include <string> as
the very first include of your source, and see if this solves
the problem. If it does, then you have to find the file which
does the #undef, and fix it.

I had the same issue. Strangely enough, the problem was not including "using namespace std;" under the header file includes. Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized.

Related

Using vcpkg and compiling in Visual Studio 2015

I am trying to compile (by porting) some code in Windows 10 that was originally developed for Linux.
The code depends on 2 external libraries: cppkafka and librdkafka.
I saw that vcpkg is able to get the libraries, compile them, and then make them automatically available in Visual Studio 2015 (through the vcpkg integrate install command).
I see that the vcpkg compiles the dependencies for windows 64 (cppkafka and librdkafka) properly, as the .dll, .lib... are all made available on the install folder of vcpkg.
When I try compiling my code in Visual Studio 2015, I see errors concerning the dependencies headers, which for me is unexpected. If vcpkg compiled them, why Visual Studio doesn't? From the vcpkg documentation, I assume they use the same compiler. Next I show some example errors I am getting:
1>------ Build started: Project: AndreKafkaDriver, Configuration: Release x64 ------
1>C:\...\vcpkg\installed\x64-windows\include\librdkafka/rdkafka.h(64): error C2371: 'ssize_t': redefinition; different basic types
1> C:\Siemens\Automation\WinCC_OA\3.16\api\include\winnt\win32.h(47): note: see declaration of 'ssize_t'
1>c:\...\vcpkg\installed\x64-windows\include\cppkafka\header_list.h(265): warning C4267: 'argument': conversion from 'size_t' to 'ssize_t', possible loss of data
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'queue1': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'queue2': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'mutex': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2275: 'std::mutex': illegal use of this type as an expression
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): note: see declaration of 'std::mutex'
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2182: 'swap_queues': illegal use of type 'void'
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2470: 'cppkafka::BufferedProducer<BufferType,Allocator>::swap_queues': looks like a function definition, but there is no parameter list; skipping apparent body
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2072: 'cppkafka::BufferedProducer<BufferType,Allocator>::swap_queues': initialization of a function
1>kafkaHWService.cxx(29): fatal error C1083: Cannot open include file: 'execinfo.h': No such file or directory
...
Thanks in advance,
Nerea

std::filesystem doesn't work in DLL project

I feel sorta silly asking this question, but I just cannot find a solution anywhere on the internet.
Notes:
I am using VS2019
C++17 is enabled
My problem is the following:
I want to iterate files in a directory with std::filesystem. To do so, I need to use the directory_iterator. However, when I include the filesystem library, it doesn't find the directory_iterator, so I checked the filesystem header file. It threw me a bunch of errors. I also cannot use experimental/filesystem because for some reason the path class also has errors which make the string functions unusable.
However, when I create a fresh console application, it works fine for me. No errors, directory_iterator has been found, I can iterate without issues.
Here is a small snippet of what the errors I'm being given when trying to compile:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(917,28): warning C4003: not enough arguments for function-like macro invocation 'concat'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2365: '_InIt': redefinition; previous definition was 'template parameter'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921): message : see declaration of '_InIt'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2061: syntax error: identifier '_First_InIt'

Why is my code not compiling when including OpenCV in my Visual Studio Project?

There is too much code to post so I'll be short and sweet here.
I'm migrating a project to Visual Studio that I originally built in Eclipse on OSX, using the OpenCV Apple framework distribution (opencv delivered as a .framework).
I've created a visual studio project from the existing code but when I build it, I get a bunch of errors from one of the headers (opencv2/core/fast_math.hpp) that are included along the header chain of <opencv2/opencv.hpp>.
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C2065: '__m128d': undeclared identifier
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C2146: syntax error: missing ';' before identifier 't'
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C2065: 't': undeclared identifier
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C3861: '_mm_set_sd': identifier not found
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(106):
error C2065: 't': undeclared identifier
Nothing has really changed in my code, just that I'm now using Visual Studio 2017. I have added opencv\build\include to my include path. I see that this code is SIMD intrinsics, which I don't think should have any problem compiling.
Is there a step I'm missing here?
This looks to be something with how I set up the project. The SIMD intrinsics require extra headers. I didn't configure the project to use precompiled headers which also appears to explain why std::string was undefined too. The extra headers can be added in stdafx.h and it's presence resolves other missing components.

file writing in vs2010 (c++, win32)

I asked this question earlier and you told me to mention the errors,
so I will mention them now(I couldn't figure out how to continue the last thread I started,all I saw was an "add a comment" button and an "answer your question" button, so I had to correct the questio and ask it again, sorry about that):
My question is the following:
I'm using visual studio 2010 and I'm writing a win32 application(not a console application).
I need to know how to write to a file from this application.
I included these headers: windows.h, stdlib.h, string.h and tchar.h
I wrote a very simple hello world application and it ran just fine.
But when I tried to include iostream and fstream
in my project the compiler gave me the following errors.
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(21): error C2039: 'abort' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(21): error C2873: 'abort' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2039: 'exit' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2873: 'exit' : symbol cannot be used in a using-declaration
IntelliSense: the global scope has no "abort" c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib 21 13
IntelliSense: the global scope has no "exit" c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib 24 13
And when I include fstream.h,I get:
error C1083: Cannot open include file: 'fstream.h': No such file or directory c:\users\user\documents\visual studio 2010\projects\helloworld\helloworld\main.cpp 5 1 helloworld
IntelliSense: cannot open source file "fstream.h" c:\users\user\documents\visual studio 2010\projects\helloworld\helloworld\main.cpp 5 1 helloworld
Same thing for iostream.h
Why are these errors occurring?
In C++, you should use <cstdlib> instead of <stdlib.h>, <cstring> instead of <string.h> (assuming you mean the C style strings. If you want C++ std::string, use <string> [without .h].
And you should use <fstream>, not <fstream.h>.
Please check that your :
#include "stdafx.h"
is the first include of you .cpp file.
Write other includes after this one :
#include "stdafx.h"
#include <iostream>
// ... and so on
int main(...) {
}
... this is a quite frequent mistake with Microsoft compilers (see C++ cout gives undeclared identifier).
Probably you wrote #include "iostream" instead of #include <iostream>
May be this helps .. Try to Check your errors reasons from
http://msdn.microsoft.com/en-us/library/et4zwx34%28v=vs.80%29.aspx

Moving C++ project, errors in atlplus.h

I am trying to move an old C++ project to VS2010.
The last version of VS to compile it was VS2005, as far as I know. I already fixed a bunch of errors but now I am stuck,
since I am getting errors in atlplus.h, which is a VC10 header file.
Error 1 error C2065: 'CStringW' : undeclared identifier C:\Program
Files (x86)\Microsoft Visual Studio
10.0\VC\atlmfc\include\atlplus.h 692 1
Error 2 error C2146: syntax error : missing ';' before
identifier 'strW' C:\Program Files
(x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlplus.h 692 1
Error 3 error C3861: 'strW': identifier not found
C:\Program Files
(x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlplus.h 692 1
Error 4 error C2065: 'strW' : undeclared identifier C:\Program Files
(x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlplus.h 693 1
Does anyone have any idea? I've been stuck here since last week.
You need to include atlstr.h before any headers that use CString.
CString has been moved to the atlstr.h header file.
I met the similar problem. please try to include atlbase.h instead of atlstr.h.
You can see a comment line in file atlplus.h:
//Avoid using <atlstr.h> except in the registry templates (for circular dependencies).