0

I am using scientific linux. I am dealing with a huge amount of code in C++ with tons of cpp files. Right now, it compiles successfully, but the values/data I'm getting are definitely wrong. Also, for some small changes I make to the code causes seg faults.

In the directory user/project/Build, I enter make to compile and link all the cpp files. I then have to go to user/project/Build/bin/project to run the project binary by typing user/run/run.sh

When I go to directory /user/project/Build/bin and then type gdb project and then run, I see Program exited with code 01. Missing separate debuginfos, use: debuginfo-install glibc..

If I try to set a breakpoint, such as by break test.cpp:19, I get the message No source file named test.cpp. Make breakpoint pending on future shared library load? But I clearly have a source file named test.cpp

How can I set breakpoints? Considering that I'm a beginner with Unix, should I use another IDE such as emacs or Qt creator?

user4352158
  • 731
  • 4
  • 13
  • 24
  • To set breakpoints by line number, you need to pass the `-g` option to the C++ compiler. Here's a question/answer that says how to do that for typical cases: [Compiling with cmake and include debug information](http://stackoverflow.com/a/8447957/2554472) – Mark Plotnick Feb 24 '15 at 16:35
  • In my `Build` directory, I entered `cmake -DCMAKE_BUILD_TYPE:STRING=Debug ../src`. But the output I got was `Looking for pthread_create - not found. -- Found Threads: TRUE CMake Error at log4cplus/CMakeLists.txt:152 (SetupBoost): Unknown CMake command "SetupBoost". -- Configuring incomplete, errors occurred!` – user4352158 Feb 24 '15 at 18:01
  • OK. So you normally run `cmake ../src` and that works? – Mark Plotnick Feb 24 '15 at 18:06
  • What do you mean? I just entered that because that is what they suggested on that link you provided. To compile, I just enter `make` – user4352158 Feb 24 '15 at 18:15
  • 1
    OK, so you're using CMake, but you never had to use the `cmake` command? – Mark Plotnick Feb 24 '15 at 18:19
  • Let's just look at the files that `make uses. If you have a file named `Makefile` or `makefile`, is there a line in it that starts with `CFLAGS=` ? – Mark Plotnick Feb 24 '15 at 18:21
  • In the `Makefile`, there is no line with `CFLAGS` – user4352158 Feb 24 '15 at 18:23
  • 1
    Sorry, I forgot you're using C++, not C. Is there a `CXXFLAGS` line? If not, please add a line near the top of the Makefile that says `CXXFLAGS+= -g`, then recompile. The g++ or clang++ command lines that `make` spews should have a `-g` in them. – Mark Plotnick Feb 24 '15 at 18:29
  • Thanks for the suggestion. But the MakeFile says at the top `CMAKE generated file: DO NOT EDIT!`. Can I just ignore that? Or is there a way to add that CXXFLAGS via the prompt? – user4352158 Feb 24 '15 at 18:40
  • 1
    Edit Makefile for now. Worst that can happen is that the manual changes you make to Makefile get overwritten by cmake at some point. Ultimately, we will need to know what command in the `cmake` family of commands you type to generate that Makefile. – Mark Plotnick Feb 24 '15 at 18:49
  • ok, I edited the Makefile to include the CXXFLAGS but now the error is `/opt/apps/ossw/applications/cmake/cmake-2.8.9/sl6/gcc-4.6/bin/cmake: /usr/lib64/libstdc++.so.6: version GLIBCXX_3.4.15 not found (required by /opt/apps/ossw/applications/cmake/cmake-2.8.9/sl6/gcc-4.6/bin/cmake)` – user4352158 Feb 24 '15 at 19:00
  • Odd. If you remove that new `CXXFLAGS` line from Makefile, the error goes away? – Mark Plotnick Feb 24 '15 at 19:17
  • turns out that I think I got that error because I forgot to type `module load boost`. Once I did that, I was able to compile successfully even with that `CXXFLAGS` line in the MakeFile. But when I try to run gdb again, I get the same messages as in the OP – user4352158 Feb 24 '15 at 19:46
  • Sorry I couldn't find a solution. Someone else will help. – Mark Plotnick Feb 24 '15 at 20:59
  • Your question is unclear. What is the huge amount of code you are struggling with? – Basile Starynkevitch Feb 24 '15 at 22:02
  • And how big is that code? Do you have more experienced colleagues working on it (you probably do, if the code is huge as you say it is) – Basile Starynkevitch Feb 24 '15 at 22:11

1 Answers1

0

Did you read the documentation of GDB? It is definitely worthwhile to read it. Read also some tutorial on gdb

If your Makefile-s are generated by cmake, you should also study the documentation of cmake and the documentation of make. See also this answer to a related question.

Did you compile all your software with g++ -Wall -g (and without any optimization flags like -O1 or -O2) - or perhaps even -g3 instead of -g?

You might even install debugging variants of the major libraries you are using (e.g. packages like glibc-debuginfo etc...)

You probably want to specify (for gdb) the source directories to search with the dir command of gdb ...

And yes, I recommend using emacs. But above all, I strongly recommend spending hours (and perhaps days or even weeks) to learn more about Linux and software development on it (there are lots of books, websites, tutorials and other training, ... about that). Maybe start with a small, hello-world like, program (learning how to compile it with g++ and to debug it with gdb). Then try to compile and debug a small (e.g. of a hundred thousand lines of source code) free software that you like (e.g. fishshell or anything you've got from sourceforge or github), just to get a feeling of how such software is built.

If you are using (or improving) a big scientific software, it probably has some community website, mailing list, or forum for help (see geant or kiva or aster as examples, which I only know by name!). Please also use them.

PS. It is not mostly a matter of choosing tools: you are using the good ones (GCC i.e. g++, emacs, gdb, make, grep or ack, etags, git, awk, ....). It is a matter to get the knowledge -spending weeks or months of your time- about how to use them wisely and combine their use. See also this & that.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • If it a code on which only a dozen people worked it is not a *huge* code, but a middle-sized one. the GCC compiler, the Linux kernel, the mozilla browser, or the GEANT4 simulation code have many millions lines of code (so are developed by several hundred people each). And if there is no community around that code, you should start one! – Basile Starynkevitch Feb 24 '15 at 22:49
  • Adn you really should edit your questions to improve them by explaining more, and give more context. At least explain in a few sentences what your code is doing, how it is organized (whatr size is it) etc. – Basile Starynkevitch Feb 24 '15 at 22:55