我想在 linux for windows 中编译静态库。以下是我编译的过程
- 使用
i586-mingw32msvc-cc -c static_lib.c -o static_lib.o
编译linux下静态库源码 - 在 linux 中创建静态库
ar rv static_lib.a static_lib.o
和ranlib static_lib.a
- 我在 windows 上的 eclipse 中创建了一个示例程序,并链接了这个在 linux for windows 中交叉编译的静态库。 windows使用的编译器是mingw。
在windows eclipse中编译程序时,编译器报如下错误。
static_test\static_lib.a: file format not recognized; treating as linker script
\static_test\static_lib.a:1: syntax error
collect2: ld returned 1 exit status
Build error occurred, build is stopped
代码如下:
静态库.c
#include <stdio.h>
void func(void)
{
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
printf("Hello\n");
}
sample_static.c
#include <stdio.h>
extern void func(void);
int main ()
{
printf ("Main function\n");
func();
}
请给我一些编译和让它工作的建议。
问候 约翰尼·艾伦
最佳答案
尝试使用交叉编译器归档器而不是 native 归档器,即使用 i586-mingw32msvc-ar
和 i586-mingw32msvc-ranlib
而不是 ar
和 ranlib
。
或者这只是问题的错字?
关于从 Linux for windows 交叉编译静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4624078/