Cross-build a static library from Linux for windows

I want to compile a static library in linux for Windows. Below is the procedure I followed to compile

  • Compile the source code of the static library on Linux with i586-mingw32msvc-cc -c static_lib.c -o static_lib.o
  • Created a static library in linux ar rv static_lib.a static_lib.oandranlib static_lib.a
  • I created a sample program in eclipse on windows and linked this static library which crossbreeds in linux for Windows. The compiler used on Windows was mingw.

when compiling a program in windows eclipse, the compiler gives me the following error.

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

The codes are as follows:

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();
}

kindly give me tips for compiling and getting this work.

Relations Johnny Alan

+5
source share
2

- , .. i586-mingw32msvc-ar i586-mingw32msvc-ranlib ar ranlib.

?

+1

i586-mingw32msvc-ar ar. ar Linux PE, Windows. ( , PE.)

+1

All Articles