Giter VIP home page Giter VIP logo

Comments (48)

hebaishi avatar hebaishi commented on August 16, 2024

I have just done a small test and I am getting the same error message twice - once for the cpp file, and once for the h file.

Are you sure you are viewing all errors in the project? You can see all errors by clicking on the Project button at the bottom of the atom window. This should show you the errors in both files.

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

If I click on the project button, I still only get the one message, but it also displays the CPP filename against the error.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

So you get the same message occuring twice. Is that what you are saying?

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

No, if I've got File selected, I get one error; if I've got Project selected, I get the same one error, but the error shows the filename as well.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Could you send me a screenshot of your atom window? Do you have both files open in atom? They both need to be open for you to see the errors from both files.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

It is actually perfectly normal for an error in a header to be shown in the source file. This is because of how the C++ compiler works. The preprocessor is invoked before the compiler, so essentially all #include statements are expanded (basically the code from the included file is pasted into the current file). Then the compiler is invoked. This is why it looks like the error is in the CPP file.

What I am trying to establish is whether you have both files open or only one. linter-gcc will only show errors for open files. You can find more information about C++ compilation here.

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

I know how the C++ preprocessor works. :) I have both header and source file open, and there is no error shown in the header file.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Ok. Could you show me the header and source files you are working with? Or maybe create a small code snippet that recreates the problem so I can play with it?

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

I'll try and do that over the weekend. In (at least some) other compilers, if there is a problem in a header file, it shows you the error at the right line in the right file. It's odd that GCC can't do the same! :)

from linter-gcc.

kioplato avatar kioplato commented on August 16, 2024

I'm getting this error in all of my header files: "cc1: error: output filename specified twice".
When I compile the program I get no errors. It only happens inside atom when using linter-gcc.
Sorry I'm somewhat new to github. Should I create a separate issue?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Could you turn on debugging, open the console, copy the linter-gcc command and paste it here?

from linter-gcc.

kioplato avatar kioplato commented on August 16, 2024

cc1: error: output filename specified twice
My linter-gcc version is 0.6.8
Is this ok?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

You need to open the debugging console by pressing Ctrl+Shift+I, turn on the debugging options in the linter-gcc configuration page, and copy the linter-gcc command that appears in the console window.

from linter-gcc.

kioplato avatar kioplato commented on August 16, 2024

-1458397310067.txt
Here are the log files.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Could you try pasting the command in the above file into a terminal and running it? It looks fine to me.
The command is:

/usr/bin/gcc -Wall -fsyntax-only -c -fmax-errors=0 /home/platwnas/Desktop/Projects/Algorithms/Recursion/tower_of_hanoi/stack.h

from linter-gcc.

kioplato avatar kioplato commented on August 16, 2024

$ /usr/bin/gcc -Wall -fsyntax-only -c -fmax-errors=0 /home/platwnas/Desktop/Projects/Algorithms/Recursion/tower_of_hanoi/stack.h
cc1: error: output filename specified twice

It's not linter-gcc's problem, right?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

This is very strange. It looks like it's a gcc bug. Could you report the output of gcc --version and perhaps try updating GCC? Also, which platform are you on? ubuntu?

from linter-gcc.

kioplato avatar kioplato commented on August 16, 2024

$ gcc --version
gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I'm using ubuntu 15.10

GCC is up-to-date
I ran sudo apt-get install --reinstall gcc

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Looks like there's something wrong with your version of GCC. Could you try installing clang and running the above command with clang instead, so substituting clang for /usr/bin/gcc?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@MrPlatwnas unfortunately, it looks like the problem you are having is with the compiler itself. Since linter-gcc is simply an interface to GCC, it will simply display whatever GCC reports. If you disagree with me, and think linter-gcc is doing something wrong, please let me know.

@steronydh could you please do the same - paste the linter-gcc command into a terminal and see if you get the same output. If you do, the issue is with GCC itself, and not linter-gcc.

from linter-gcc.

kioplato avatar kioplato commented on August 16, 2024

I will give it a try with clang and I will report the outcome. No problem. It should be the compiler's problem, indeed.

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

I have the same problem (headers errors in c file) quite often too

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

I'm using platformio, and seeing:

avr-g++.exe (AVR_8_bit_GNU_Toolchain_3.4.5_1522) 4.8.1

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@steronydh @Arignir do you get the same issue when your run the linter-gcc command in the terminal?

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

Yes, but the message indicates that the error is from my header file, and not from my c file.

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

Sorry, what linter-gcc command?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

You need to do the following:

  1. Turn on debugging messages in the linter-gcc configuration page
  2. Press Ctrl+Shift+I to open the developer tools window
  3. Click on console
  4. Type in your source file to trigger linter-gcc, and the linter-gcc command will appear in the console window.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

To determine the cause of this issue, I have done the following:

  1. I have created two files source.cpp and header.hpp. The source file contains no errors, but the header file does (a missing semicolon after a variable declaration). The source file includes the header.
  2. Below is the output of running g++ on both files:
/tmp/cpp_play$ cat source.cpp 
#include <iostream>
#include "header.hpp"

int main(int argc, char* argv[])
{
    return 0;
}

/tmp/cpp_play$ cat header.hpp 
#include <iostream>

int i

/tmp/cpp_play$ /usr/bin/g++ -std=c++11 -c -Wall -o /dev/null -fmax-errors=0 -I/tmp/cpp_play/include -I/tmp/cpp_play /tmp/cpp_play/source.cpp 
/tmp/cpp_play/source.cpp:4:1: error: expected initializer before ‘int’
 int main(int argc, char* argv[])
 ^

/tmp/cpp_play$ /usr/bin/g++ -std=c++11 -c -Wall -o /dev/null -fmax-errors=0 -I/tmp/cpp_play/include -I/tmp/cpp_play /tmp/cpp_play/header.hpp 
/tmp/cpp_play/header.hpp:3:5: error: expected initializer at end of input
 int i
     ^

You can see that when you lint the source file, the error appears to occur in the source file, and the same for the header. This makes perfect sense, because the C++ preprocessor does the #include substitutions before compilation. Therefore, the source file that is compiled actually has the entire contents of the header file, and this is why g++ reports an error in the source file.

My advice to you is to ensure that your headers are all error-free before working on your source files. You can easily test this by #includeing your header files one by one into a empty source file to determine if one of them has an error.

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

I understand and appreciate what is happening with the preprocessor. I've got .gcc-flags.json pointing linter-gcc at the same copy of gcc as I'm using to compile the project, and the project compiles with no errors, so I'm at a loss as to why linter-gcc should be showing errors at all!

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

How are you compiling your project? What build system are you using? And what is the error that you are seeing in linter-gcc that doesn't appear when you compile?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Also, you need to follow the steps I outlined describing how to find the command run by linter-gcc.

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

@hebaishi I do understand how include works, but it could be cool if errors from the .h file could not be displayd on a .c / .cpp file, because having a red dot with an error like "missing semicolon" on a blank space in a .cpp file is very strange and quite frustrating when you get started with linter-gcc.

It will be much better if the error is not show on a c/cpp file, or if it is only show at the #include line.

(Sorry for english, i'm french ^^)

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@Arignir Unfortunately this is how GCC works - the preprocessor runs before the compiler. There might be a setting to get around this, but I doubt it. In any case this is a compiler issue and has nothing to do with linter-gcc.

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

I'm using platformio which compiles the Arduino project fine.

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

@hebaishi When gcc pop the error, the file is indicate. Why not just parse this to pop the error on the good file and not always on the current file ?

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@Arignir This is exactly what GCC does already. That is what I tried to explain in the long post above with the two sample files.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@steronydh I will have a play with platformio and get back to you.

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

@hebaishi >____<

We're not arrived :D

So, when there is an error in a hpp file, gcc points out that the error is on the hpp file. BUT, linter - gcc shows it in the cpp file, not in the hpp file. Is it possible to only show errors that GCC points out to be on this file, so that errors from hpp file will not be saw in cpp file ?

Thanks in advance, and sorry for my bad english ><

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@Arignir I really do not think that is possible. I could be wrong, but I seriously doubt it. Expansion of #include directives is fundamental to the way the compiler works. The directives are always expanded BEFORE compilation, so the compiler doesn't know where the error has come from.

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

Okey, let's have a test:
I have helloworld.c, with content:

#include "helloworld.h"

int main()
{
  printf("Hello World !\n");
  return (0);
}

And helloworld.h, with content

#ifndef HELLO_WORLD_H_
# define HELLO_WORLD_H_

# include <stdio.h>

Oh shit ! An error, just here !

#endif /* !HELLO_WORLD_H_ */

Let's now compile with the command gcc helloworld.c -I./ (I'm using gcc 5.3)
Here is the output :

In file included from helloworld.c:1:0:
helloworld.h:6:1: error: unknown type name ‘Oh’
 Oh shit ! An error, just here !
 ^
helloworld.h:6:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘!’ token
 Oh shit ! An error, just here !

Don't you see these beautiful "helloworld.h" in the error output ? ;)

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

Looks like we have found an inconsistency in the way GCC reports errors. In my test case, GCC reports an error in the source file, even though it's actually in the header. In the example you have given, you are right - the error is reported as coming from the header file.

Your input has been helpful in identifying the problem, which is in the case of linting on-the-fly (where linter-gcc actually lints a temporary file), the temporary filename has to be substituted for the original file, but that has to leave any header errors alone. I will update linter-gcc asap and let you know.

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

Thanks man ! :)
Because i'm using linter-gcc 10h per day, i have tons of ideas to improve it ! Maybe i'll fork / pull request it one day :D

Anyway, thank you !

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

That's fantastic to hear. If it's easier for you, why don't you create another issue and make a list of some suggested improvements that we can discuss together? As someone who uses it all time, I would love to hear your ideas! Also, it would be great for all the users of linter-gcc (myself included) to benefit from these ideas as soon as possible.

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

It looks like I need to compile Arduino code with gcc 5.3 to get the improved error reports! ;)

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

I have made the necessary change. Please update to linter-gcc v0.6.9. Note that a restart of Atom is necessary after updating linter-gcc.

from linter-gcc.

hebaishi avatar hebaishi commented on August 16, 2024

@steronydh @Arignir everything working normally guys?

from linter-gcc.

Arignir avatar Arignir commented on August 16, 2024

@hebaishi Didn't had the time to code a lot since the update, so i don't know that much :s

from linter-gcc.

kravlost avatar kravlost commented on August 16, 2024

Looking good! Thanks, @hebaishi. Errors in header files are now showing at the exact line in the header file. :) Great fix!

from linter-gcc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.