From: Scott D. F. <sd...@ms...> - 2005-09-27 14:00:05
|
Hi John, I have found that there are 3 patches that must be applied to the OpenC++ 2.8 release (numbered 1-3 below). 1 and 3 have been added to the OpenC++ CVS repository, but 2 has yet to be added. Here is a link to the latest CVS snapshot as of now: http://opencxx.sourceforge.net/snapshots/opencxx-20050912.tar.gz PATCH #1 -------- The problem is that in gcc 3.4.x std::auto_ptrs can't be swapped with std::swap. The reason for the problem is that std::swap has a const tmp variable; i.e. (from bits/stl_algobase.h): template<typename _Tp> inline void swap(_Tp& __a, _Tp& __b) { // concept requirements __glibcxx_function_requires(_SGIAssignableConcept<_Tp>) const _Tp __tmp = __a; // <---THIS CAUSES std::auto_ptr PROBLEMS __a = __b; __b = __tmp; } And std::auto_ptr's auto_ptr_ref operator, which is called in the const line above, is a non-const method; i.e. (from memory.h): template<typename _Tp> class auto_ptr { ... template<typename _Tp1> operator auto_ptr_ref<_Tp1>() throw() { return auto_ptr_ref<_Tp1>(this->release()); } ... My solution to the problem was add my own swap function to the OpenC++ code, and use it to swap std::auto_ptrs. To accomplish this, I edited the MetacompilerConfiguration.h file in the OpenC++ source. I added this function definition near the top of the file just under "class ErrorLog": template<class T> inline void MYswap(std::auto_ptr<T>& a, std::auto_ptr<T>& b) { std::auto_ptr<T> c = a; a = b; b = c; } Next (in the same file), I changed class MetacompilerConfiguration::Iterator (found in the public section of class MetacompilerConfiguration), so that its operator= went from: Iterator& operator=(Iterator iter) { std::swap(impl_, iter.impl_); return *this; } To: Iterator& operator=(Iterator iter) { MYswap(impl_, iter.impl_); return *this; } And this solved the problem for me, and I expect it will for you as well. PATCH #2 -------- There is a mistake in the grammar that OpenC++'s parser expects. Prior to GCC 3.4, this was never a problem, but since GCC 3.4, the STL library uses the syntax that the broken grammar doesn't accept. In particular OpenC++ expects template declarations to look like this: template<typename T>... With an identifier like "T" following typename, but in fact the following is legal C++: template<typename>... This causes occ to issue errors whenever it parses the GCC library files that include the latter syntax (e.g., bits/cpp_type_traits.h). I fixed the problem by changing the Parser::rTempArgDeclaration member function definition in parser/Parser.cc. I changed this line (roughly the third line in the function): if(t0 == CLASS && lex->LookAhead(1) == Identifier){ To this: if(t0 == CLASS && !(lex->LookAhead(1) == Identifier)){ lex->GetToken(tk1); decl = PtreeUtil::List(new Leaf(tk1)); } else if(t0 == CLASS && lex->LookAhead(1) == Identifier){ I am not positive that my Ptree representation for the template argument declaration (temp.arg.declaration) is exactly what the OpenC++ maintainers would want, but it seemed to make sense to me. PATCH #3 -------- This patch solves the problem of -I flags not being passed to gcc/g++, and was originally reported in: http://sourceforge.net/mailarchive/message.php?msg_id=9785370 I will copy the relevant portions of that message here for convenience: My patch does the following: - Add a method to get the CC options to OpencxxConfiguration - In file driver2.cc method RunPreprocessor, inserts the CC options after argv.push_back(compiler) diff -ur opencxx-2.8/opencxx/driver2.cc opencxx-patched/opencxx/driver2.cc --- opencxx-2.8/opencxx/driver2.cc 2004-08-10 09:48:05.000000000 +0200 +++ opencxx-patched/opencxx/driver2.cc 2004-10-14 14:49:27.870216699 +0200 @@ -241,9 +241,11 @@ string compiler = config.CompilerCommand(); vector<string> argv; - + argv.push_back(compiler); + argv.insert(argv.end(), config.CppOptions().begin(), config.CppOptions().end()); + if(config.RecognizeOccExtensions()) argv.push_back("-D__opencxx"); diff -ur opencxx-2.8/opencxx/MetacompilerConfiguration.h opencxx-patched/opencxx/MetacompilerConfiguration.h --- opencxx-2.8/opencxx/MetacompilerConfiguration.h 2004-08-10 09:48:05.000000000 +0200 +++ opencxx-patched/opencxx/MetacompilerConfiguration.h 2004-10-14 14:42:21.060422444 +0200 @@ -20,6 +20,7 @@ #include <opencxx/defs.h> #include <string> #include <memory> +#include <vector> namespace Opencxx { @@ -95,7 +96,7 @@ virtual Opencxx::ErrorLog& ErrorLog() const = 0; virtual Iterator CcOptions() const = 0; - + virtual const std::vector<std::string>& CppOptions() const = 0; virtual Iterator Metaclasses() const = 0; }; diff -ur opencxx-2.8/opencxx/OpencxxConfiguration.h opencxx-patched/opencxx/OpencxxConfiguration.h --- opencxx-2.8/opencxx/OpencxxConfiguration.h 2004-08-10 09:48:05.000000000 +0200 +++ opencxx-patched/opencxx/OpencxxConfiguration.h 2004-10-14 14:42:32.511592506 +0200 @@ -117,6 +117,9 @@ { cc2Options_.push_back(option); } + const std::vector<std::string>& CppOptions() const { + return cc2Options_; + } void SetDoPreprocess(bool v) { doPreprocess_ = v; } bool DoPreprocess() const { return doPreprocess_; } Hope this helps. Cheers, Scott John Altidor wrote: > Hello, > > Whenever I try to compile a metaclass, I get the following error message: > > /courses/cs400/cs491s/jaltidor/opencxx-2.8/opencxx/parser/Ptree.h:47: > error: `metaclass' does not name a type > > I entered this command to attempt to compile my files: > > g++ -I. -I../opencxx-2.8 -D__opencxx JNIClass.ii -shared -o JNIClass.so > *.o /courses/cs400/cs491s/jaltidor/opencxx-2.8/libs/libocc.0 > > I tried using the OpenC++ script (occ) to compile my metaclass but the > script would never use my include flags (-I<path>) so the compiler would > never find any of the OpenC++ headers. > > Does anyone know what is wrong? > > John |