Tag: gcc

构建交叉编译器 – 错误:找不到libmpfr

我正在尝试构建一个交叉编译器。 我按照本教程: http : //wiki.osdev.org/GCC_Cross-Compiler 我在/ opt / cross中安装了binutils。 现在我尝试用mpfr-2.4.2安装gcc-4.7.4。 我使用命令来准备和配置: export PREFIX=”$HOME/opt/cross” export TARGET=i686-elf export PATH=”$PREFIX/bin:$PATH” mv gmp-4.3.2 gcc-4.7.4/gmp mv mpfr-2.4.2 gcc-4.7.4/mpfr mv mpc-0.8.1 gcc-4.7.4/mpc # i am in usr/src directory mkdir build-gcc cd build-gcc ../gcc-4.7.4/configure –target=$TARGET –prefix=”$PREFIX” –disable-nls –enable-languages=c,c++ –without-headers 现在,我使用make all-gcc来构建,但是我收到以下错误: configure: error: libmpfr not found or uses a different ABI (including […]

头文件不能工作-undefined引用`method’

头文件似乎无法正常工作。 我是C的新手,并不知道我在做什么 error – findvals.c:(.text+0x561): undefined reference to `approxEqual’ findvals.c #include #include #include #include #include “utils.h” int main(int argc, char **argv) { //printf(“GRR ENTAR SOMETHANG”); //char word[64]; //scanf(“%s”, word); int count = 0; int ret; double x; double y; int i = 0; int c = 0; char *refStr, *tolStr; double refDub; double tolDub; int […]

架构x86_64的未定义符号在C中的含义是什么?

这是我的代码。 #include int main(){ int first; int second; int third; float average=0.0; printf (“This program will find the average of 3 numbers.\n”); delay(1000); printf (“Type the first number.\n”); scanf (“%d”, &first); printf (“Type the second number.\n”); scanf (“%d”, &second); printf (“Type the third number.\n”); scanf (“%d”, &third); average = (first+second+third)/2.0; printf (“The average of %d, […]

-L和-l命令在Makefile中不起作用

我有以下Makefile: TOP = ../Bank/src CC = gcc CFLAGS = -g -Wall -std=c99 LDFLAGS = -L$(TOP) LFLAGS = -lVirtualBank INCLUDES = -I$(TOP)/VirtualBank/ LIBS = VirtualBank.a BANK_SOURCES = $(TOP)/bank.c VirtualBank_SOURCES = $(TOP)/VirtualBank/bankServer.c $(TOP)/VirtualBank/dataBase.c $(TOP)/VirtualBank/account.c BANK_OBJECTS = $(BANK_SOURCES:.c=.o) VirtualBank_OBJECTS = $(VirtualBank_SOURCES:.c=.o) TARGET = bank all: VirtualBank.a $(TARGET) VirtualBank.a:$(VirtualBank_OBJECTS) rm -f $@ ar cq $@ $(VirtualBank_OBJECTS) mv *.a $(TOP)/ […]

在gcc中使用primefaces操作3.4.3

内置的primefaces操作是在gcc-4.1.2中引入的。 但是,我在OpenIndiana上使用gcc,它只有gcc 3.4.3。 现在我的问题是如何在gcc 3.4.3中使用primefaces操作? 此外,我试图在OpenIndiana中使用gcc 4.6.1,但它不起作用,因为它抱怨一些运行时库。 如果有人成功使用它,请告诉我。

如何让GCC __attribute __((构造函数))在OSX下工作?

extern void MyInitFunc(void) __attribute__ ((constructor)); extern void MyTermFunc(void) __attribute__ ((destructor)); void MyInitFunc(void) { printf(“%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n”); } void MyTermFunc(void) { } 我把它放在主应用程序(不是库或框架)中的.c文件中。 根据GCC文档,它不会被调用。 我错过了重要的事吗? 这是在Snow Leopard的XCode 3.2上。

将非指针变量转换为指向数组的指针

好吧,我知道我的标题可能有点令人困惑,但我会解释。 我正在C中完成一项家庭作业。我给了一个.c文件,需要为某些函数提供实现。 简而言之,我将此作为.c文件 typedef int set_t; … void init(set_t *a, int N); // Initialized an array to a of size N … int main() { set_t a; init(&a, 10); } 在我提出的几个实现中,我能够使用a创建一个数组,但是在程序运行时我不断出现分段错误: – /。 除了init(set_t *a, int N)的实现之外,是否可以在不更改原始.c文件中的任何内容的情况下将 a初始化为数组? 编辑 这是我当前的init实现 – >它会导致分段错误 void init(set_t *a, int N) { //set_t thing[10]; *a = malloc(sizeof(set_t)*N); for (int […]

我的交叉编译器出了什么问题?

我正在尝试编译一个基本程序,我可以在我的mac上交叉编译。 我正在运行Mac OS X Mavericks。 我的交叉编译器是arm-elf-gcc-4.7.3。 我写了一个简单的测试程序,看起来像: int main() { ; return 0; } 当我运行/opt/local/bin/arm-elf-gcc-4.7.3 -o test test.c时,我收到这些错误。 test.c:4:Unknown pseudo-op: .global test.c:4:Rest of line ignored. 1st junk character valued 109 (m). test.c:5:Unknown pseudo-op: .type test.c:5:Rest of line ignored. 1st junk character valued 109 (m). test.c:7:Junk character 64 (@). test.c:7:Rest of line ignored. 1st junk character […]

gcc为全局变量生成不必要的调试符号?

在我们的项目中,我们从gcc 5.3移到gcc 7.3,并发现调试符号增加了很多; 经过一番挖掘,我发现gcc 7.3生成不必要的(我想,请纠正我,如果我错了)调试全局变量的符号,因为我们声明了很多全局变量并且很多c文件都包含它们,调试符号大小为最终的ELF筹集到巨大的价值。 是否有一个gcc开关来解决这个问题而不改变全局变量的使用? 编辑1 “-O3” or “-Os”, “-feliminate-unused-debug-types” does not help. 下面是一个显示问题的示例(在ubuntu 18.04上,使用gcc 5.5和gcc 7.3):示例代码: ### test.c #include “global.h” int main() { return 0; } ###global.c #include “global.h” int __my_unused = 1; ###global.h extern int __my_unused; GCC 5.5,test.c中没有不必要的调试符号“__my_unused” root@b-test:/tmp# gcc-5 -g -O2 test.c global.c root@b-test:/tmp# readelf -wi a.out Contents of the .debug_info […]

gcc中的运行时参数(反向va_args / varargs)

我正在尝试对我正在研究的微控制器的解释器进行一些改进。 为了执行内置函数,我目前有这样的东西(虽然有点快): function executeBuiltin(functionName, functionArgs) { if (functionName==”foo”) foo(getIntFromArg(functionArgs[0])); if (functionName==”bar”) bar(getIntFromArg(functionArgs[0]),getBoolFromArg(functionArgs[1]),getFloatFromArg(functionArgs[2])); if (functionName==”baz”) baz(); … } 但它适用于资源非常有限的嵌入式设备(ARM),我需要大幅减少代码大小。 我想做的是有一个通用函数来调用具有不同参数的其他函数 – 如下所示: function executeBuiltin(functionName, functionArgs) { functionData = fast_lookup(functionName); call_with_args(functionData.functionPointer, functionData.functionArgumentTypes, functionArgs); } 所以我希望能够调用标准的C函数并将其传递给它所需的任何参数(可能都是不同的类型)。 为此,我需要一个call_with_args函数。 我想避免重写每个函数来采取argc + argv。 理想情况下,每个被调用的函数都是完全标准的C函数。 这里有一个关于这个问题的讨论 – 但自1993年撰写该帖以来,有什么变化吗? 特别是当我在ARM上运行时,参数位于寄存器而不是堆栈中。 即使它不在标准C中,是否有任何GCC具体可以完成? 更新:看起来尽管根据规范行为是“未定义的”,看起来因为C调用的方式工作,你可以传递更多的参数到一个函数而不是它期望的一切都很好,所以你可以解压缩所有将参数放入uint32s数组中,然后可以将每个uint32传递给该函数。 这使得为​​调用编写“漂亮”代码变得更加容易,并且它似乎运行得很好(在32位平台上)。 唯一的问题似乎是传递64位数字并编译为64位x86,因为在这种情况下它似乎做了一些特别奇怪的事情。