Tag: 链接器

C中的函数模拟(用于测试)?

我想在C中编写C库的测试。我想模拟测试的一些函数。 假设我的库是从以下源编译的: /* foo.h */ int myfunction(int x, int y); /* foo.c */ #include “foo.h” static int square(int x) { return x * x; } int myfunction(int x, int y) { return square(x) + square(y); } 我想写一个这样的测试: /* foo_test.c */ #include “foo.h” static int square(int x) { return x + 1; } int main(void) { […]

clang链接器问题

我刚尝试了最新的llvm和clang trunk版本。 他们编译时没有开箱即用的单一警告,但我在连接一个hello world示例时遇到了问题。 我的代码是 #include int main(){ printf(“hello\n”); } 如果我编译使用 clang test.c 我收到以下错误 /usr/bin/ld: crt1.o: No such file: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) 使用-v显示gnu ld被调用为 “/usr/bin/ld” –eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out crt1.o crti.o crtbegin.o -L -L/../../.. /tmp/cc-0XJTsG.o -lgcc […]

C main()函数可以是静态的吗?

main()函数可以在C程序中声明为static吗? 如果是的话那么它的用途是什么? 是否可以使用汇编代码并自己调用static main()函数(考虑嵌入式程序)?

自动为C / C ++可执行文件生成目标文件(链接器)依赖项

我目前正在开发一个灵活的C / C ++构建框架,我很快就会(希望)开源。 (有关背景,请参阅此问题)。 我使用以下命令为源/头文件生成#include文件依赖项。 gcc -M -MM -MF 有没有一种巧妙地推断可执行文件的链接器(.o文件)依赖关系(unit testing+在我的情况下为目标平台的主要可执行文件)使用gcc / GNU实用程序以类似的方式? 目前,该框架做了很多假设,并且在确定这些依赖关系时非常愚蠢。 我听说过一种方法,其中nm命令可用于在目标文件中提供未定义符号的列表。 例如,在目标文件上运行nm(使用gcc -c编译)会出现类似这样的内容 – nm -o module.o module.o: U _undefinedSymbol1 module.o: U _undefinedSymbol2 module.o:0000386f T _definedSymbol 然后,人们将查找其他目标文件,其中定义了这些未定义的符号,以提供成功链接文件所需的目标文件依赖性列表。 这是确定可执行文件的链接器依赖性的最佳实践吗? 有没有其他方法可以推断出这些依赖关系? 在提出解决方案时,假设所有目标文件已经存在(即已经使用gcc -c编译)。

编译简单的hello world ZeroMQ C例子,编译标志?

尝试从zeromq教程编译示例hello_world.c:http://zguide.zeromq.org/page:all #Ask-and-Ye-Shall-Receive很确定我已经在OSX Mountain Lion中安装了所有内容。 clang -Wall hwserver.c -o hwserver 给我一个错误: Undefined symbols for architecture x86_64: “_zmq_bind”, referenced from: _main in hwserver-OgrEe6.o “_zmq_ctx_new”, referenced from: _main in hwserver-OgrEe6.o “_zmq_msg_close”, referenced from: _main in hwserver-OgrEe6.o “_zmq_msg_data”, referenced from: _main in hwserver-OgrEe6.o “_zmq_msg_init”, referenced from: _main in hwserver-OgrEe6.o “_zmq_msg_init_size”, referenced from: _main in hwserver-OgrEe6.o “_zmq_msg_recv”, referenced from: _main […]

带有objcopy的巨大二进制文件

我在ARM9处理器的基本C程序中定义全局变量时遇到问题。 我正在使用EABI GNU编译器,12KB精灵生成的二进制文件是4GB! 我假设问题出在我的分散文件中,但我无法理解它。 我有256KB的ROM(基地址0xFFFF0000)和32KB的RAM(基地0x01000000) SECTIONS { . = 0xFFFF0000; .text : { * (vectors); * (.text); } .rodata : { *(.rodata) } . = 0x01000000; sbss = .; .data : { *(.data) } .bss : { *(.bss) } ebss = .; bssSize = ebss – sbss; } 我的计划如下: int a=10; int main() { int […]

如何在编译/链接时使用地址进行计算?

我写了一些用于初始化IDT的代码,它将32位地址存储在两个不相邻的16位半中。 IDT可以存储在任何地方,并通过运行LIDT指令告诉CPU在哪里。 这是初始化表的代码: void idt_init(void) { /* Unfortunately, we can’t write this as loops. The first option, * initializing the IDT with the addresses, here looping over it, and * reinitializing the descriptors didn’t work because assigning a * a uintptr_t (from (uintptr_t) handler_func) to a descr (aka * uint64_t), according to the compiler, “isn’t […]

如何将VSTS .lib转换为MinGW .a?

我有一个用Visual Studio编译的静态库,我想从MinGW链接到它。 我尝试更改后缀但是我得到了一堆警告: Warning: .drectve /DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”uuid.lib” /DEFAULTLIB:”MSVCRT” /DEFAULTLIB:”OLDNAMES” ‘ unrecognized 。 还有一些错误,包括: ./libetpan.a(Release_ssl/mailimap.obj):(.text[_mailimap_noop]+0x7): undefined reference to 。 ./libetpan.a(Release_ssl/mailimap.obj):(.text[_mailimap_noop]+0x7): undefined reference to ___ security_cookie’`。 任何帮助是极大的赞赏。

未定义的引用`mysql_init’

我正在尝试在我的新服务器上编译我的程序,但目前它并不适合我。 错误日志是: rasmus@web01:~/c++$ make test g++ `mysql_config –cflags –libs` main.cpp logger.cpp cpulogger.cpp -o test /tmp/ccPaMZUy.o: In function `CPULogger’: /home/rasmus/c++/cpulogger.cpp:7: undefined reference to `mysql_init’ /home/rasmus/c++/cpulogger.cpp:8: undefined reference to `mysql_real_connect’ /home/rasmus/c++/cpulogger.cpp:10: undefined reference to `mysql_get_client_info’ /tmp/ccPaMZUy.o: In function `~CPULogger’: /home/rasmus/c++/cpulogger.cpp:16: undefined reference to `mysql_close’ collect2: ld returned 1 exit status make: *** [all] Error 1 正如您所看到的,我正在编译MySQL – […]

为什么linux上的curses会让我出现以下错误?

试图让getch()努力捕获按键。 #include … … WINDOW *w; char f; w = initscr(); timeout(3000); f = getch(); endwin(); 给我以下错误: – undefined reference to `wgetch’ undefined reference to `stdscr’