#25 cc task linking with gcc instead of g++

v1.0 (example)
open
nobody
website (6)
5
2004-04-22
2003-03-13
Anonymous
No

This problem is so obvious. Basically <cc> cannot
compile and link C++ program. Even the simplest one
shown below.

#include <iostream>

int main()
{
std::cout << "Hi there" << "\n";
return 0;
}

It's very likely that even though you set the name of the
compiler to "g++", it still invokes "gcc" no matter what.
So when it's time to link the program, it cannot find all
kinds of C++ libraries.

Discussion

  • Logged In: NO

    You need to use syslibset - for example:
    <cc link="executable"
    objdir="${obj.dir}/snmp-test-agent"
    outfile="${build.bin.dir}/agent"
    warnings="none" multithreaded="true"
    >
    <compiler refid="compiler.options"/>
    <sysincludepath location="${agent++.dir}/include"/>
    <includepath location="${gen-agent}"/>
    <fileset dir="${src.dir}/adapters/snmp/testagent"
    includes="*.cpp"/>
    <fileset dir="${gen-agent}"
    includes="*.cpp"/>
    <fileset dir="${agent++.dir}/lib"
    includes="libagent++.a"/>
    <fileset dir="${snmp++.dir}/lib"
    includes="libsnmp++.a"/>
    <fileset dir="${ace.dir}/ace" includes="libACE.so"/>
    <syslibset libs="stdc++,pthread,util"/>
    <syslibset libs="socket,nsl" unless="is.linux"/>
    </cc>

     
  • James Doyle
    James Doyle
    2003-08-03

    Logged In: YES
    user_id=836477

    I have a similar problem/result even when I specify that the
    linker should be g++ it still uses gcc.

    ...

    <!-- This option is found in the latest CVS code -->

    <linker name="g++">

    ....

    But when I try to compile this using 'ant -v' it states that it's
    still using gcc and will not compile.

    This hack found in the other comments may work (haven't
    tried it yet) but only because you're including the libraries that
    are normally brought in by g++ link process by default.

     
  • Logged In: YES
    user_id=213710

    The bug is that the "g++" linker does not add the GCC C++ runtime
    unless at least one other library is linked in. Any other library, it
    doesn't matter. As a workaround, you can just add the attribute <
    syslibset libs="m"/> which should be safe and innocuous on all
    platforms.

     
  • Curt Arnold
    Curt Arnold
    2004-04-22

    • summary: Cannot link C++ program. --> cc task linking with gcc instead of g++
     
  • Curt Arnold
    Curt Arnold
    2004-04-22

    Logged In: YES
    user_id=27193

    Bugs 724599 and 787595 appear to be duplicates of this bug.

    This will be fixed as part of a refactoring of processor families
    which is also necessary to simplify cross-compilation.

     
  • Logged In: NO

    Fix:

    Change all "gcc" strings in GppLinker
    to "g++" strings and things will work better !!

    Martijn Hijdra

     
  • Adam
    Adam
    2005-06-30

    Logged In: YES
    user_id=1298368

    I couldn't use the syslibs to include anything else because
    it would hang at building. However, a linkerarg at the end
    with value="-lstdc++" seems to work.

     
  • cozmic72
    cozmic72
    2006-10-09

    Logged In: YES
    user_id=1616900

    This problem caused me major head-aches. With the latest versions of gcc,
    ither g++ should be invoked directly, or -fexceptions should be passed to gcc.
    As I couldn't find a way of passing the extra argument, I ended up patching
    GppLinker to use 'g++' from the command line. If I can work out how to submit
    a patch, I will do later.