I used to work with math.h without any problem. Now, I use an external library which itself has a file called math.h, but which includes < cmath>.
Adding this library to my project (or even just adding the include directory, without touching the code) now generates tons of errors from < cmath> :
C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2039: 'acosf' : is not a member of '`global namespace''
C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2873: 'acosf' : symbol cannot be used in a using-declaration
C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2039: 'asinf' : is not a member of '`global namespace''
C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2873: 'asinf' : symbol cannot be used in a using-declaration
[etc, etc...]
I don't understand why this happens. I am using Visual Studio 2005 and looking on the internet, it seems that this problem is solved under VS 2008. However, I'd like to stay on VS 2005...
Including using namespace std; everywhere, or changing the order of my includes doesn't seem to change anything. Defining _STD_BEGIN solves the error, but produce as many in < xlocinfo>.
How can this be solved?
Same Problem exists in VC 10. I think, that <cmath> includes itself a math.h but insted of the correct one, which is shipped with VC it uses the one which is created in the User-Project (with different content of course).
Solution: Do never use a File named math.h in your Project... (Or correct the std somewhere).
I'm not sure I read your question correctly but it seems odd that a library would ship it's own math.h file.
Perhaps you are suppose to put the parent directory in your include path so that <my_lib/math.h> can be included without conflicting with your compiler <math.h>?
The problem is probably mixing C libraries with C++ conventions. For instance:
#include <math.h>
namespace TEST {
}
This compiles fine, whereas:
namespace TEST {
#include <math.h>
}
This generates a large number of spurious errors.
Just to confuse the issue:
#include <math.h>
namespace TEST {
#include <math.h>
}
This also compiles as it can only be included once (the first time).
Hence also:
#include <math.h>
namespace TEST {
#include "SomethingThatIncludesMath.h"
}
Will work, whereas:
namespace TEST {
#include "SomethingThatIncludesMath.h"
}
Won't.
You can also get similar problems by including C++ headers into a *.c file, rather than a *.cpp file.
I am sure that other similar mixing of C and C++ can lead to similar problems.
(1) According to Microsoft, the C2873 means;
'symbol' : symbol cannot be used in a using-declaration
A using directive is missing a namespace keyword. This causes the compiler to misinterpret the code as a using declaration rather than a using directive.
(2) Also when I had C2873 with C2039 (I tried to merge CEF3 and Cinder), somehow I bypassed the both error by changing Properties->Configuration Properties->C/C++->Code Generation;
Enable Minimal Rebuild: Yes(/Gm), Enable C++ Exception: Yes(/EHsc), Enable Function-Level Linking: empty
Related
I just encountered problem with Visual Studio 2013, when I get C1083 for every project/solution. Error I am getting looks like this one (path and name differ from project to project)
Error 1 error C1083: Cannot open source file: 'main.cpp': No such file or directory D:\what\c1xx what
there is only one file, main.cpp containing just
#include <stdio.h>
int main(){
printf("hello world");
while (1);
}
so nothing should be wrong there. Project folder contains
Debug
main.cpp
what.sdf
what.sln
what.vcxproj
what.vcxproj.filters
what I find strange, VisualStudio keeps claiming main.cpp does not exist even when I place absolute path to it in vcxproj instead of just filename.
I'd like to note that VisualStudio was working, stopped without me fiddling with anything and reinstalation nor repair did help.
Any help would be much appreciated.
I'm trying to build a VS 2008 project written by someone else who is currently AWOL in VS2010. I need help with the WinDDK includes, particularly with hidsdi.h.
I've installed the WinDDK and VS2010 on a clean install of Win7. In Properties -> VC++ Directories -> Include Directories, I have added C:\WinDDK\7600.16385.1\inc\api, as well as \ddk and \crt. In Properties -> VC++ Directories -> Library Directories, I have added C:\WinDDK\7600.16385.1\lib\win7\i386.
However, when I attempt to build the project, I get repeated instances of
"error C3861: 'HidD_SetOutputReport': identifier not found" and "error C3861: 'HidD_GetInputReport': identifier not found
I opened up hidsdh.h from the following code block:
extern "C"
{
#include "setupapi.h"
#include "hidsdi.h"
}
And the functions listed in the error reports are present within the header file in question. Clearly, I'm doing something wrong with the include paths. Some assistance would be greatly appreciated.
You must not be defining NTDDI_VERSION or you're not defining it correctly. As you can see in hidsdi.h, the definition of HidD_SetOutputReport is conditional on this:
#if (NTDDI_VERSION >= NTDDI_WINXP)
NTDDI_VERSION determines what versions of Windows you're going to support. The appropriate values can be found here.
I'm trying to compile this code:
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
#include <luabind/luabind.hpp>
#include<iostream>
int main(){
lua_State*pL=lua_open();
luabind::open(pL);
lua_close(pL);
return 0;
}
But I don't have a .lib of luabind, so I use the source with the .h/.cpp files.
The way I do it is by adding the directories to include, but I get a link error.
The only way I can compile is by adding the .cpp files as existing elements, but the solution tree gets messy with the additional files.
Can somebody tell me if there's a way to add the directory of the additional .cpp files in the solution's properties?
Thanks
Compile the lua cpp files into a static library. Add the directory where you put those under "linker | input | additional library directories".
You need to tell the linker where to find the functions referenced by the .h files (the .lib file, typically).
I want to use google-ctemplate in a project. But if I include the basic file, I get the following error (with Visual Studio C++ 2005):
Error 1 fatal error C1083: Cannot open include file: 'tr1/unordered_map': No such file or directory f:\entwicklung\libraries\ctemplate-0.99\src\ctemplate\template_cache.h 39
I can find the unordered_map.hpp in the boost-directory and the boost-directory is set in the include-path in Visual Studio. How can I solve this problem?
I found out what the problem was. I included the wrong directory from google-ctemplate. Instead of src I have to use src/windows.
But that triggers another Problem, this time from the linker.
As is, you can use:
#include <boost/tr1/unordered_map.hpp>
Alternatively, add your $(boost-directory)/boost/tr1/tr1 to the include path and use:
#include <unordered_map>
See this Header Include Style for more details.
Note: I'm assuming $(boost-directory) is set to something like "C:\boost_1_46_0".
Considering that TR1 was not published until the summer of 2005, I wouldn't be surprised that it isn't present in VS 2005. You might try a more up-to-date version of the compiler!
There is one idl file defined in microsoft sdk which is not available in VS2005. I am using some of the interfaces from that IDL.
Now this works fine on VS 2010 . I want to make it compile on VS2005.
I copied the header file to my project directory. But it is giving me compilation error.
When I looked into header file , the class id is defined in it as
EXTERN_C const CLSID CLSID_Xyz.
Now it is defined as extern so it means it should be declared somewhere else in code.
So my question is just including .h file is sufficient or do I need to also include _i.c file.
Any suggestions
Once you examine that _i.c file you'll see the indeed the CLSID constants are defined there. So yes, you need to incorporate that .c file into you program - either by #including it into a .c or .cpp file or just by adding it to your project so that it compiles separately and then links into the final binary.