When I run qmake, it ends up defining CXX as /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++. which clang++ though sends me to /usr/bin/clang++. No big deal right?
Consider hello.cpp
#include <string>
int main() {
return 0;
}
when I run clang++ hello.cpp it compiles with no issues. But if I use the qmake clang++,
Tims-Air:hello tim$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ hello.cpp
In file included from hello.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:171:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:638:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.
How can I overcome this issue in my qmake Makefile besides hardcoding the clang++ from /usr/bin?
Update. Details reveal that the search paths are different!
Tims-Air:Projects tim$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -v -E -x c++ - < /dev/null
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/tim/Projects -ferror-limit 19 -fmessage-length 165 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.0.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 342 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
and
Tims-Air:Projects tim$ clang++ -v -E -x c++ - < /dev/null
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I/usr/local/include -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/tim/Projects -ferror-limit 19 -fmessage-length 165 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 342 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
Workaround. It can be fixed by adding the 10.13 include as it is missing in the search path. But it sure feels ghetto.
Tims-Air:hello tim$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include hello.cpp
-isysroot does the trick as well
I fixed it by removing all the references to .qmake.stash in the output folder
qmake will also search up the directory hierarchy. If you run qmake directly, you can be sure that you're not using some cached information if it says "Info: creating file .... .qmake.stash"
Related
I have a stripped down spec file that looks like:
Name: some-binary
Version: 6.1.0
Release: 1
License: proprietary
Summary: a binary
%description
Whatever
%install
install -d %{buildroot}/fromrpm
cp %{_sourcedir}/thebinary %{buildroot}//fromrpm/thebinary
%files
/fromrpm/thebinary
Then I run:
$ cd ~/rpmbuild/
$ rpmbuild -bb SPECS/some-binary.spec 2>/dev/null
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.gxRpSj
Processing files: some-binary-6.1.0-1.x86_64
Provides: some-binary = 6.1.0-1 some-binary(x86-64) = 6.1.0-1
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/dspeyer/rpmbuild/BUILDROOT/some-binary-6.1.0-1.x86_64
Wrote: /home/dspeyer/rpmbuild/RPMS/x86_64/some-binary-6.1.0-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.WR3Utx
$ rpm2cpio RPMS/x86_64/some-binary-6.1.0-1.x86_64.rpm | cpio -idmv
./fromrpm/thebinary
41456 blocks
$ readelf -a SOURCES/thebinary | grep rela\\.
[ 5] .rela.plt RELA 0000000000400338 00000338
00 .note.gnu.property .note.gnu.build-id .note.ABI-tag .note.go.buildid .rela.plt
Relocation section '.rela.plt' at offset 0x338 contains 29 entries:
$ readelf -a fromrpm/thebinary | grep rela\\.
[ 6] .rela.got.plt RELA 0000000000000000 0143d048
Relocation section '.rela.got.plt' at offset 0x143d048 contains 29 entries:
I'm not actually sure what the rela tags do, but I strongly suspect they're the reason the post-rpm binary when run on rhel 7.9 immediately crashes trying to crash with "Unexpected reloc type in static binary". Yes, the binary is statically linked. (And, yes, I did say "crashes trying to crash": sigsegv inside __libc_fatal)
Any ideas what rpmbuild is trying to do, or how to stop it?
In x86-64 target Debian, most of the programs are link against shared objects with the /lib64/ld-linux-x86-64.so.2. And there is also one in /lib/x86_64-linux-gnu/, so I delete it as I thought
it is unnecessary :
rm /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
then test :
gcc test.c
it showed as the following :
/usr/bin/ld: cannot find /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 inside /
collect2: error: ld returned 1 exit status
So , why does ld need to find the /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 while the default dynamic linker is /lib64/ld-linux-x86-64.so.2 when linking ?
/lib64/ is a symlink to /usr/lib64/.
cd /lib64/ && ls -l ld-linux-x86-64.so.2
lrwxrwxrwx 1 root .. ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.28.so
cd /usr/lib/x86_64-linux-gnu/
ls -l ld-linux-x86-64.so.2
lrwxrwxrwx 1 root .. ld-linux-x86-64.so.2 -> ld-2.28.so
The main link to the linker ld-2.28.so is /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 : Do not change it. (The link in /lib64/ and /usr/lib64/ is for compatibility reasons with certain software.)
I'm trying to compile a project with esp_iot_sdk 1.30 but I get esptool: Permission denied every time I do make.
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ ls -al
total 36
drwxrwxr-x 7 david david 4096 אפר 24 20:40 .
drwxrwxr-x 6 david david 4096 אפר 20 19:38 ..
drwxrwxr-x 2 david david 4096 אפר 20 16:51 driver
drwxrwxr-x 12 david david 4096 אפר 24 20:40 esp_iot_sdk_v1.3.0
drwxrwxr-x 8 david david 4096 אפר 20 16:51 .git
drwxrwxr-x 3 david david 4096 אפר 20 16:51 include
-rw-rw-r-- 1 david david 4069 אפר 20 19:44 Makefile
-rw-rw-r-- 1 david david 597 אפר 20 16:51 README.md
drwxrwxr-x 2 david david 4096 אפר 20 16:51 user
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ sudo make clean
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ sudo make
CC driver/uart.c
CC user/user_main.c
AR build/app_app.a
LD build/app.out
FW firmware/0x00000.bin
/bin/sh: 1: /home/david/myprojects/esptool: Permission denied
Makefile:109: recipe for target 'firmware/0x00000.bin' failed
make: *** [firmware/0x00000.bin] Error 126
david#david-VirtualBox:~/myprojects/esp8266-injection-example$
There is no global variable ESPTOOL, or FW_TOOL:
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ echo $FW_TOOL
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ echo $ESPTOOL
david#david-VirtualBox:~/myprojects/esp8266-injection-example$
I'm using esp-open sdk. I downloaded esptool from here: http://filez.zoobab.com/esp8266/esptool-0.0.2.zip (according to step 2 here: https://github.com/cnlohr/ws2812esp8266) and made that my FW_TOOL.
I'm tying to compile this project.
I tried this solution but it didn't work (I tried to do it for the esptool folder in esp-open-sdk, and for the esptool folder I downloaded above) viewtopic.php?p=12465
I tried to do sudo chmod 777 esptool, for both esptool folders, and nothing works for me.
NOTE: If I do esptool.py chip_id I do get a response. Also I was able to burn the blinky demo with the new SDK (that came with esp-open-sdk). So it looks like there is a problem with this SDK specifically...
I am also part of dialout group:
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ lsusb
Bus 001 Device 003: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ ls -al /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 אפר 24 20:20 /dev/ttyUSB0
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ groups
david adm dialout cdrom sudo dip plugdev lpadmin sambashare
Please help!
Here is my make file:
david#david-VirtualBox:~/myprojects/esp8266-injection-example$ cat Makefile
# tnx to mamalala
# Changelog
# Changed the variables to include the header file directory
# Added global var for the XTENSA tool root
#
# This make file still needs some work.
#
#
# Output directors to store intermediate compiled files
# relative to the project directory
BUILD_BASE = build
FW_BASE = firmware
# Base directory for the compiler
XTENSA_TOOLS_ROOT ?= ~/myprojects/esp-open-sdk/xtensa-lx106-elf/bin
# base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= $(CURDIR)/esp_iot_sdk_v1.3.0
#Esptool.py path and port
ESPTOOL ?= ~/myprojects/esp-open-sdk/esptool/esptool.py
ESPPORT ?= /dev/ttyUSB0
# name for the target project
TARGET = app
# which modules (subdirectories) of the project to include in compiling
MODULES = driver user
EXTRA_INCDIR = include ~/myprojects/esp-open-sdk/xtensa-lx106-elf/include
# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal pp phy net80211 lwip wpa main
# compiler flags using during compilation of source files
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
# linker script used for the above linkier step
LD_SCRIPT = eagle.app.v6.ld
# various paths from the SDK used in this project
SDK_LIBDIR = lib
SDK_LDDIR = ld
SDK_INCDIR = include include/json
# we create two different files for uploading into the flash
# these are the names and options to generate them
FW_FILE_1 = 0x00000
FW_FILE_1_ARGS = -bo $# -bs .text -bs .data -bs .rodata -bc -ec
FW_FILE_2 = 0x40000
FW_FILE_2_ARGS = -es .irom0.text $# -ec
# select which tools to use as compiler, librarian and linker
CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
####
#### no user configurable options below here
####
FW_TOOL ?= ~/myprojects/esptool
SRC_DIR := $(MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT))
INCDIR := $(addprefix -I,$(SRC_DIR))
EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR))
MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin)
FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin)
V ?= $(VERBOSE)
ifeq ("$(V)","1")
Q :=
vecho := #true
else
Q := #
vecho := #echo
endif
vpath %.c $(SRC_DIR)
define compile-objects
$1/%.o: %.c
$(vecho) "CC $$<"
$(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$#
endef
.PHONY: all checkdirs flash clean
all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2)
$(FW_FILE_1): $(TARGET_OUT)
$(vecho) "FW $#"
$(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS)
$(FW_FILE_2): $(TARGET_OUT)
$(vecho) "FW $#"
$(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS)
$(TARGET_OUT): $(APP_AR)
$(vecho) "LD $#"
$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $#
$(APP_AR): $(OBJ)
$(vecho) "AR $#"
$(Q) $(AR) cru $# $^
checkdirs: $(BUILD_DIR) $(FW_BASE)
$(BUILD_DIR):
$(Q) mkdir -p $#
firmware:
$(Q) mkdir -p $#
flash: firmware/0x00000.bin firmware/0x40000.bin
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
clean:
$(Q) rm -f $(APP_AR)
$(Q) rm -f $(TARGET_OUT)
$(Q) rm -rf $(BUILD_DIR)
$(Q) rm -rf $(BUILD_BASE)
$(Q) rm -f $(FW_FILE_1)
$(Q) rm -f $(FW_FILE_2)
$(Q) rm -rf $(FW_BASE)
I'm using arm-linux-gcc to compile a simple C file at host (debian i386) with -g.
Then copy the a.out file to the target (arm,uclibc) computer.
Run the a.out – it's just ok.
Use GDB (target) gdb a.out and list the source code, it says No such file or directory.
The fact has always been so?
If I copy the 1.c file to the target, then list command it lists the source code.
My Question:
GDB has always been so, or there are other options I can control?
Do you have any suggestions to debug the program?
Some information maybe is useful:
source code 1.c file:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// main function
int main(void)
{
int i;
for(i=0;i<3;i++){
printf("i=%d\n",i);
}
return 0;
}
cross compile version(host)
zodiac1111#debian:tmp$ arm-linux-gcc -v
Using built-in specs.
Target:arm-unknown-linux-uclibcgnueabi
Configured with:/home/ldsh/rt9x5/linux/buildroot/buildroot/output/toolchain/gcc-4.3.5/configure \
--prefix=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu \
--target=arm-unknown-linux-uclibcgnueabi --enable-languages=c,c++ \
--with-sysroot=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/sysroot \
--with-build-time-tools=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/bin \
--disable-__cxa_atexit --enable-target-optspace --disable-libgomp --with-gnu-ld --disable-libssp \
--disable-multilib --disable-tls --enable-shared --with-gmp=/opt/rt9x5/arm-linux-uclibcgnueabi/usr \
--with-mpfr=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --enable-threads --disable-decimal-float \
--with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=arm926ej-s \
--with-pkgversion='Buildroot 2011.05-dirty' \
--with-bugurl=http://bugs.buildroot.net/ : (reconfigured) /home/ldsh/rt9x5/linux/buildroot/buildroot/output/toolchain/gcc-4.3.5/configure \
--prefix=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu \
--target=arm-unknown-linux-uclibcgnueabi --enable-languages=c,c++ \
--with-sysroot=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/sysroot \
--with-build-time-tools=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/bin \
--disable-__cxa_atexit --enable-target-optspace --disable-libgomp --with-gnu-ld --disable-libssp \
--disable-multilib --disable-tls --enable-shared --with-gmp=/opt/rt9x5/arm-linux-uclibcgnueabi/usr \
--with-mpfr=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --enable-threads --disable-decimal-float \
--with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=arm926ej-s \
--with-pkgversion='Buildroot 2011.05-dirty' --with-bugurl=http://bugs.buildroot.net/
Thread model:posix
gcc version 4.3.5 (Buildroot 2011.05-dirty)
compile command:
arm-linux-gcc -g 1.c
host:
zodiac1111#debian:tmp$ uname -a
Linux debian 3.12-1-686-pae #1 SMP Debian 3.12.9-1 (2014-02-01) i686 GNU/Linux
target:
# uname -a
Linux AT91SAM9-RT9x5 2.6.39 #25 Mon Dec 30 17:40:40 CST 2013 armv5tejl GNU/Linux
after copy to the target,then:
# ls -l
total 1
-rwxr--r-- 1 ftp 83 6094 Feb 21 15:19 a.out
execute is ok
# ./a.out
i=0
i=1
i=2
the target gdb version
# gdb -v
dlopen failed on 'libthread_db.so.1' - File not found
GDB will not be able to debug pthreads.
GNU gdb 6.8
Copyright (C) 2008 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 "arm-unknown-linux-uclibcgnueabi".
debug a.out
# gdb a.out
<...>
(gdb) list
1 1.c: No such file or directory.
in 1.c
(gdb) break main
Breakpoint 1 at 0x847c: file 1.c, line 8.
(gdb) run
Starting program: /data/a.out
Breakpoint 1, main () at 1.c:8
8 in 1.c
(gdb) step
9 in 1.c
(gdb) p i
$1 = 0
(gdb) step
i=0
8 in 1.c
(gdb) p i
$2 = 0
(gdb) step
9 in 1.c
(gdb) p i
$3 = 1
(gdb)
if I copy the source code file 1.c into the same directory
# ls -l
-rw-r--r-- 1 ftp 83 158 Feb 21 15:51 1.c
-rwxr--r-- 1 ftp 83 6094 Feb 21 15:19 a.out
gdb could list the source code now.
# gdb a.out
<...>
(gdb) list
warning: Source file is more recent than executable.
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 // main function
5 int main(void)
6 {
7 int i;
8 for(i=0;i<3;i++){
9 printf("i=%d\n",i);
10 }
(gdb)
At host Platform,if I
compile with gcc -g 1.c at host platform.
than rename or remove the 1.c file.
Usegdb a.out
The same situation occurs.
zodiac1111#debian:tmp$ gdb -v
GNU gdb (GDB) 7.6.2 (Debian 7.6.2-1)
Copyright (C) 2013 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 "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
zodiac1111#debian:tmp$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.8/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.8.2-14' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --with-arch-32=i586 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.8.2 (Debian 4.8.2-14)
Read carefully the documentation of GDB notably about source path. You want to use the dir command
Also, switch to a newer gdb (perhaps by compiling gdb from its source code). Current version is 7.7 (so 6.8 is really old)
AFAIK you need a copy of source on your target machine (where you run the debugger).
Another way to debug this is to run your code under gdbserver on target machine, then connect to gdbserver from your PC.
So, first on target machine do something like:
gdbserver localhost:9999 a.out
Then on your PC do:
gdb a.out
target remote your-target-ip-or-name:9999
...
For me compiling with your switches and then trying to list source in gdb lists source as expected. You must not move source or binary around, or gdb will not be able to locate it.
First the question:
I need a way without placing a config file in /etc/ld.so.conf.d to allow clients to build against my SDK on both RHEL5.7 and RHEL6.1 using the default install of gcc. Setting the LD_LIBRARY_PATH does not work in this case. Are there any other ways to allow clients to link against my sdk without having to provide them with a knowledge base article on how to configure their system? Please read below for clarification.
Second the senario:
I am responsible for the build of a runtime SDK on both RHEL5 and RHEL6. My RHEL5.7 box is a standard non-registered install as is my RHEL6.1 box. However, on my RHEL6 box I have compiled gcc myself:
[mehoggan#hoggant35002 ~]$ cat /etc/redhat-release; gcc --version
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51)
Copyright (C) 2006 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 PURPOS
--
[mehoggan#hogganz400 session2]$ cat /etc/redhat-release; gcc --version
Red Hat Enterprise Linux Server release 6.1 (Santiago)
gcc (GCC) 4.5.2
Copyright (C) 2010 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
--
I cannot provide the .so and .a files I am trying to link against. However, I will attempt to depict what is happening. Taking the same source and building it against my SDK and running it. I get the following results:
RHEL 6 Box:
[mehoggan#hogganz400 session2]$ ls -l
total 1848
-rw-rw-r-- 1 mehoggan mehoggan 189 Nov 3 13:02 main.cpp
-rw-rw-r-- 1 mehoggan mehoggan 845 Nov 3 13:02 mainwindow.cpp
-rw-rw-r-- 1 mehoggan mehoggan 288 Nov 3 13:02 mainwindow.h
-rwxrwxr-x 1 mehoggan mehoggan 25818 Nov 4 09:26 Session2
-rw-rw-r-- 1 mehoggan mehoggan 649 Nov 3 13:02 Session2.pro
-rw-rw-r-- 1 mehoggan mehoggan 1847296 Nov 3 13:02 vc90.pdb
[mehoggan#hogganz400 session2]$ qmake
[mehoggan#hogganz400 session2]$ cat Session2.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-10-21T09:32:55
#
#-------------------------------------------------
QT += core gui
TARGET = Session2
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
#Modify the path accordingly
CONFIG += debug_and_release
INCLUDEPATH += "/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/include"
CONFIG(debug, debug|release) {
LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
-lArcGISQtd
} else {
LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
-lArcGISQt
}
[mehoggan#hogganz400 session2]$ make
make -f Makefile.Release
make[1]: Entering directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/main.o main.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/mainwindow.o mainwindow.cpp
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease mainwindow.h -o release/moc_mainwindow.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/moc_mainwindow.o release/moc_mainwindow.cpp
g++ -m64 -Wl,-O1 -Wl,-rpath,/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -o Session2 release/main.o release/mainwindow.o release/moc_mainwindow.o -L/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -L/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin -lArcGISQt -lQtGui -lQtCore -lpthread
make[1]: Leaving directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
[mehoggan#hogganz400 session2]$ echo ${LD_LIBRARY_PATH}
/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine/supp:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine/supp:
[mehoggan#hogganz400 session2]$ ./Session2
./Session2: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by /home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so.1)
If I run the following command: export LD_LIBRARY_PATH=/usr/local/lib64:${LD_LIBRARY_PATH}; ./Session2 or set the path to the compiled version of libstdc++ in /etc/ld.so.conf.d the application runs.
RHEL5 Box:
[mehoggan#hoggant35002 session2]$ ls -l
total 1852
-rw-rw-r-- 1 mehoggan mehoggan 189 Nov 3 15:21 main.cpp
-rw-rw-r-- 1 mehoggan mehoggan 845 Nov 3 15:21 mainwindow.cpp
-rw-rw-r-- 1 mehoggan mehoggan 288 Nov 3 15:21 mainwindow.h
-rw-rw-r-- 1 mehoggan mehoggan 649 Nov 3 15:21 Session2.pro
-rw-rw-r-- 1 mehoggan mehoggan 25151 Nov 3 15:51 Session2.pro.user
-rw-rw-r-- 1 mehoggan mehoggan 1847296 Nov 3 15:21 vc90.pdb
[mehoggan#hoggant35002 session2]$ qmake
[mehoggan#hoggant35002 session2]$ ls -l ./Session2.pro
-rw-rw-r-- 1 mehoggan mehoggan 649 Nov 3 15:21 ./Session2.pro
[mehoggan#hoggant35002 session2]$ cat ./Session2.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-10-21T09:32:55
#
#-------------------------------------------------
QT += core gui
TARGET = Session2
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
#Modify the path accordingly
CONFIG += debug_and_release
INCLUDEPATH += "/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/include"
CONFIG(debug, debug|release) {
LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
-lArcGISQtd
} else {
LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
-lArcGISQt
}
[mehoggan#hoggant35002 session2]$ make
make -f Makefile.Release
make[1]: Entering directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/main.o main.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/mainwindow.o mainwindow.cpp
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease mainwindow.h -o release/moc_mainwindow.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/moc_mainwindow.o release/moc_mainwindow.cpp
g++ -m64 -Wl,-O1 -Wl,-rpath,/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -o Session2 release/main.o release/mainwindow.o release/moc_mainwindow.o -L/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -L/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin -lArcGISQt -lQtGui -lQtCore -lpthread
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so: undefined reference to `FT_Library_SetLcdFilter'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::_List_node_base::_M_unhook()#GLIBCXX_3.4.14'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)#GLIBCXX_3.4.9'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::_List_node_base::_M_hook(std::_List_node_base*)#GLIBCXX_3.4.14'
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so: undefined reference to `FcFreeTypeQueryFace'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::basic_ostream<char, std::char_traits<char> >::_M_insert<double>(double)#GLIBCXX_3.4.9'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::ctype<char>::_M_widen_init() const#GLIBCXX_3.4.11'
collect2: ld returned 1 exit status
make[1]: *** [Session2] Error 1
make[1]: Leaving directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
make: *** [release] Error 2
This is getting to be a really long post, and I think I have provided enough to start helping. Please let me know if you need anything specific to help.
One last bit of information on the libstdc++ I am linking against.
RHEL6:
[mehoggan#hogganz400 session2]$ strings /usr/local/lib64/libstdc++.so.6 | grep GLIB
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
RHEL5:
[mehoggan#hoggant35002 session2]$ strings /usr/lib64/libstdc++.so.6 | grep GLIBC
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.4
GLIBC_2.2.5
GLIBCXX_FORCE_NEW
It looks like your Qt libraries (libQtGui.so and libArcGISQt.so) have a dependency on GLIBCXX_3.4.14, which is not present on your RHEL 5 box, probably as you built and installed it (Qt) on your RHEL 6 box. You need to build Qt on RHEL 5, or provide access to the updated 3.4.14 lib on the RHEL 5 box. Anyone who wants to run your binary will need access to the correct versions of the shared libraries it was built against.
In order to have 'access' to a library, it needs to be readable on the machine in question and be in a location that is either configured in ld.so.conf, in the LD_LIBRARY_PATH envvar at the app is run, OR configured into the executable via a -rpath link option.
One linking option I find EXTREMELY useful for avoiding/dealing with this issue is -Wl,-rpath,'$ORIGIN'. This will cause the application to look in the directory containing the executable for dynamic libs as well as (and in preference to) ld.so.conf. So you can build an executable and give people a package with the executable and a bunch of .so dynamic libs and tell them "either install the .so files on your machine or stick them all in the same directory as the executable, whichever you prefer" and then they can run the executable without too much trouble. This allows for a single binary package that can be used on pretty much any linux variant.
Note that when you put this option in a Makefile it generally needs to be -Wl,-rpath,'$$ORIGIN' as make will treat the $ as a variable expansion ($$ expands to $). qmake may be the same.