Articles of gcc

从源代码编译gcc(问题)

我想从源码编译一个gcc,因为我不能使用yum,apt-get等等。 我的步骤很简单: – 我在我的电脑上下载了GCC源代码(我尝试了gcc-4.8.4和gcc-5.3.0) ./contrib/download_prerequisites 在此之后,我使用powerPC和Linux将此gcc源文件发送到我的系统。 mkdir objdir cd objdir ../gcc-4.6.2/configure –prefix=/usr –enable-languages=c,c++,fortran,go make 我有下一个错误: In file included from ../../gcc-4.9.2/gcc/genmddeps.c:19:0: ../../gcc-4.9.2/gcc/system.h:205:20: fatal error: cstring: No such file or directory # include <cstring> ^ compilation terminated. make[3]: *** [build/genmddeps.o] Error 1 make[3]: Leaving directory `/home/root/build/gcc' make[2]: *** [all-stage1-gcc] Error 2 make[2]: Leaving directory `/home/root/build' make[1]: *** […]

在Ruby中由system()调用时,GCC不会编译

GCC在命令行上使用gcc main.c -o bfcout调用时编译我的C脚本。 我在Ruby中写了一个脚本,第36行表示system("gcc main.c -o bfcout") 。 我也试过bash -c #{Shellwords.escape("gcc -Wall #{filename}.c -o bfcompoutput")} 。 但是我得到一个错误: /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crt1.o: In function '_start': (.text+0x20): undefined reference to 'main' / /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crt1.o: In function '_start': (.text+0x20): undefined reference to 'main' 有一个main()函数,正如我所说的,在命令行编译工作! 这里有什么问题? 编辑:C文件看起来像这样。 它由脚本生成。 是的,这是Brainf ***的参考。 对不起,许多行(和格式不正确)。 #include <stdio.h> unsigned char _c[30000]={}; int ptr=0; int main(){ ++_c[ptr]; ++_c[ptr]; […]

Mingw32 @function的汇编错误

我使用mingw32将一个项目移植到Windows,而该项目依赖于一个名为libfec的库。 Libfec有很多汇编代码来优化内部工作。 在Linux(与GCC 5.4)库编译罚款。 今天我试图在windows上使用mingw32(以及gcc 5.4)编译它,我得到这个错误: as -o mmxbfly27.o mmxbfly27.s mmxbfly27.s: Assembler messages: mmxbfly27.s:10: Warning: .type pseudo-op used outside of .def/.endef ignored. mmxbfly27.s:10: Error: junk at end of line, first unrecognized character is `u' make: *** [mmxbfly27.o] Error 1 关于.type的警告也发生在Linux上,但错误不会。 我检查了binutils,他们实际上是不同的(在Linux上是2.26,在mingw是2.25),但是libfec的代码有点旧了(几年),甚至binutils 2.0也可以编译。 我不知道为什么我不能在Windows上编译这个。 完整的代码在这里: https://github.com/quiet/libfec/blob/master/mmxbfly27.s 我问过一个有编译器经验的朋友,他在代码中找不到问题(并且在linux中编译得很好)。

如何在gcc -o错误顺序后重新获得我的源代码

我错误地运行了“gcc -o program.c程序”而不是“gcc program.c -o program”,现在我失去了我的源程序(program.c)。 有什么解决scheme来重新获得我的来源,或者肯定会丢失?

.lib中的函数被定义,但是当我从相同的.lib生成.so时,该函数不存在

我有一个函数fun1(),它显示了当我做nm时定义的lib1.lib。 我创buildmy.so出my.lib。 但是,当我searchmy.so那fun1()是根本不存在的,因为可能没有调用者编译器可能会忽略它。 所以我创build了一些虚拟数组 char* dummyArray={ &fun1; }; 在fun1()被定义的文件中。 但是这也是行不通的。 请帮助。

在Linux中从C代码生成原始二进制文件

我一直在实现一个简单的x86架构操作系统。 我实现了从磁盘加载内核并以32位模式进入的引导加载程序的汇编代码。 加载的内核代码是用C编写的,所以为了执行这个想法就是从C代码生成原始二进制文件。 首先,我使用了这些命令: $gcc -ffreestanding -c kernel.c -o kernel.o -m32 $ld -o kernel.bin -Ttext 0x1000 kernel.o –oformat binary -m elf_i386 但是,它没有生成任何二进制回馈这些错误: kernel.o: In function 'main': kernel.c:(.text+0xc): undefined reference to '_GLOBAL_OFFSET_TABLE_' 为了清楚起见,kernel.c代码是: /* kernel.c */ void main () { char *video_memory = (char *) 0xb8000 ; *video_memory = 'X'; } 然后我遵循这个教程: http ://wiki.osdev.org/GCC_Cross-Compiler为我自己的目标实现我自己的交叉编译器。 它为我的目的工作,但是反汇编命令ndisasm我获得了这个代码: 00000000 […]

LD_PRELOAD与可能的静态共享库函数

我的目标是挂钩在Linux上使用的开放函数。 由于某种原因,这段代码并不是钩住dlopen-> open,而是挂钩了我打开main.c-> open的版本。 dlopen不是以某种方式使用我的符号? 汇编过程如下: gcc main.c -ldl -ggdb gcc fake-open.c -o libexample.so -fPIC -shared export LD_PRELOAD="$PWD/libexample.so" 当我运行程序时,一切正常。 确保LD_PRELOADvariables已设置..等 这里有个问题,当我尝试直接或间接地调用dlopen挂接open函数时,不知何故,这个open的“版本”没有被我的版本解决/redirect/挂钩。 [main.c] #include <dlfcn.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main() { puts("calling open"); int fd = open("/tmp/test.so", O_RDONLY|O_CLOEXEC); puts("calling dlopen"); int *handle = dlopen("/tmp/test.so", RTLD_LAZY); } [fake-open.c] #define _GNU_SOURCE #include <stdio.h> […]

每个任务使用一个CPU核心

我有一个运行Linux的双核心板,我安装了PJSIP(VoIP软件)。 我想添加回声/噪声消除algorithm,但我不希望它在与PJSIP相同的内核上工作。 我如何拆分两个应用程序之间的内核?

在执行时强制使用特定的库

我编译一个可执行文件选项使用特定的库(而不是系统库)。 编译是好的。 但是当我执行这个二进制文件时,尽pipe指定了LD_LIBRARY_PATH来指向这些特定的库,但我在libc发现了一个关于glib错误版本的错误: ./bin: /lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.17' not found (required by /home/user/ptxdist/platform-i586/sysroot-target/usr/lib/libglib-2.0.so.0) 这是正常的,因为可执行文件使用系统libc而不是特定的libc …在可执行文件上的ldd显示问题: [user ~/Desktop/gesram_x86 ] ldd -v bin ./bin: /lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.17' not found (required by /home/user/ptxdist/platform-i586/sysroot-target/usr/lib/libglib-2.0.so.0) linux-gate.so.1 => (0xb7704000) libgesram.so.0 => /home/user/Desktop/gesram_x86/gesram/lib_gesram/.libs/libgesram.so.0 (0xb76f9000) libsofutils.so.0 => /home/user/ptxdist/platform-i586/sysroot-target/applications/base/lib/libsofutils.so.0 (0xb76f1000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7531000) libglib-2.0.so.0 => /home/user/ptxdist/platform-i586/sysroot-target/usr/lib/libglib-2.0.so.0 (0xb7403000) libgio-2.0.so.0 => /home/user/ptxdist/platform-i586/sysroot-target/usr/lib/libgio-2.0.so.0 (0xb721b000) libgobject-2.0.so.0 => /home/user/ptxdist/platform-i586/sysroot-target/usr/lib/libgobject-2.0.so.0 […]

gcc:-DVAR = -linux在linux上没有像预期的那样工作

我有以下的C程序: test.c的 #include <stdio.h> #define DEF0(v) #v #define DEF(v) DEF0(v) int main() { printf("RUNNING… %s\n", DEF(VAR)); } 汇编 gcc -DVAR=-linux test.c 运行 ./a.out 给 RUNNING… -1 Asm输出 .file "test.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "-1" .LC1: .string "RUNNING… %s\n" .text .p2align 4,,15 .globl main .type main, @function main: .LFB11: .cfi_startproc movl $.LC0, %esi movl $.LC1, %edi […]