[Gate-users] Workaround for compiling Gate on OS X 10.8 Mountain Lion & 10.7 Lion
Jonathan Madsen
jonathanrmadsen at gmail.com
Wed Sep 5 22:28:51 CEST 2012
For me to reproduce the error, the issue is with the C++ compiler Clang. I can't remember if it was an Apple update, a CMake thing, or something I did with MacPorts to make Clang the default C++ compiler over g++ but I had a similar issue when building Geant4 a couple of months ago. Clang is supposedly a little more syntactically strict than g++, hence the ostringstream error.
Straight from unpacking the source, when you run your cmake command, you will probably see something like this:
[ 75 - Jonathan - 02:59 PM: gate_v6.2-build ] $ cmake -DCMAKE_INSTALL_PREFIX=$HOME/Gate_6.2/ /Users/Jonathan/Applications/GATE/sources/gate_v6.2/
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is Clang 4.0.0
… etc.
and with that, I get the aforementioned error with ostringstream.
The fix is to add the CXX environment variable before the cmake command, so…
CXX=/usr/bin/g++ cmake -DCMAKE_INSTALL_PREFIX=… etc.
(or export CXX=/usr/bin/g++ and then the cmake command separate) and you will then see something like:
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is GNU 4.2.1
So erase the CMakeCache.txt file, do a make clean, and reissue the cmake command with the CXX environment variable pointing to the GNU compiler and I believe the code will compile for you too.
BTW, I also had to add the missing ' this-> ' in GateMap.hh
Jonathan
On Sep 5, 2012, at 9:15 AM, Mojca Miklavec <mojca.miklavec.lists at gmail.com> wrote:
> On Wed, Sep 5, 2012 at 8:23 AM, Gaens, Michaela wrote:
>> Hi Marc and Gate Users,
>>
>> I actually ran into the same trouble when trying to compile Gate v6.2 on Mac OS X Lion yesterday. In the end I also managed to compile and run Gate, but I went the other way and looked at the code instead of the compiler.
>>
>> Looking at the definition of std:ostringstream (http://www.cplusplus.com/reference/iostream/ostringstream/ostringstream/), the used constructor in GateUIcmdWithAVector.hh line 124 indeed has the wrong arguments, since it does not expect an integer. After a slight modification the error disappeared.
>>
>> I then encountered one more error related to GateMaps.hh:
>>
>> /Applications/gate_v6.2/source/digits_hits/include/GateMaps.hh:120:7: error: use of undeclared identifier 'insert'
>>
>> It seems that a "this->" was missing there.
>>
>> After changing that, the compilation completed (using llvm-gcc-4.2) and also the benchmarks worked fine.
>>
>> I have attached the modified files.
>>
>> GateUIcmdWithAVector.hh belongs into the folder gate_v6.2/source/general/include and GateMaps.hh into the folder gate_v6.2/source/digit_hits/include .
>>
>> Maybe someone can have a look if my modifications make sense.
>
> Thank you very much for the patches. They worked for me (the
> compilation still failed, but the two building errors were solved).
> What I don't understand is why
> os << '\0';
> is needed in GateUIcmdWithAVector.hh and I'm not sure how
> ostringstream without any argument works on other compilers. Maybe
> something like
> std::ostringstream os (std::ostringstream::out);
> would be needed, but I'm not experienced enough to judge about that. I
> was only looking at
> http://www.cplusplus.com/reference/iostream/ostringstream/ostringstream/.
>
> Just for a reference, the errors without the patches were the following:
>
> {{{{{
>
> [ 7%] Building CXX object CMakeFiles/Gate.dir/Gate.cc.o
> In file included from /Users/gate/gate_v6.2/Gate.cc:26:
> In file included from
> /Users/gate/gate_v6.2/source/physics/include/GateSourceMgr.hh:19:
> In file included from
> /Users/gate/gate_v6.2/source/physics/include/GateVSource.hh:26:
> In file included from
> /Users/gate/gate_v6.2/source/physics/include/GateVSourceMessenger.hh:32:
> /Users/gate/gate_v6.2/source/general/include/GateUIcmdWithAVector.hh:124:22:
> error: no matching constructor for initialization of
> 'std::ostringstream' (aka 'basic_ostringstream<char>')
> std::ostringstream os(st,100);
> ^ ~~~~~~
> /usr/include/c++/4.2.1/sstream:436:7: note: candidate constructor not
> viable: no known conversion from 'int' to 'ios_base::openmode' (aka
> 'std::_Ios_Openmode') for 2nd argument;
> basic_ostringstream(const __string_type& __str,
> ^
> /usr/include/c++/4.2.1/sstream:416:7: note: candidate constructor not
> viable: requires at most 1 argument, but 2 were provided
> basic_ostringstream(ios_base::openmode __mode = ios_base::out)
> ^
> /usr/include/c++/4.2.1/bits/sstream.tcc:265:25: note: candidate
> constructor (the implicit copy constructor) not viable: requires 1
> argument, but 2 were provided
> extern template class basic_ostringstream<char>;
> ^
> 1 error generated.
> make[2]: *** [CMakeFiles/Gate.dir/Gate.cc.o] Error 1
> make[1]: *** [CMakeFiles/Gate.dir/all] Error 2
> make: *** [all] Error 2
>
>
>
> [ 23%] Building CXX object
> CMakeFiles/Gate.dir/source/geometry/src/GateMDBFieldReader.cc.o
> In file included from
> /Users/gate/gate_v6.2/source/geometry/src/GateMDBFieldReader.cc:19:
> In file included from
> /Users/gate/gate_v6.2/source/geometry/include/GateMDBFieldReader.hh:19:
> In file included from
> /Users/gate/gate_v6.2/source/geometry/include/GateMDBFieldDecoder.hh:17:
> /Users/gate/gate_v6.2/source/digits_hits/include/GateMaps.hh:120:7:
> error: use of undeclared identifier 'insert'
> insert(*iter);
> ^
> this->
> /Users/gate/gate_v6.2/source/geometry/src/GateMDBFieldReader.cc:207:51:
> note: in instantiation of member function 'GateMap<G4String,
> int>::GateMap' requested here
> GateCodeMap GateMDBFieldReader::theFMFPrefixMap =
> GateCodeMap(N_FMFPREFIXMAPS,theFMFPrefixMapArray);
> ^
> /usr/include/c++/4.2.1/bits/stl_map.h:399:7: note: must qualify
> identifier to find this declaration in dependent base class
> insert(const value_type& __x)
> ^
> /usr/include/c++/4.2.1/bits/stl_map.h:426:7: note: must qualify
> identifier to find this declaration in dependent base class
> insert(iterator __position, const value_type& __x)
> ^
> /usr/include/c++/4.2.1/bits/stl_map.h:439:9: note: must qualify
> identifier to find this declaration in dependent base class
> insert(_InputIterator __first, _InputIterator __last)
> ^
> 1 error generated.
> make[2]: *** [CMakeFiles/Gate.dir/source/geometry/src/GateMDBFieldReader.cc.o]
> Error 1
> make[1]: *** [CMakeFiles/Gate.dir/all] Error 2
> make: *** [all] Error 2
>
> }}}}}
>
> There were some further warnings which might be worth patching in
> patch releases for Gate though:
>
> {{{{{
> [ 29%] Building CXX object
> CMakeFiles/Gate.dir/source/digits_hits/src/GateCrossSectionProductionActor.cc.o
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/src/GateCrossSectionProductionActor.cc:20:
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/include/GateCrossSectionProductionActor.hh:25:22:
> warning: extra tokens at end of #include directive [-Wextra-tokens]
> #include "G4Event.hh";
> ^
> //
> 1 warning generated.
> [ 29%] Building CXX object
> CMakeFiles/Gate.dir/source/digits_hits/src/GateCrossSectionProductionActorMessenger.cc.o
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/src/GateCrossSectionProductionActorMessenger.cc:17:
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/include/GateCrossSectionProductionActor.hh:25:22:
> warning: extra tokens at end of #include directive [-Wextra-tokens]
> #include "G4Event.hh";
> ^
> //
> 1 warning generated.
>
>
> [ 41%] Building CXX object
> CMakeFiles/Gate.dir/source/digits_hits/src/GatePhaseSpaceActor.cc.o
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/src/GatePhaseSpaceActor.cc:27:
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEAHeader.h:5:
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEARecord.h:6:
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEAUtilities.h:83:9:
> warning: 'LITTLE_ENDIAN' macro redefined
> #define LITTLE_ENDIAN __LITTLE_ENDIAN
> ^
> /usr/include/i386/endian.h:93:9: note: previous definition is here
> #define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
> ^
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/src/GatePhaseSpaceActor.cc:27:
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEAHeader.h:5:
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEARecord.h:6:
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEAUtilities.h:84:9:
> warning: 'BIG_ENDIAN' macro redefined
> #define BIG_ENDIAN __BIG_ENDIAN
> ^
> /usr/include/i386/endian.h:94:9: note: previous definition is here
> #define BIG_ENDIAN __DARWIN_BIG_ENDIAN
> ^
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/src/GatePhaseSpaceActor.cc:27:
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEAHeader.h:5:
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEARecord.h:6:
> /Users/mojca/app/fizika/gate/gate_v6.2/source/general/include/GateIAEAUtilities.h:85:9:
> warning: 'PDP_ENDIAN' macro redefined
> #define PDP_ENDIAN __PDP_ENDIAN
> ^
> /usr/include/i386/endian.h:95:9: note: previous definition is here
> #define PDP_ENDIAN __DARWIN_PDP_ENDIAN
> ^
> 3 warnings generated.
>
>
> [ 46%] Building CXX object
> CMakeFiles/Gate.dir/source/digits_hits/src/GateSimplifiedDecay.cc.o
> In file included from
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/src/GateSimplifiedDecay.cc:12:
> /Users/mojca/app/fizika/gate/gate_v6.2/source/digits_hits/include/GateSimplifiedDecay.hh:15:17:
> warning: using directive refers to implicitly-defined namespace 'std'
> using namespace std;
> ^
> 1 warning generated.
>
> }}}}}
>
> I would like to make a Portfile for MacPorts, but I first need to
> figure out how to solve the problem with linking against CLHEP.
>
> Mojca
> _______________________________________________
> Gate-users mailing list
> Gate-users at lists.opengatecollaboration.org
> http://lists.opengatecollaboration.org/mailman/listinfo/gate-users
More information about the Gate-users
mailing list