Author Topic: cannot locate error line, if compilation error occured  (Read 5460 times)

Offline alys666

  • Multiple posting newcomer
  • *
  • Posts: 11
cannot locate error line, if compilation error occured
« on: January 23, 2017, 02:20:31 pm »
Hi!
I have C++ project with custom make file, and I cannot jump to source line from error window("Build messages") to source file and line, even when this file is opened in editor.
compiler is gcc.
i've inspected .cbp file of my project and there all files paths are relative to .cbp file, which is stored separately from my sources and make files.
kinda -
./project (dir with .cbp inside)
./sources (sources and makefiles)

it looks like Codeblocks cannot find the source needed.

example of error(warning) line from "Build Messages" window.
../../firmware/camera.cpp|99|warning: unused variable 'llen' [-Wunused-variable]|

i have CodeBlocks 16.01, ubuntu 14.04

thanks.
Ubuntu 14.04, CodeBlocks 16.01

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: cannot locate error line, if compilation error occured
« Reply #1 on: January 23, 2017, 02:53:38 pm »
Thanks for saying you used "custom make file"; you can try adding the file to the project.

But, I think this never worked for "custom make file". But, I use "custom make file" with a non supported compiler.
So, it might work with a supported compiler.

Tim S.
« Last Edit: January 23, 2017, 02:55:13 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline alys666

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: cannot locate error line, if compilation error occured
« Reply #2 on: January 23, 2017, 03:25:38 pm »
if you use non supported compiler, CB could not be able to parse it's error message to get correct filepath and line number, so CB cannot locate the file.
But for GCC it can, and it is visibile that it can, because file and error lines columns of Build Messages window are correct.
So CodeBlocks just has to get file name, in my case ../../firmware/camera.cpp(relative to .cbp), make absolute path from it and open(or switch to editor page if file already opened).
anyway, thanks for reaction.
Ubuntu 14.04, CodeBlocks 16.01

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: cannot locate error line, if compilation error occured
« Reply #3 on: January 23, 2017, 05:57:25 pm »
Simple things to check:

Is the makefile in the same folder as the cbp file?
Does the makefile call other makefiles or use the cd command?

Edit: Is the CB Project set to use the correct compiler?
Edit2: Is the correct compiler set as the default compiler?

Tim S.
« Last Edit: January 23, 2017, 06:11:16 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: cannot locate error line, if compilation error occured
« Reply #4 on: January 23, 2017, 06:08:57 pm »
Complex things to check:

Find the line in the "build log"
Copy it to the Advanced Compiler Options and test that the regex works.

Settings -> Compiler
Tab: Other Settings
Button: Advanced Options
Tab: Output Parsing

Paste line into "Test String"
Button: Test

Is the filename and line number found correctly?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline alys666

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: cannot locate error line, if compilation error occured
« Reply #5 on: January 23, 2017, 06:55:31 pm »
Is the makefile in the same folder as the cbp file?
Does the makefile call other makefiles or use the cd command?
Edit: Is the CB Project set to use the correct compiler?
Edit2: Is the correct compiler set as the default compiler?
Tim S.
1. folders of cbp and make files(there are few makefiles and moreover sh scripts to build application) are different, because of simple reason. I develop my code in a team, but people aren't using CB, when I like CB. so to prevent mixing of sources and specific for me project files, i use separate folder for .cbp.
Imo, restriction that cbp and makefiles must be in the same folder is too hard.

2. in reality my custom make command calls sh script, which calls couple of makes, and one of them calls makefiles from folders tree. so structure of makefiles quite complex.

3. default compiler is gcc, which i use. error/warnings decoding is correct. error parser is able to get source file path and error line.

4. there is your good idea, that current dir is changing during such complex invocation of makefiles, and CB cannot properly locate it.
Ubuntu 14.04, CodeBlocks 16.01

Offline alys666

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: cannot locate error line, if compilation error occured
« Reply #6 on: January 23, 2017, 07:51:01 pm »
i've found the reason:  at least i'm closer to solution...

gcc compiler gives error/warning in form(build log):
tasks.cpp:292:36: warning:........

but CB decodes it as(Build Messages):
../../firmware/tasks.cpp|292|warning: ......

and here is error, because in reality the relative(to .cbp file) path is:
../../firmware/LIB/tasks.cpp

and in .cbp this file is recorded as:
   <Unit filename="../../firmware/LIB/tasks.cpp" />


so it missed subfolder LIB, but properly found that it is ../../firmware folder.

hmm...
« Last Edit: January 23, 2017, 07:54:23 pm by alys666 »
Ubuntu 14.04, CodeBlocks 16.01

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: cannot locate error line, if compilation error occured
« Reply #7 on: January 23, 2017, 09:21:13 pm »
I compile my wxWidgets from git with a custom-makefile project, where the Makefile is in a build-folder, the sources are in a source folder and the projectfile is in a third-folder and jump to errors works fine.

Did you set the execution-directory on the first tab ("Project settings") of the project properties dialog to the folder, where the makefile is located ?

Offline alys666

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: cannot locate error line, if compilation error occured
« Reply #8 on: January 23, 2017, 10:03:29 pm »
I compile my wxWidgets from git with a custom-makefile project, where the Makefile is in a build-folder, the sources are in a source folder and the projectfile is in a third-folder and jump to errors works fine.

Did you set the execution-directory on the first tab ("Project settings") of the project properties dialog to the folder, where the makefile is located ?

I solved the problem and understood the reason.
problem that CB just takes this "execution directory" and adds it to the file path(name) given by compiler in error/warning. and it can bring errors.
it can be solved easy. you must give sources in full paths to gcc. then gcc will return full path in error/warning, and CB will correctly find file and line.

Your advice will work only if you have one makefile in "execution directory". And you give to gcc all your sources relatively to this directory. Then path = execution directory +"/" + path_from_gcc_message will point correctly to the file.

But my "give source in absolute path" advice seem is universal.

So finally:
if you have custom make file or some custom build system, to preserve an ability to locate error/warning file and line, given by gcc(or supported compiler), you must:
1. or have absolute paths in compiler error/warning message
2. or have relative to "execution directory"(first tab of project settings) paths.
« Last Edit: January 24, 2017, 10:00:04 am by alys666 »
Ubuntu 14.04, CodeBlocks 16.01