- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试生成一个不依赖于 libc(或任何其他)的可执行文件。首先,我这样做了:
// test.c
void _start()
{
// write(1, "hello!\n", 7);
asm ("int $0x80"::"a"(4), "b"(1), "c"("hello!\n"), "d"(7));
// exit(0);
asm ("int $0x80"::"a"(1), "b"(0));
}
用 gcc -m32 -nostdlib test.c -o test
编译:
hello
到目前为止一切顺利。后来我尝试使用一些更“高级”的 C,比如 long long
。在 32 位平台上(我的情况)这需要 libgcc
:
// test.c
void _start()
{
volatile long long int a = 10;
volatile long long int b = 5;
volatile int c = a/b; // Implemented as a call to '__divdi3'
}
编译失败,undefined reference to '__divdi3'
。似乎是正确的,因为我实际上并没有告诉它链接。但是添加标志 -static-libgcc
并不能解决问题!为什么?
请注意,我无法动态链接到 libgcc。以下必须成立:
$ ldd test
not a dynamic executable
我正在使用 gcc 4.8.2 从 64 位 Ubuntu 14.04 编译(没什么特别的)。
最佳答案
最终我自己找到了解决方案。似乎 gcc 无法找到该库,也没有费心去提示它。我运行了以下命令:
$ locate libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/32/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/x32/libgcc.a
然后我没有将 -static-libgcc
提供给编译器,而是将标志更改为:
gcc -m32 -nostdlib test.c -o test -L/usr/lib/gcc/x86_64-linux-gnu/4.8/32 -lgcc
它编译并运行得很好!
-L
是多余的。以下也适用:
gcc -m32 -nostdlib test.c -o test -lgcc
关于c - 将 libgcc 链接到 -nostdlib 编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23410221/
据我所知,libgcc 实现了一些 libc 函数,当程序使用内置函数并且 gcc 决定不通过某些内联汇编实现它时调用这些函数。然而,是否有可能让 gcc 始终将所有内置函数作为对 libgcc 的调
我正在尝试为 i386-elf 目标构建 gcc 4.6。 我的问题如下。编译 libgcc 时,我得到了使用全局偏移表的 output-file _fixunsdfdi.o。 该函数用于将 'dou
我一直在 Mac OS X 10.6 上使用 GCC 4.6.2。我在编译时使用 -static-libgcc 选项,否则我的二进制文件会在系统上寻找 libgcc,我不确定 OS X 是否支持 GC
我正在用 C++ 编写一个 Windows DLL。这个库只有 C 接口(interface),并且只使用也有 C 接口(interface)的标准 Windows 库。因此,将所有 C++ 库静态链
当我编译一个二进制文件时,即使我有依赖项,我仍然会收到以下错误。 /usr/bin/ld: 找不到 -l-static-libgcc /usr/bin/ld: 找不到-l-static-libstdc
我正在尝试编译 zbar-0.10 以静态链接到 MinGW 依赖项,因此它不需要 libgcc_s_dw2-1.dll、libwinpthread-1.dll 和 libstdc++-6.dll。
我有一个带有为目标平台编译的 libgcc 的交叉编译器,但不存在标准 C 库。 libgcc 依赖于哪些函数,我在哪里可以找到这些信息? 最佳答案 这些是 libgcc 所依赖的 C 函数:: 强
我目前正在尝试将我所有应用程序的依赖项编译为静态库。我的动机: 不依赖任何操作系统提供的库以拥有完美可重现的代码库 避免在其他系统上部署时由动态链接引起的问题 在链接不同版本的库时避免运行时冲突 能够
我们已经使用 RPM 文件在 AIX 6.1 上安装了 GCC 和 libgcc。 我想知道的是为什么“libgcc_s.a”没有创建在下面的文件夹下? /opt/freeware/lib/gcc/p
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我正在尝试安装交叉编译器,this tutorial ,当我想制作 libgcc 时,我只是把 make all-target-libgcc在我的终端。这会抛出错误 checking whether
我正在尝试生成一个不依赖于 libc(或任何其他)的可执行文件。首先,我这样做了: // test.c void _start() { // write(1, "hello!\n", 7);
我正在尝试使用 Google Toolchain 为我的 Android 手机独立编译内核,并且已经尝试过 Uber 和 linarc。 他们都给出了同样的错误,我不明白: /home/aayushg
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
int main(int argc, char **argv) { return 0; } 我交叉编译(host=linux x86_64,target=linux aarch64) /pat
我一直在使用clang-3.5愉快地构建musl libc的位码版本和使用结果生成漂亮的独立可执行文件。 最近对clang-3.8的尝试并不那么令人满意。看起来位代码 clang-3.8 生成使用 中
我正在尝试为 Android 交叉编译一个非常简单的程序,该程序适用于 android-ndk-r6b 和之前的版本,但不适用于 android-ndk- r7 及更新版本: int main() {
我正在尝试构建 GCC 4.7.3。当我用相当旧的系统 GCC 4.1 构建它时,一切正常,我得到了 GCC 4.7.3。但是当我试图用刚刚编译的 GCC 4.7.3(实际上是自己构建)重建它时,我遇
我尝试使用 -static -static-libgcc -static-libstdc++ 编译项目,以便静态链接库。但是,exec 是用动态链接库编译的。我尝试重新安装 gcc 和 g++ 但它没
我在将 libgcc 链接到静态链接 .so 时遇到问题 它仅在使用 -m64 链接 64 位模块时发生 Ubuntu 64 位 12.10 gcc 4.7 在 Ubuntu 64 位 12.04 g
我是一名优秀的程序员,十分优秀!