针对Windows从Linux交叉编译静态库 [英] Cross compile Static Library from Linux for windows

查看:340
本文介绍了针对Windows从Linux交叉编译静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Linux中为Windows编译静态库.以下是我遵循的编译过程

  1. 使用i586-mingw32msvc-cc -c static_lib.c -o static_lib.o
  2. 编译linux中静态库的源代码
  3. 在linux ar rv static_lib.a static_lib.oranlib static_lib.a
  4. 中创建了静态库
  5. 我在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

代码如下:

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

请给我一些建议,以使其编译并开始工作.

问候 约翰尼·艾伦

解决方案

尝试使用交叉编译器归档器而不是本机归档器,即使用i586-mingw32msvc-ari586-mingw32msvc-ranlib代替arranlib. /p>

还是这只是一个错字?

I want to compile static library in linux for windows. Following is the procedure I followed for compiling

  1. Compile the source code of static library in linux using i586-mingw32msvc-cc -c static_lib.c -o static_lib.o
  2. Created the static library in linux ar rv static_lib.a static_lib.o and ranlib static_lib.a
  3. I created a sample program in eclipse on windows and linked this static library which is cross compiled in linux for windows. The compiler used at windows was mingw.

while compiling the 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 suggestions to compile and get it work.

Regards Johnnie Alan

解决方案

Try using the cross-compiler archiver instead of the native one, i.e. use i586-mingw32msvc-ar and i586-mingw32msvc-ranlib instead of ar and ranlib.

Or is that just a typo on the question?

这篇关于针对Windows从Linux交叉编译静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆