简体   繁体   中英

g++ -g option is not working only in makefile

Weirdly -g in my makefile is not working. Possibly its using different g++ version?

Here's my makefile

.default: all

all: linkedlist

clean:
    rm -f linkedlist *.o

linkedlist: main.o list.o
    g++ -Wall -Werror --std=c++14 -g -O -o $@ $^

%.0: %.cpp
    g++ -Wall -Werror --std=c++14 -g -O -c $^

Here's the output:

╰ make
c++    -c -o main.o main.cpp
c++    -c -o list.o list.cpp
g++ -Wall -Werror --std=c++14 -g -O -o linkedlist main.o list.o

But it doesn't work with my lldb. However if i generate it manually

g++ -Wall -Werror -g --std=c++14 -O -o linkedlist list.cpp main.cpp , my debugger works and I also notice that it generates linkedlist.dSYM folder (with the makefile it doesn't). I'm not sure but I think before I updated my xcode last week, I never saw.dSYM file when generating binaries with -g.

Any idea why?

Cheers

G++ Version:

╰ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

You have a mistake in your Makefile

%.0: %.cpp

should be

%.o: %.cpp

The letter 'o', not the number zero.

Because of this mistake you were using the default rules for compiling C++ code, and those didn't include the -g option, and potentially are using a different compiler, c++ vs g++.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM