【发布时间】:2011-01-07 18:45:37
【问题描述】:
我想在 linux 中为 windows 编译静态库。以下是我编译的过程
- 在linux中使用
i586-mingw32msvc-cc -c static_lib.c -o static_lib.o编译静态库的源代码 - 在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
代码如下:
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();
}
请给我一些编译和让它工作的建议。
问候 约翰尼·艾伦
【问题讨论】: