debugginggccg++

How to make g++ (avr-g++) output error line number and column?


i believe -g turn on debug information output:

09-19 19:31:34.788: INFO/System.out(24948): /data/data/app/sdk/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -I/data/data/app/sdk/hardware/arduino/cores/arduino -I/data/data/app/sdk/hardware/arduino/variants/standard /data/data/app/build/Blink.cpp -o /data/data/app/build/Blink.cpp.o
09-19 19:31:34.828: WARN/System.err(24948): /data/data/app/sdk/hardware/tools/avr/bin/avr-g++[1]: syntax error: ')' unexpected

not sure the command-line is build correctly and some arguments can be missed but it's arduino IDE code.

why error line number and column is missing and how can i switch it on?


Solution

  • UPDATE based on comments:

    The OP had installed a MacOS g++ executable on a Linux system. The Linux system didn't recognize it as an executable file, so it tried to execute it as a shell script, resulting in a misleading error message.


    That particular error message:

    syntax error: ')' unexpected
    

    looks like a shell error, not a compiler error.

    On my system, a C++ program with an extraneous ) causes g++ to produce this message:

    c.cpp: In function ‘int main()’:
    c.cpp:2:5: error: expected primary-expression before ‘)’ token
    c.cpp:2:5: error: expected ‘;’ before ‘)’ token
    

    Note that the messages include line and column numbers, as g++ syntax error messages generally do.

    whereas a Bourne shell script with an extraneous ) produces a message like this:

    ./foo.sh: 3: ./foo.sh: Syntax error: ")" unexpected
    

    which is very similar, but not quite identical, to what you saw. (The difference could easily be caused by a different implementation of sh.)

    Somewhere, either you have a shell script with a syntax error, or you're trying to execute something other than a shell script as if it were a shell script.

    What command are you running that produces this error? Is

    /data/data/app/sdk/hardware/tools/avr/bin/avr-g++
    

    a proper executable? What happens if you run

    /data/data/app/sdk/hardware/tools/avr/bin/avr-g++ --version
    

    from the command line? What about

    file /data/data/app/sdk/hardware/tools/avr/bin/avr-g++ ?
    

    From a comment, this command:

    /data/data/app/sdk/hardware/tools/avr/bin/avr-g++ --version
    

    produces the same error message:

    syntax error: ')' unexpected).
    

    Which means that the avr-g++ command is executable, but not recognized by the system as an executable, so it's trying to run it as a shell script.

    What OS are you running this on? Is the avr-g++ command intended to run on the host system or on the target (running g++ on an Arduino seems unlikely). Compare the output of

    file /data/data/app/sdk/hardware/tools/avr/bin/avr-g++
    

    to, for example,

    file /usr/bin/g++
    

    or, if it's a symbolic link, to whatever actual file it points to (/usr/bin/g++-4.7 on my system). The point is to determine just what kind of file this avr-g++ is, and to compare it to executables that are known to be correct for your system. (Just to be 100% sure, try /usr/bin/g++ --version.)

    On my system, for example, I get:

    $ file /usr/bin/g++
    /usr/bin/g++: symbolic link to `g++-4.7'
    $ file /usr/bin/g++-4.7
    /usr/bin/g++-4.7: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xac398e1061dbb1a6f8da022f0a1616f15cf07085, stripped