Results 1 to 8 of 8

Thread: How to check for errors in code without compiling?

  1. #1
    Join Date
    Aug 2009
    Location
    Mar del Plata, Argentina
    Beans
    81
    Distro
    Ubuntu 11.04 Natty Narwhal

    Cool How to check for errors in code without compiling?

    Well, I'm really starting with that ".configure" and "make" thing... And today I realized that for large programs, a "make" may take a looooong time... So, there is a way to check for errors without actually compile the program? Because it sucks when it find errors after 15 min of the start =/

  2. #2
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: How to check for errors in code without compiling?

    No, because the only way to "know" whether or not an error will occur is to execute the program (in that case, the compilation). One could probably convert that to the halting problem.

  3. #3
    Join Date
    Sep 2009
    Beans
    1,293

    Re: How to check for errors in code without compiling?

    Remember, 'make' looks to recompile only files who have changed since it was last run. In theory if you 'make' a 1000 file project and then change one file, only that 1 file will be recompiled on a following 'make'. In practice obviously any other files that depend on the changed file will themselves be recompiled too and so on. For this reason you'll often find that changing a source file might only cause a short recompile whereas changing a header file causes a much larger one since it is #include'd by any number of others

  4. #4
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: How to check for errors in code without compiling?

    There are IDE's which do fast partial compilation as you type. Visual studio for example.
    I think netbeans is a free IDE capable of doing that but unfortunately gcc is not well suited for that. Consider using LLVM and clang.


    you can make in verbose mode (which is mostly default)
    make V=1
    then copy paste the command which compiles your particular edited file and execute it by hand.

    This may save you some time when modifying headers which are included in all other files, forcing long recompilation.

    If you only modify source files make should compile the minimal requirements by itself. If you are doing that and make compiles everything your Makefile make be suboptimal (I have seen projects where make executes a rm *.o before compiling...)

    For C++ you can use the pimple (pointer to implementation) design idiom do avoid long compilation times which is a huge problem in C++.

    If the linking is a problem, consider using the gold linker in binutils (still beta)
    It is supposed to be quite a bit faster than ld
    Last edited by MadCow108; May 1st, 2010 at 05:08 PM.

  5. #5
    Join Date
    Nov 2008
    Location
    Maine
    Beans
    1,126
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to check for errors in code without compiling?

    Hm, Doesnt Qdevelop also provide partial compilation?
    ~Conradin~

  6. #6
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: How to check for errors in code without compiling?

    IDEs aren't really a solution here, though. If I understand correctly, what the OP wants is download a piece of software as a source tarball and know beforehand whether or not compilation will be successful. It's different from a programming project of your own in an IDE.
    「明後日の夕方には帰ってるからね。」


  7. #7
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: How to check for errors in code without compiling?

    if you have a multicore pc you can increase the speed by compiling in parallel
    increase the number of jobs with the -j flag of make

    you can also use distcc to compile on several connected computers in parallel

  8. #8
    Join Date
    Aug 2009
    Location
    Mar del Plata, Argentina
    Beans
    81
    Distro
    Ubuntu 11.04 Natty Narwhal

    Talking Re: How to check for errors in code without compiling?

    Quote Originally Posted by SevenMachines View Post
    Remember, 'make' looks to recompile only files who have changed since it was last run. In theory if you 'make' a 1000 file project and then change one file, only that 1 file will be recompiled on a following 'make'. In practice obviously any other files that depend on the changed file will themselves be recompiled too and so on. For this reason you'll often find that changing a source file might only cause a short recompile whereas changing a header file causes a much larger one since it is #include'd by any number of others
    I didn't know that! :O
    Thanks ^^

    Quote Originally Posted by MadCow108
    if you have a multicore pc you can increase the speed by compiling in parallel
    increase the number of jobs with the -j flag of make

    you can also use distcc to compile on several connected computers in parallel
    Thanks! It's a very useful parameter, it should use it by default xD.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •