从Linux for Windows交叉编译静态库

Joh*_*nie 5 c linux

我想在linux中为windows编译静态库.以下是我编写的程序

  1. 使用linux编译静态库的源代码 i586-mingw32msvc-cc -c static_lib.c -o static_lib.o
  2. 在linux ar rv static_lib.a static_lib.o和.中创建了静态库ranlib static_lib.a
  3. 我在windows上的eclipse中创建了一个示例程序,并链接了这个静态库,它在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
Run Code Online (Sandbox Code Playgroud)

守则如下:

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");
}
Run Code Online (Sandbox Code Playgroud)

sample_static.c

#include <stdio.h>

extern void func(void);

int main ()
{
    printf ("Main function\n");
    func();
}
Run Code Online (Sandbox Code Playgroud)

请给我建议编译并使其工作.

关于约翰尼艾伦

Chr*_*fer 2

尝试使用交叉编译器归档器而不是本机归档器,即使用i586-mingw32msvc-arandi586-mingw32msvc-ranlib而不是arand ranlib

或者这只是问题上的错字?