相关疑难解决方法(0)

使用gcc mingw嵌入二进制blob

我试图将二进制blob嵌入到exe文件中.我正在使用mingw gcc.

我像这样制作目标文件:

ld -r -b binary -o binary.o input.txt
Run Code Online (Sandbox Code Playgroud)

然后我看objdump输出来获取符号:

objdump -x binary.o
Run Code Online (Sandbox Code Playgroud)

它给出了符号:

_binary_input_txt_start
_binary_input_txt_end
_binary_input_txt_size
Run Code Online (Sandbox Code Playgroud)

然后我尝试在我的C程序中访问它们:

#include <stdlib.h>
#include <stdio.h>

extern char _binary_input_txt_start[];

int main (int argc, char *argv[])
{
    char *p;
    p = _binary_input_txt_start;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后我这样编译:

gcc -o test.exe test.c binary.o
Run Code Online (Sandbox Code Playgroud)

但我总是得到:

undefined reference to _binary_input_txt_start
Run Code Online (Sandbox Code Playgroud)

有谁知道我做错了什么?

c binary gcc mingw

45
推荐指数
3
解决办法
1万
查看次数

函数名称由编译器以下划线为前缀的原因是什么?

当我看到C应用程序的汇编代码时,如下所示:

emacs hello.c
clang -S -O hello.c -o hello.s
cat hello.s
Run Code Online (Sandbox Code Playgroud)

函数名称以下划线为前缀(例如callq _printf).为什么要这样做,它有什么优势?


例:

你好ç

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {
  char *myString = malloc(strlen("Hello, World!") + 1);
  memcpy(myString, "Hello, World!", strlen("Hello, World!") + 1);
  printf("%s", myString);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

hello.s

_main:                       ; Here
Leh_func_begin0:
    pushq   %rbp
Ltmp0:
    movq    %rsp, %rbp
Ltmp1:
    movl    $14, %edi
    callq   _malloc          ; Here
    movabsq $6278066737626506568, %rcx
    movq    %rcx, (%rax)
    movw    $33, 12(%rax)
    movl    $1684828783, 8(%rax)
    leaq    L_.str1(%rip), %rdi
    movq …
Run Code Online (Sandbox Code Playgroud)

c assembly naming compilation function

37
推荐指数
2
解决办法
1万
查看次数

用Newlib实现write(),_ write()或_write_r()?

我正在尝试将printf()使用Newlib作为标准C库的ARM GCC工具链环境中的STM32F411RET微控制器的功能重定向。

当我寻找如何重新定位时printf(),很多人说我需要实施_write()_write_r()。而且似乎都可行。

但是我仍然对它们有疑问:

  1. 当我浏览Newlib文档时,它说我可以实现write()输出文件,但是看起来不起作用。看起来我们可以实现,_write()但是此功能在文档中从未提及。发生什么事了write()?下划线有什么不同吗?

  2. 在哪种情况下_write_r()_wirte()?我不了解C语言中的可重入性概念。有什么例子吗?

感谢您阅读本文。

c embedded gcc arm newlib

6
推荐指数
1
解决办法
5074
查看次数

使用C创建一个小型的可执行文件

出于好奇心的考虑,我试图看看用最少的汇编语言制作C程序的最小.我想看看我是否可以使用动态链接的OpenGL和GLUT进行简单的OpenGL演示(即演示场景),而无需标准库.但是,我遇到了最基本的问题.

我创建了一个包含的测试main.c文件

void newStart() {
  //Do stuff here...

  asm("movl $1, %eax;"
      "xorl %ebx, %ebx;"
      "int  $0x80;");
}
Run Code Online (Sandbox Code Playgroud)

我正在制作它

gcc main.c -nostdlib -e newStart -o min
Run Code Online (Sandbox Code Playgroud)

使用此StackOverflow问题建议的'-e'选项.我尝试编译时遇到以下错误:

ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
ld: entry point (newStart) undefined. for architecture x86_64
Run Code Online (Sandbox Code Playgroud)

我正在运行OS X 10.7(Lion).谁能帮我吗?

c macos assembly

5
推荐指数
1
解决办法
574
查看次数

使用gcc编译时,函数和变量前面是否为"_"?

我正在使用GCC在Linux环境中学习OS开发.我在Bran的内核开发中了解到,编译时C中的所有函数和变量名都在其相应的汇编源文件中以"_"(下划线)开头.但是当我浏览已编译的C程序的汇编源代码时,我甚至找不到"_main"函数.我执行了以下操作.

cpp sample.c sample.i

gcc -S sample.I

c gcc operating-system kernel

4
推荐指数
1
解决办法
336
查看次数

标签 统计

c ×5

gcc ×3

assembly ×2

arm ×1

binary ×1

compilation ×1

embedded ×1

function ×1

kernel ×1

macos ×1

mingw ×1

naming ×1

newlib ×1

operating-system ×1