C++ clang应用程序的问题
我正在使用clang库构建一个应用程序,我运行到 如果有人能给出一些方向,这将非常有帮助 ./a.out/home/nmahew/Desktop/algorithms/array.cpp给出 我的包含搜索目录如下 包括。。。搜索从这里开始: 包括搜索从这里开始: /usr/include/linux /usr/lib/gcc/i686 redhat linux/4.4.3/include /usr/include/c++/4.4.3 /usr/include/c++/4.4.3/backward /usr/include/c++/4.4.3/i686-redhat-linux /usr/本地/包括 /usr/包括 搜索列表结束。 而char_traits.h在/usr/include/c++/4.4.3/bits/中,我使用 Fedora 12 32位系统。 我的代码列在下面 图01_pp.cppC++ clang应用程序的问题,c++,linux,gcc,clang,fedora12,C++,Linux,Gcc,Clang,Fedora12,我正在使用clang库构建一个应用程序,我运行到 如果有人能给出一些方向,这将非常有帮助 ./a.out/home/nmahew/Desktop/algorithms/array.cpp给出 我的包含搜索目录如下 包括。。。搜索从这里开始: 包括搜索从这里开始: /usr/include/linux /usr/lib/gcc/i686 redhat linux/4.4.3/include /usr/include/c++/4.4.3 /usr/include/c++/4.4.3/backward
#include "PPContext.h"
int main(int argc, char *argv[])
{
if (argc != 2)
{
return 0;
}
PPContext scope;
scope.headers.PrintStats();
const FileEntry *File = scope.fm.getFile(argv[1]);
if(!File)
{
return 0;
}
scope.sm.createMainFileID(File, SourceLocation());
scope.pp->EnterMainSourceFile();
IdentifierTable identitab(scope.lang);
MinimalAction action(*(scope.pp));
Parser parse(*(scope.pp), action);
parse.ParseTranslationUnit();
identitab.PrintStats();
return 0;
}
PPContext.h
#ifndef PP_CONTEXT
#define PP_CONTEXT
#include <iostream>
#include <string>
using namespace std;
#include <llvm/Support/raw_ostream.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/TargetInfo.h>
#include <clang/Basic/TargetOptions.h>
#include <clang/Basic/FileManager.h>
#include <clang/Basic/SourceManager.h>
#include <clang/Lex/Preprocessor.h>
#include <clang/Lex/HeaderSearch.h>
#include <clang/Frontend/Utils.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Frontend/DiagnosticOptions.h>
#include <clang/Frontend/HeaderSearchOptions.h>
#include <clang/Parse/Action.h>
#include <clang/Parse/Parser.h>
#include "llvm/System/Host.h"
using namespace clang;
using namespace llvm;
struct PPContext {
PPContext():tdp(ost, options), diag(&tdp), sm(diag), headers(fm)
{
TargetOptions target_options;
target_options.Triple = sys::getHostTriple();
target_options.CXXABI = "itanium";
target = TargetInfo::CreateTargetInfo(diag, target_options);
lang.CPlusPlus = 1;
pp = new Preprocessor(diag, lang, *target, sm, headers);
headeropts.EnvIncPath = "/usr/include/linux";
headeropts.CXXEnvIncPath =
"/usr/lib/gcc/i686-redhat-linux/4.4.3/include/";
headeropts.Verbose = 1;
ApplyHeaderSearchOptions(headers, headeropts, lang,
llvm::Triple(target_options.Triple));
};
~PPContext()
{
delete pp;
delete target;
};
llvm::raw_stdout_ostream ost;
const DiagnosticOptions options;
TextDiagnosticPrinter tdp;
Diagnostic diag;
LangOptions lang;
SourceManager sm;
FileManager fm;
HeaderSearch headers;
TargetInfo *target;
Preprocessor *pp;
HeaderSearchOptions headeropts;
};
#endif //#ifndef PP_CONTEXT
array.cpp
#include <iostream>
#include "array.hpp"
using namespace std;
template <class gen>
ARRAY<gen>::ARRAY()
{
size = MAX;
ptr = (gen (*)[MAX])new gen[size];
}
template <class gen>
ARRAY<gen>::ARRAY(int array_size)
{
size = array_size;
ptr = (gen (*)[])new gen[size];
}
template <class gen>
ARRAY<gen>::~ARRAY()
{
delete (gen (*)[MAX])ptr;
}
template <class gen>
int ARRAY<gen>::getsize()
{
return size;
}
template <class gen>
ARRAY<gen>::ARRAY(const ARRAY &orig)
{
ptr = (gen (*)[MAX])new gen[orig.size];
memcpy(ptr, orig.ptr, sizeof(gen)*orig.size);
size = orig.size;
}
template <class gen>
gen& ARRAY<gen>::operator [](unsigned int index)
{
return *ptr[index];
}
int main(void)
{
ARRAY <int> intarray;
intarray[8] = 16;
return 0;
}
错误显示模板类char_traits不存在。这一个实际上是在char_traits.h中定义的,不包括在array.cpp中 尽管在该文件中,它的内容如下:
/** @file char_traits.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
但您仍然可以尝试将其包括在内,让叮当高兴。欢迎使用堆栈溢出,@nmahew!我尽我所能重新格式化代码。代码应缩进四个空格;您不需要使用会弄乱格式的。而且,一般来说,比起HTML标记,更喜欢标记语法;结果可能不会那么令人惊讶:
/** @file char_traits.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/