从 Linux for windows 交叉编译静态库

标签 c linux

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

  1. 使用i58​​6-mingw32msvc-cc -c static_lib.c -o static_lib.o编译linux下静态库源码
  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

代码如下:

静态库.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();
}

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

问候 约翰尼·艾伦

最佳答案

尝试使用交叉编译器归档器而不是 native 归档器,即使用 i58​​6-mingw32msvc-ari58​​6-mingw32msvc-ranlib 而不是 arranlib

或者这只是问题的错字?

关于从 Linux for windows 交叉编译静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4624078/

相关文章:

当我将一个 c 文件的输出重定向到另一个文件时出现 C 编程错误

c - 编码,解码一个整数到一个字符数组

c - 取消引用指针

linux - 如何计算逗号分隔行中的字符数,其中分隔符内的逗号不被视为单独的?

linux - 为什么 gethostbyaddr 不适用于 www.google.com

c - 为什么它会取代初始值?

python - 我如何在 X 中获得第一个未使用的显示?

regex - awk 检查列中的空格

c - 使用 popen(3) 与系统交互的 C 程序与 bash shell 相比如何?

c - rewind() 之后,您可以使 fprintf() 写入文件末尾吗(例如完全覆盖)