【问题标题】:Cross compile Static Library from Linux for windows从 Linux for windows 交叉编译静态库
【发布时间】:2011-01-07 18:45:37
【问题描述】:

我想在 linux 中为 windows 编译静态库。以下是我编译的过程

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

请给我一些编译和让它工作的建议。

问候 约翰尼·艾伦

【问题讨论】:

    标签: c linux


    【解决方案1】:

    尝试使用交叉编译器存档器而不是原生存档器,即使用i586-mingw32msvc-ari586-mingw32msvc-ranlib 而不是arranlib

    或者这只是问题的一个错字?

    【讨论】:

    • 即使在使用交叉编译器归档器之后,windows 上的 mingw 链接器也会抛出相同的错误。
    【解决方案2】:

    尝试i586-mingw32msvc-ar 而不是普通的ar。通常,Linux 中的ar 不支持用于 Windows 编程的 PE 格式。 (或者你必须指示它使用 PE 格式。)

    【讨论】:

      猜你喜欢
      • 2021-01-21
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 2023-01-27
      相关资源
      最近更新 更多