I am using clang tool to parse standard header file located in /usr/lib/gcc/x86_64-linux-gnu/4.7/string. But I get the following error.
In file included from ~/PrototypeWork/user/header.hpp:3:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/string:41:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/char_traits.h:41:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/postypes.h:41:
/usr/include/c++/4.7/tr1/cwchar:42:14: error: no member named 'wcstof' in namespace 'std'
using std::wcstof;
~~~~~^
/usr/include/c++/4.7/tr1/cwchar:45:14: error: no member named 'vfwscanf' in namespace 'std'
using std::vfwscanf;
~~~~~^
The problem seemed to be that clang is reading string header as a C header instead of c++ header and so it could not parse "using" keyword.
So I went ahead an added the -TP command line options that says to treat all source files as C++ but that did not help.
I get the following warning after using -TP command line option
warning: argument unused during compilation: '-T P'
Can anyone help me with this issue?
Clang command line options: http://clang.llvm.org/docs/UsersManual.html#id5
Code
My main function has these:
int main() {
std::vector<std::string> cmdLine = boost::assign::list_of
("-TP")
("-I/usr/include")
("-I/usr/include/c++/4.7/tr1/");
clang::tooling::FixedCompilationDatabase db(".",cmdLine);
// Provide clang with the header file that needs to be parsed
// Run the clang tool .
}
Sorry if this is a "Thank you, Captain Obvious" answer, but: is it possible that the code being parsed is simply failing to #include <cwchar>? clang is a bit more stringent by default than gcc, so you'll see an error like this if you've failed to include the header that declares the function.
Related
Hello I am testing new c++ library : TagParser from Martchus
https://github.com/Martchus/tagparser
I am getting that error when I compile the following code:
CODE:
#include <tagparser/mediafileinfo.h>
#include <tagparser/diagnostics.h>
using namespace TagParser;
// create a MediaFileInfo for high-level access to overall functionality of the library
MediaFileInfo fileInfo;
// create container for errors, warnings, etc.
Diagnostics diag;
...
ERROR:
In file included from /usr/include/c++/5/cstdint:35:0,
from /usr/local/include/c++utilities/conversion/types.h:4,
from /usr/local/include/tagparser/tagtarget.h:6,
from /usr/local/include/tagparser/settings.h:4,
from /usr/local/include/tagparser/abstractcontainer.h:5,
from /usr/local/include/tagparser/mediafileinfo.h:4,
from TagParserTest.cpp:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error:
#error This file requires compiler and library support for the ISO C++ 2011 standard.
This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
When I try to build with the -std=c++11 option I get this error:
In file included from /usr/local/include/tagparser/abstractcontainer.h:5:0,
from /usr/local/include/tagparser/mediafileinfo.h:4,
from TagParserTest.cpp:1:
/usr/local/include/tagparser/settings.h: In function ‘constexpr TagParser::TagCreationFlags& TagParser::operator|=(TagParser::TagCreationFlags&, TagParser::TagCreationFlags)’:
/usr/local/include/tagparser/settings.h:53:1: error: expression ‘(lhs = ((TagParser::TagCreationFlags)(((std::underlying_type<TagParser::TagCreationFlags>::type)lhs) | ((std::underlying_type<TagParser::TagCreationFlags>::type)rhs))))’ is not a constant-expression
}
I really don't know how to solve this. Can anyone help me?
Many thanks to Daniel H.
When I use c++14 instead of c++11 it just works fine.
Thanks.
In one of my project's header file, the following line is included in a inline method
typedef boost::archive::iterators::transform_width<boost::archive::iterators::binary_from_base64< boost::archive::iterators::remove_whitespace<std::string::const_iterator>>, 8, 6> Base64ToBin;
When I compile this with gcc 4.8.2 I'm getting the following error:
error: ‘boost::archive::iterators::remove_whitespace<__gnu_cxx::__normal_iterator > >’ has a field ‘boost::archive::iterators::remove_whitespace<__gnu_cxx::__normal_iterator > >::’ whose type uses the anonymous namespace [-Werror]
I'm really hitting hard but could not resolve this issue, also from the link1 and link2 it looks like it is an issue with lower version of gcc. Can somebody suggests how to silence this warning or get over with that. I'm using -Werror flag compilation.
This looks like a correct warning. Because the code is in a header, it will be included from multiple files but the anonymous namespace is unique for every file. That means the type doesn't have the same definition everywhere.
Solution: move the relevant code to a .cpp file.
I am trying to use the GNU C library regex functionality in my C++ project, particularly I'm trying to use the regex_t regcomp, regexec, regfree functions. Upon compilation I get errors stating that these symbols are undefined:
me> g++ -I/me/myheaders/ -c RootGenerator.cpp -o RootGenerator.o -std=gnu++0x -Wall
RootGenerator.cpp: In function ‘std::string findFirstFileInCurrentDirectory(std::string)’:
RootGenerator.cpp:1072: error: ‘regex_t’ was not declared in this scope
RootGenerator.cpp:1072: error: expected ‘;’ before ‘re’
RootGenerator.cpp:1073: error: ‘re’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘REG_EXTENDED’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘REG_NOSUB’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘regcomp’ was not declared in this scope
RootGenerator.cpp:1074: error: expected ‘;’ before ‘int’
RootGenerator.cpp:1084: error: ‘status’ was not declared in this scope
RootGenerator.cpp:1084: error: ‘regexec’ was not declared in this scope
RootGenerator.cpp:1092: error: ‘REG_NOMATCH’ was not declared in this scope
RootGenerator.cpp:1108: error: ‘regfree’ was not declared in this scope
I realize that the regex header is a TR1 implementation and is therefore experimental for my version of GCC. I added the -std=gnu++0x compiler option according to the compiler warning recieved when first trying to compile but this doesn't seem to fix the issue. Is this an issue of the system not recognizing and adding paths to "experimental" headers? Are there additional include paths or compiler options that I need to specify?
As an additional note, I noticed in Eclipse/CDT that under the "includes" tab in the Project Explorer view, it shows a list of the system header paths. It lists many header files under the /user/include/c++/4.4.4 path tab, but It doesn't list the regex header. I think this is also reaffirming that there is a setting issue.
Found the problem:
#include <regex>
should be
#include <regex.h>
The regex.h header is the GNU C library implementation of regex, containing the functions I was trying to use in my source. The regex header is the TR1 (and incomplete) regex implemntation. So #Oli, I wasn't referencing the relevant header after all!
I am coding an computer vision program using OpenCV library. In my program, I "typedef" a type called "CLabPixelType" by "Vec3d", which is to represent a color pixel in Lab color space. However, I encounter the following problem when I compile the code by g++ under Mac OS X Mountain Lion with XCode 4.4.1.
g++ ${CXXFLAGS} main.cpp slic.cpp slic_contrast.cpp -o sclbp -I/opt/local/include
-L/opt/local/lib -lopencv_core.2.4.2 -lopencv_imgproc.2.4.2 -lopencv_highgui.2.4.2
In file included from /usr/include/c++/4.2.1/backward/map.h:59,
from lxp_factory.h:8,
from cmd_parser.h:4,
from main.cpp:2:
/usr/include/c++/4.2.1/backward/backward_warning.h:32:2: warning: #warning This
file includes at least one deprecated or antiquated header. Please consider using
one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples
include substituting the <X> header for the <X.h> header for C++ includes, or
<iostream> instead of the deprecated header >>><iostream.h>. To disable this
warning use -Wno-deprecated.
In file included from lxp_framework.h:5,
from lxp_factory.h:5,
from cmd_parser.h:4,
from main.cpp:2:
img_interpolater.h:10: error: ‘Vec3d’ does not name a type
img_interpolater.h:45: error: ‘CLabPixelType’ does not name a type
img_interpolater.h:97: error: ‘CLabPixelType’ does not name a type
I do not know why it shows "'Vec3d' does not name a type? I checked the other questions about such "XX does not name a type" error in Stackoverflow but failed to find an answer.
It is a while back when I used opencv library the last time, but I think the problem may be that you don't take into account namespace cv
Try adding using namespace cv, or using namespace cv::CLabPixelType or just qualify the name fully each time you use it like typedef cv::CLabPixelType Vec3d.
I'm looking for an implementation of Hybrid Tree(not important), and find an "old" one here.
The author said they have tried this code on the SUN Sparc platform (running Solaris 2.6) and with gcc-2.8.1 compiler. And my environment is gcc version 4.4.3 (Ubuntu 10.10).
The problem is:
I run "make" with the makefile he provides, but it gives me lots of error message as follows:
g++ -c Node.C
g++ -c DataNode.C
In file included from DataNode.h:18,
from DataNode.C:17:
Query.h:9:20: error: vector.h: No such file or directory
Query.h:10:19: error: stack.h: No such file or directory
Query.h:13:22: error: function.h: No such file or directory
Query.h:14:22: error: iostream.h: No such file or directory
DataNode.C:283:8: warning: extra tokens at end of #endif directive
In file included from DataNode.h:18,
from DataNode.C:17:
Query.h:29: warning: ‘typedef’ was ignored in this declaration
Query.h:44: warning: ‘typedef’ was ignored in this declaration
Query.h:86: error: expected initializer before ‘<’ token
Query.h:118: error: ISO C++ forbids declaration of ‘PQ’ with no type
Query.h:118: error: expected ‘;’ before ‘*’ token
Query.h:122: error: ISO C++ forbids declaration of ‘PQ’ with no type
Query.h:122: error: expected ‘;’ before ‘*’ token
Query.h:126: error: ISO C++ forbids declaration of ‘PQ’ with no type
Query.h:126: error: expected ‘;’ before ‘*’ token
Query.h:135: error: expected initializer before ‘<’ token
DataNode.C: In member function ‘void DataNode::DisconnectBranch(int)’:
DataNode.C:80: error: ‘memmove’ was not declared in this scope
make: *** [DataNode.o] Error 1
I know I need to modify the souce code so as to agree with the morden compiler, such as change vector.h to vector. But I find it's just endless.
So my question is: is there any convienent method to run this program, no matter automatically converting this code to "modern-style" or using a standalone "old-style" compiler ?
Any suggestions?
===Update:===
Thank you all, I installed gcc2.8.1 in a different dir using --prefix=/usr/local/gcc-2.8.1 and modify the "makefile" to use this old-version gcc(/usr/local/gcc-2.8.1/bin/gcc). But when I run "make", it still gives me errors of not finding the headers:
/usr/local/gcc-2.8.1/bin/gcc -c DataNode.C
In file included from DataNode.h:18,
from DataNode.C:17:
Query.h:9: vector.h: No such file or directory
Query.h:10: stack.h: No such file or directory
Query.h:11: deque: No such file or directory
Query.h:12: algorithm: No such file or directory
Query.h:13: function.h: No such file or directory
Query.h:14: iostream.h: No such file or directory
make: *** [DataNode.o] Error 1
Then I tried to find these heads in /usr/local/gcc-2.8.1 using find /usr/local/gcc-2.8.1 -name "*vector*", but got nothing.
So where are these heads for the old-version gcc?
You can make a vertor.h yourself which includes vector. This way you can fix the incompatibilities noninvasively.
Edit:
You may also need to add a
using namespace std;
in the header file(s). This is
generally a bad idea but this is one situation where i'd do it anyway.
Once you get it working i would reccomend rewriting it to use the new style header files and namespaces.
Debian Lenny (oldstable) has gcc 3.4. This might have a better backward compatibility. Try to make compatibility headers for the rest of the issues and include them via an extra -I directory, e.g. a vector.h header file that includes vector.
Do yourself the favor and try not to touch the old code. It is easy to break legacy code in unforeseen ways.
You could try running the program on QEMU which supports Solaris 2.6. The only problem might be hunting for the install disc/image. Also, there are people that sells old Solaris boxes on eBay for cheap, you might be able to grab one.
GCC provides download for very old versions, you might be able to get better chance if you try older version of the compiler.
gcc has -fpermissive option: try it and see whether at least some errors disappear. Also: try making a single header file that will include all requisite headers with using directives. For example, make stdinc.h containing:
#include <vector>
#include <iostream>
#include <stack>
...
using std::vector;
using std::fstream;
...
Replace all mentions of legacy C++ header files with a single include of stdinc.h. Old C++ didn't have namespaces, so even if you replace individual directives with just using namespace std;, clashes are unlikely.
If the only thing is
#include <vector.h>
to
#include <vector>
using namespace std;
Why not try sed?
grep for all includes to see if there are other includes than the c++ headers. If not your lucky.
Another thing that is more tricky is that there is old code that relies on accessing data through iterators in a non-standard way. I saw that in a Doom map editor for linux. Then you may need to do manual stuff.