Why there is no debug info loaded after I add -g parameter - makefile

I think I have added the -g option in the makefile. The makefile is like this:
C=edgelist.c geometry.c heap.c main.c memory.c output.c voronoi.c
O=edgelist.o geometry.o heap.o main.o memory.o output.o voronoi.o
tt: voronoi t
./voronoi -t <t >tt
voronoi: $O
cc -g -o voronoi $O -lm
$O:vdefs.h
voronoi.tar : $C vdefs.h Makefile Doc t
tar -cf voronoi.tar $C vdefs.h Makefile Doc t
mailable: $C vdefs.h Makefile t
bundle $C vdefs.h Makefile t > mailable
When gdb runs the program:
jack#ubuntu:~/下载/voronoi$ gdb ./voronoi
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/jack/下载/voronoi/voronoi...(**no debugging symbols found**)...done.
(gdb)
What's the problem?

Each of the object files has to be created with -g, and the executable has to be linked with -g. At the moment, you are linking with -g but not compiling with -g.
Given the structure of your makefile, the simplest fix is probably:
$O: vdefs.h
gcc -g -c $*.c
However, ideally, you should set things up so that you use CC and CFLAGS. For example:
CFLAGS = -g -Wall -Wextra -Werror
CC = gcc # May be unnecessary
LDLIBS = -lm
Then you don't need the gcc line after $O: vdefs.h. Your linking line should become:
${CC} -o $# ${CFLAGS} $O ${LDFLAGS} ${LDLIBS}
or thereabouts.

Related

gcc 4.8.2 cc1plus: error: unrecognized command line option "-std=gnu++11"

I have a system in which I've been compiling programs with C++11 using automake and everything has been working.
However, when a different user take the same exact Makefile they get the aforementioned error.
Now, if they type in g++ --std=gnu++11 program.cpp then there are no complaints.
I've narrowed it down to a line that is causing the issue; however, I don't know how to fix it.
depbase=`echo no_endl.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
g++ -DHAVE_CONFIG_H -I. -I../.. -g --std=gnu++11 -g -O2 -MT no_endl.o -MD -MP -MF $depbase.Tpo -c -o no_endl.o no_endl.cpp &&\
mv -f $depbase.Tpo $depbase.Po
The problem is with depbase; however, I don't know what is going on with it or why it is there.
Below is the Automake file that I used to generate the Makefile:
bin_PROGRAMS = no_endl
AM_CXXFLAGS = -g --std=gnu++11
no_endl_SOURCES = no_endl.cpp
The only difference between my g++ and their g++ is I have an alias so g++ turns into g++ -g.
Helpful information
g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
Copyright (C) 2013 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.
If there is any other information that I need to provide, then let me know.
Related Question
I solved the problem.
The problem was the $PATH variables for me and other users.
Now, other users have an alias for g++ to the newer version, but their $PATH omits the actual location.
Make works based on their $PATH variable, so to fix it, I just had to make sure their path had the same location as mine.
You probably need the following additional m4 macro file that handles corner cases of substituted C++11 compilers.
https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html#ax_cxx_compile_stdcxx_11

avr-gcc compiles too large optiboot hex to suit

I'd like to modify Arduino Uno's bootloader (optiboot) in order to increase upload commands timeout from 1s to 8s. So i need to recompile bootloaders and upload it.
I was able to replace deprecated '-mshort-calls' to '-mrelax' and i'm able to compile it but it produces too large binary:
MBA-Anton:optiboot asmirnov$ make atmega328
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mrelax -fno-move-loop-invariants -mmcu=atmega328p -DF_CPU=16000000L -mrelax '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -c -o optiboot.o optiboot.c
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mrelax -fno-move-loop-invariants -mmcu=atmega328p -DF_CPU=16000000L -mrelax '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o
../../../../tools/avr/bin/avr-size optiboot_atmega328.elf
text data bss dec hex filename
530 0 0 530 212 optiboot_atmega328.elf
../../../../tools/avr/bin/avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
../../../../tools/avr/bin/avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
rm optiboot.o optiboot_atmega328.elf
avr-gcc version:
MBA-Anton:optiboot asmirnov$ ../../../../tools/avr/bin/avr-gcc --version
avr-gcc (GCC) 4.8.1
Copyright (C) 2013 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.
MBA-Anton:optiboot asmirnov$
I've googled more and i found that pretty the same config produces much smaller binary, so what's wrong?
Solved by using pretty old (2012 year) avr-gcc from here

Compile program using a Makefile with gcc instead of clang

I am writing a program to spell-check a given text. On my pc I used this Makefile to compile the program:
# compiler to use
CC = clang
# flags to pass compiler
CFLAGS = -ggdb3 -O0 Qunused-arguments -std=c99 -Wall -Werror
# name for executable
EXE = speller
# space-separated list of header files
HDRS = dictionary.h
# space-separated list of source files
SRCS = speller.c dictionary.c
# automatically generated list of object files
OBJS = $(SRCS:.c=.o)
# default target
$(EXE): $(OBJS) $(HDRS) Makefile
$(CC) $(CFLAGS) -o $# $(OBJS) $(LIBS)
# dependencies
$(OBJS): $(HDRS) Makefile
I would like to continue programming on my Raspberry Pi but I only have gcc installed. Is it possible to make this Makefile work for gcc? I tried to change the compiler with:
CC = gcc
but It doesn't work. I get the error message "unrecognised option -Qunused-arguments".
The problem is that the -Q option which Clang accepts isn't an option which GCC recognises.
GCC and Clang are completely separate compilers, and so one shouldn't really expect one of them to understand the other's options. In fact, Clang does make some efforts to be modestly compatible with GCC, in large part to make it possible to use it as a drop-in replacement for GCC. However that compatibility isn't, and probably shouldn't be, complete.
So your solution is simply to change the CFLAGS definition at the same time as you change the CC definition.

compile with gsl with an existing makefile

i have a makefile for some code library i'm using and now i've added to that code some code that uses gsl. i'm not so sure how and what to add to the makefile (which i wat to keep since it's invoking boost as well) that would invoke gsl.
This is my makefile:
CXX = g++
ARCH = -mtune=generic
# ARCH = -march=core2
# ARCH = -march=native
COFLAGS = $(ARCH) -O3 -pipe
CXXFLAGS = -Wall $(COFLAGS)
PROGRAMS = getData analyzeData
BOOSTFLAGS = -I .
OPENMP = -fopenmp -DSUPPORT_OPENMP
all: $(PROGRAMS)
getData: getData.cpp common.o parse.o common.h
$(CXX) $(CXXFLAGS) getData.cpp common.o parse.o -o getData
analyzeData: analyzeData.cpp common.o parse.o parameters.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(OPENMP) estimateCrossReplicatesExpression.cpp common.o parse.o parameters.o -o analyzeData
parameters.o: parameters.cpp parameters.h
parse.o: parse.cpp parse.h
common.o: common.cpp common.h
clean:
rm *.o $(PROGRAMS)
In case GSL is installed on the default path (/usr/local/include/gsl) on your system, the compilation command for a source file "example.c" would be
gcc -Wall -I/usr/local/include -c example.c
The library is installed as a single file, libgsl.a. A shared version of the library libgsl.so is also installed on systems that support shared libraries. The default location of these files is /usr/local/lib. If this directory is not on the standard search path of your linker you will also need to provide its location as a command line flag.
To link against the library you need to specify both the main library and a supporting cblas library, which provides standard basic linear algebra subroutines. A suitable cblas implementation is provided in the library libgslcblas.a if your system does not provide one. The following example shows how to link an application with the library,
$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm
The option -lm links with the system math library. On some systems it is not needed.
Thus, you need to specify the gsl specific flags in your compile command. Update the Makefile accordingly.

How to specify RPATH in a makefile?

I'm trying to specify rpath in my binary.
My makefile looks like this-
CC=gcc
CFLAGS=-Wall
LDFLAGS= -rpath='../libs/'
main: main.c
gcc -o main main.c
clean:
rm -f main main.o
But when I query rpath using command readelf -a ./main | grep rpath I get nothing
I've tried specifying rpath as LDFLAGS= "-rpath=../libs/" but even that doesn't seem to work.
Can someone please post an example on how should I specify rpath in a makefile?
GCC and ld versions are-
gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110327
If you set the variables, you should probably use them. It's silly not to, especially when make won't magically set those variables for you! :)
main: main.c
$(CC) $(CFLAGS) $(LDFLAGS) -o main main.c
Another problem is LDFLAGS, it should be
LDFLAGS="-Wl,-rpath,../libs/"
The usual gcc switch for passing options to linker is -Wl,, and it is needed because gcc itself may not understand the bare -rpath linker option. While some builds of various versions of gcc accept -rpath, I have never seen it documented in gcc man pages or info pages. For better portability, -Wl,-rpath should be preferred.

Resources