我想在Linux中为Windows编译静态库。以下是我跟着编译从Linux为Windows开发交叉编译静态库
- 使用
i586-mingw32msvc-cc -c static_lib.c -o static_lib.o
- 创建静态库在linux
ar rv static_lib.a static_lib.o
和ranlib static_lib.a
- 编译的Linux静态库的源代码的程序我在Eclipse中创建了一个示例程序在Windows和链接这个静态库,它是在linux中为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
的代码如下:
static_lib.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();
}
请给我点建议编译并得到它的工作。
问候 杜琪峰艾伦
即使使用交叉编译器归档程序后,Windows上的mingw链接程序也会引发相同的错误。 – Johnnie 2011-01-07 10:59:20