- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编译/链接 -nostdlib
似乎阻止静态初始化,即使我添加了自己的 crti.s 和 crtn.s .init
/.fini
部分。
是否有使 g++ 生成插入在 .init
中的静态初始化代码的变通方法?或者我可以手动调用?
这是我尝试过的:
g++ -o test.o -c -fno-use-cxa-atexit test.cc # has _start (entry point)
# that calls _init and _main
as -o crti.o crti.s # has _init in section .init
as -o crtn.o crtn.s
g++ -o test ./crti.o test.o -nodefaultlibs -nostartfiles ./crtn.o
-nodefaultlibs
单独包括静态初始化代码和调用,但强制使用 libc-_start/_init。
-nodefaultlibs -nostartfiles
允许我使用自己的 _start/_init,但不包括代码或对静态初始化的调用。
最佳答案
来自 gcc linker docs ,
-nostdlib
Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker, and options specifying linkage of the system libraries, such as -static-libgcc or -shared-libgcc, are ignored.
g++ -Wl, -static
-Wl passes the next command on to the linker
-static On systems that support dynamic linking, this prevents linking with
the shared libraries. On other systems, this option has no effect.
关于gcc - g++、静态初始化和 -nostdlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10119520/
编译/链接 -nostdlib似乎阻止静态初始化,即使我添加了自己的 crti.s 和 crtn.s .init/.fini部分。 是否有使 g++ 生成插入在 .init 中的静态初始化代码的变通方
如果我使用选项 -nostdlib 调用 GCC 链接器,这是否会覆盖标准库的任何手动/显式附录? GCC 是来自 MinGW 的 4.8.1。 例子: gcc -nostdlib [MyObject
我正在尝试为一个可执行文件设置我自己的运行时环境,但我无法让 clang(v3.4-1ubuntu1,目标:x86_64-pc-linux-gnu)生成一个不支持的可执行文件段错误。我已将问题简化为以
这怎么可能在编译时不将 stdlib (mscorlib.dll) 包含到我的 C# 应用程序中?据我所知,所有类都继承了 System.Object 类,该类定义在 mscorlib.dll 中。更
我有以下代码: void cp(void *a, const void *b, int n) { for (int i = 0; i : 1000: b8 00 00 00 00
我有一个包含构造函数的动态库。 __attribute__ ((constructor)) void construct() { // This is initialization code
我正在试验入口点并遇到段错误。 程序.c: int main() { return 0; } 编译和链接: gcc -Wall prog.c -nostdlib -c -o prog.o
我需要在另一个没有安装 mudflap 库并且具有不同 glibc 版本的 linux 发行版中运行我的程序。我试图用 -static 编译我的程序,但这是不可能的: warning: Using '
我正在尝试生成一个不依赖于 libc(或任何其他)的可执行文件。首先,我这样做了: // test.c void _start() { // write(1, "hello!\n", 7);
我的家庭作业要求我们使用系统调用而不是标准库来打开、读取和写入文件。为了调试它,我想在测试编译项目时使用 std 库。我这样做了: #ifdef HOME //Home debug prinf f
我为链接器提供了我的文件:ld-2.7.so、libc-2.7.so 和 crt1.o,但未能成功编译。是否可以链接到与默认 glibc 不同的 glibc? (静态编译或安装单独的 glibc 不是
我正在使用带有 x84-elf64-gcc 编译器的 64 位 linux 机器。我刚刚开始低级编程,想了解 C 代码实际上是如何翻译成二进制的。这主要用于操作系统开发,因为我知道处理器不理解 ELF
我正在使用带有 x84-elf64-gcc 编译器的 64 位 linux 机器。我刚刚开始低级编程,想了解 C 代码实际上是如何翻译成二进制的。这主要用于操作系统开发,因为我知道处理器不理解 ELF
我在 gcc 编译选项下遇到了 -nostartfiles 和 -nostdlib 选项。但是,我不明白如何为上述选项编写代码。您是否需要编写每个启动函数(如 _start、__libc_csu_in
我编写了一个 Makefile,用另一个应用程序编译我的迷你操作系统。我必须使用 -nostdioc 和 -nostdlib 来编译它们,但问题是,该应用程序正在使用 stdio/stdlib 函数,
我正在尝试使用带有 this toolchain 的 CMake 在 arm 架构中创建一个 hello world 我的主.c int main() { char *str = "Hello W
我是一名优秀的程序员,十分优秀!