简体   繁体   English

以C99模式链接非C99静态库

[英]Linking non C99 static library in C99 mode

I have a static library which I compiled with gcc without c99 mode. 我有一个静态库,我用gcc编译时没有c99模式。 I am trying to link it in compilation using gcc -std=c99. 我正在尝试使用gcc -std = c99在编译中链接它。 This is giving me an error: 这给我一个错误:

undefined reference to 'functionName'

Here, functionName is function inside the static library. 在这里,functionName是静态库中的函数。

This is my compilation: 这是我的汇编:

gcc -std=c99 -g -I../ -Llib/ -lmylib test.c ../file1.c ../file2.c -o test  

I am using C99 here because my code in test.c #includes header files whose implementation uses C99 standard. 我在这里使用C99是因为test.c中的代码#includes头文件的实现使用C99标准。

The static library(lib/libmylib.a) in not compiled with c99 standard because it's code uses some libraries which are failing to compile in C99 mode(but compiles without c99 flag). 静态库(lib / libmylib.a)未使用c99标准进行编译,因为它的代码使用了一些无法在C99模式下编译的库(但没有c99标志的编译)。

I also tried changing the order of the -L & -l flags to the end & immediately after gcc -std=c99 but it gave the same 'undefined reference' error. 我还尝试在gcc -std = c99之后立即将-L&-l标志的顺序更改为末尾,但它给出了相同的“未定义引用”错误。

How do I link these together? 如何将它们链接在一起?

Thank you. 谢谢。

EDIT : The function which I've mentioned as functionName is a pseudonym for setupStacktrace() shown here: http://pastebin.com/2RbEEPaj . 编辑 :我提到的functionName名称为functionName是此处显示的setupStacktrace()的假名: http ://pastebin.com/2RbEEPaj。 It is signature is void setupStacktrace(); 它的签名是void setupStacktrace();

The order of the command line arguments matter. 命令行参数的顺序很重要。 The way you have it now, the linker goes through your static libraries, realizes that nothing so far need anything it provides, and throw away everything in it. 链接器将遍历您的静态库,从而意识到您到目前为止所拥有的方式并不需要它提供的任何内容,并丢弃其中的所有内容。 Do this: 做这个:

gcc -std=c99 -g -I../ -Llib/  test.c ../file1.c ../file2.c -lmylib -o test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM