首先要修改Makefile,把gdbserver做成静态链接,避免出现库问题。
Can't resolve symbol 'personality'
CFLAGS = -g -O2 -static
./configure --target=arm-linux --prefix=/opt/gdbserver/ --host=arm-linux
或者
./configure --host=x86_64-openwrt-linux --target=x86_64-openwrt-linux --prefix=/dest/path/gdb_server CC=/Path_to/OpenWrt-SDK-15.05.1-x86-64_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-x86_64_gcc-4.8-linaro_uClibc-0.9.33.2/bin/x86_64-openwrt-linux-gcc
./configure --target=arm-linux --prefix=/opt/arm-linux-gdb/ make && make install 编交叉工具gdb,所以需要指定taget,没指定build和host,那么属于本地编译,编译出来的arm-gdb运行于本地
./configure --target=arm-linux --prefix=/opt/gdbserver/ --host=arm-linux make && make install 编交叉工具gdbserver 有target,是要编译交叉工具;build默认本机,host不等于build,属于交叉编译;编译出来的gdb-server运行于host机上,它要处理的taget也是arm-linux,对接arm-linux-gdb
vim Makefile 加-static ; 或者CFLAGS='-static' ./configure ....; 或者 ./configure CFLAGS='-static' 都可能会出错
先不加静态编译,直接make & make install
之后再改Makefile加-static, 再执行一遍make & make install, 此时就能编出gdbserver的静态版本了
--target , --host的值其实就是交叉编译工具的前缀
在进行./configure --host=x86_64-nacl --target=x86_64-nacl时,会检查对应的gcc, ar等工具是否存在
板子上跑: ./gdbserver banziip:port test_bin
主机上跑 ./arm-linux-gdb test_bin
(gdb) target remote banziip:ip
(gdb) c
binutils包含底下这些指令:
as |
汇编器 |
ld |
链接器 |
gprof |
性能分析工具程序 |
addr2line |
从目标文件的虚拟地址获取文件的行号或符号 |
ar |
可以对静态库做创建、修改和取出的操作。 |
c++filt |
解码 C++ 的符号 |
dlltool |
创建Windows 动态库 |
gold |
另一种链接器 |
nlmconv |
可以转换成NetWare Loadable Module目标文件格式 |
nm |
显示目标文件内的符号 |
objcopy |
复制目标文件,进程中可以修改 |
objdump |
显示目标文件的相关信息,亦可反汇编 |
ranlib |
产生静态库的索引 |
readelf |
显示ELF文件的内容 |
size |
列出总体和section的大小 |
strings |
列出任何二进制档内的可显示字符串 |
strip |
从目标文件中移除符号 |
windmc |
产生Windows消息资源 |
windres |
Windows 资源档编译器 |
http://landley.net/writing/docs/cross-compiling.html
Host vs Target
A compiler is a program that turns source code into executable code. Like all programs, a compiler runs on a specific type of computer, and the new programs it outputs also run on a specific type of computer.[1]
The computer the compiler runs on is called the host, and the computer the new programs run on is called the target. When the host and target are the same type of machine, the compiler is a native compiler. When the host and target are different, the compiler is a cross compiler.[2]
https://www.cnblogs.com/my_life/articles/10675475.html
编译器compiler本身也是平台相关的:在x86机器上使用x86版本的gcc来编译target arm的应用程序;也可以在mips机器上使用mips版本的gcc来编译target为arm的应用程序。
【实例】
当前我有一个x86计算机,它上面工具很全,至少有gcc。这时我有了一个arm处理器的上网本。
我想为我的arm上网本写点程序,但是因为上网本性能很差我不想在arm上开发编译,于是我就想在自己电脑上开发然后copy过去给他用。
这时我就需要一个在我的x86(build)上编译一个“可以在我x86(host)本机上运行的gcc,这个新gcc编出来的程序是可以在arm(target)上运行的”。 此时选项为 build=x86,host=x86,target = arm。
此时我用这个gcc编译一个helloworld,这个helloworld的build=x86,host=arm
后来我又得到了一个超强服务器计算机,假设框架叫Super。我想用服务器编译比用我的x86要快的多,于是我就想在Super上用Gcc编译arm程序。但是我怎么得到在Super上能跑起来的gcc呢?当然是自己编译。
于是我就需要在我的x86(build)上编译一个能在Super(host)上运行的gcc,而且它编出来的程序是在arm(target)上运行。此时选项为 build=x86,host=Super,target = arm。
此时我用这个gcc编译一个helloworld,这个helloworld的build=Super,host=arm
【build】当前你使用的计算机。
【host】你的目的是编译出来的程序可以在host上运行。 指定用来编译target所使用的GCC的运行平台!
【target】普通程序没有这个概念。对于想编译出编译器的人来说此属性决定了新编译器编译出的程序可以运行在哪!
---------------------
作者:牛晨光
来源:CSDN
原文:https://blog.csdn.net/ChrisNiu1984/article/details/6620709
版权声明:本文为博主原创文章,转载请附上博文链接! 感觉说的都是错的
--build:
表示目前我们正在运行的平台名称是什么,如果当前我们是在intel的pentium机器中编译该系统,那么我们的--build就可能是 i686-pc-linux-gnu!
当然如果我们在其它种类的机器上编译那么这个build就应该是那个机器所对应的平台名称。
该参数在不指定的情况下将自动常识猜测目前平台的名称。
--host:
表示我们把这个编译好的gcc在什么样的平台下运行,在交叉编译过程中这个需要我们来指定,
因为机器自己是不能知道我们心里是怎么想的, 那么我们可以明确的告诉它,我们要做出来的程序是运行在“龙芯”上的,但是目前还不能直接指定“龙芯”。
因此我们这里指定为 mips64el- unknown-linux-gnu(如果你省点事情那么就用这个名字好了,如果你想用个有个性的名字,那么请你想明白它的含义再动手,
并且做好后面的过 程需要多出一些手续的麻烦的心理准备)。
--host也可以不指定,那么host将自动使用build来定义自己,不过那将不再是交叉编译。
注:--build 和 --host 在不同的时候就被配置文件认定为交叉编译方式。
--target:
该参数的目的是让配置程序知道这个软件被编译后使用来处理什么平台上的文件的。
target这个参数只有在为数不多的几个包中有用处,虽然在 ./configure --help中经常能看到该参数,但实际上绝大多数软件包都是不需要该参数的。
从这个参数的含义来看,说明其处理的目标只有在不同平台下表现为不同的时候才有作用,而这些文件通常都跟目标平台 的指令系统直接或间接有关:
比如可执行文件,对于不同平台下使用的可执行文件的编码可以是完全不同的,因此必须使用 对应能处理该编码的程序才能正确处理,
而如果错误的使用则可能导致程序错误或者破坏文件,对于这样要处理不同平台下会 出现不同编码的软件,我们就应当对它指定目标平台,以免另其错误处理;
而对于文本文件,对于不同的平台同样的内容表达的 含义都是相同的,因此我们不需要专门针对平台来处理,这样的软件我们就可以不必对它指定需要处理的平台了。
3. 总结一下
build:自动测试在用平台名称,若无法检测出来则需要指定。
host:若无指定,自动使用 build 的结果。
build 和 host 相同时表示本地编译,若不相同则表示交叉编译。
target:表示需要处理的目标平台名称,若无指定使用 host 相同名称,gcc、binutils, gdb 等与平台指令相关的软件都有此参数,多数软件此参数无用处。
--build=BUILD configure for building on BUILD [guessed] 当前进行编译的机器,无论是用来编译交叉供给链 还是 用来编译目标机器平台上的执行程序,可guess出来
--host=HOST cross-compile to build programs to run on HOST [BUILD] 交叉编译出来的程序要执行在哪个平台下
--target=TARGET configure for building compilers for TARGET [HOST] 编译哪个平台的交叉编译链,一般软件无需这参数
下面举几个例子,虽然是英文,但是很好理解。
1. `./configure --build=mipsel-linux --host=mipsel-linux --target=mipsel-linux'
will build native mipsel-linux binutils on mipsel-linux.
2. `./configure --build=i386-linux --host=mipsel-linux --target=mipsel-linux'
will cross-build native mipsel-linux binutils on i386-linux.
3. `./configure --build=i386-linux --host=i386-linux --target=mipsel-linux'
will build mipsel-linux cross-binutils on i386-linux.
4. `./configure --build=mipsel-linux --host=i386-linux --target=mipsel-linux'
will cross-build mipsel-linux cross-binutils for i386-linux on mipsel-linux.
---------------------
作者:veryitman
来源:CSDN
原文:https://blog.csdn.net/veryitman/article/details/7051680
版权声明:本文为博主原创文章,转载请附上博文链接!
一般来说,我们平时所说的交叉编译用不到target的,比如. /configure --build=i386-linux --host=arm-linux就可以了,在386的平台上编译可以运行在arm板的程序.
但是,一般我们都是编译程序,而不是编译工具, 如果我们编译工具,比如gcc、gdb, 这个target就有用了.
如果我们需要在一个我们的机器上为arm开发板编译一个可以处理 mips程序的gcc,那么target就是mips了
==================================
–target仅适用于编译工具链。当你正在做一个库或二进制文件的正常交叉编译
--build=the architecture of the build machine
--host=the architecture that you want the file to run on
但是,当你构建工具链时,事情会变得更复杂。:
比如说你有:
>一个powerpc构建机器,你要做所有的编译
>几个嵌入式设备,用mips处理器,你的代码将运行
>一个x86笔记本电脑,你将用于调试这些设备在现场
您将配置和构建您的调试服务器(例如gdbserver)以在嵌入式设备上运行
./configure --build=powerpc --host=mips 在powerpc上编译,编译出来的程序跑在mips上;因为build和host不同,所以这是一个交叉编译
所以你可以putty到你的嵌入式设备,并运行“gdbserver:1234 a.out”开始调试和侦听端口1234。
然后,您将构建您的调试客户端(连接到并控制gdbserver)
./configure --build=powerpc --host=i686 --target=mips 在powerpc上编译,编译出来的程序跑在i686上,它是为了调试上面生成的mips程序
它会复制到您的x86笔记本电脑,以便在字段中,你可以运行“gdbclient embedded.device:1234”,以调试您的a.out程序。
这一切都适用于编译器,你可能想看看上面的GCC链接或本节关于Canadian cross编译。
还要注意,在实践中,您可能不会看到build,host或target,因为根据this Autoconf manual page,“target默认为host,host to build,并构建到config.guess的结果。
总而言之,在–build上构建代码,使用–target架构环境在–host上运行它。