Cross compile Static Library from Linux for windows
NickName:Johnnie Ask DateTime:2011-01-07T17:26:39

Cross compile Static Library from Linux for windows

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

Copyright Notice:Content Author:「Johnnie」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/4624078/cross-compile-static-library-from-linux-for-windows

Answers
Christoffer 2011-01-07T10:44:37

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.\n\nOr is that just a typo on the question?",


More about “Cross compile Static Library from Linux for windows” related questions

Cross compile Static Library from Linux for windows

I want to compile static library in linux for windows. Following is the procedure I followed for compiling Compile the source code of static library in linux using i586-mingw32msvc-cc -c static_l...

Show Detail

How to compile static .lib library for Windows in Linux or Macos

I am searching way to compile static library for Windows in Linux or Macos, there seems to be cross compiler to generate .a library for Windows like this one, but that is not what I want, what I wa...

Show Detail

Cross-compile Fortran library from Linux to Windows using CMake including Lapack

I have a Fortran library that I have been developing on Linux that I want to share with colleagues who normally use Windows. I do not expect them to help develop it, so all I want to do is produce a

Show Detail

Cross compile with linux libraries on windows

I have some functional libraries (Qt) builded on linux Mint and I already built some test applications (cross compile) for ARM that works. Since it was impossible to cross compile the same libs on

Show Detail

How to Cross Compile Alsa library for Windows Eclipse

I would like to know how could it be possible to cross compile the Alsa library in Windows for my linux host. I am using an iMX8X with a Linux image, made by Yocto, and I need to implement the Alsa

Show Detail

Is it possible to cross compile for Windows, from linux, when static libraries are not available?

I am trying to compile a project using Qt, OpenCV and FlyCapture2 libraries into an executable for a Windows 8 target system. I am running ubuntu 14.04. Unfortunately the FlyCapture2 SDK only provi...

Show Detail

gcc cross compile helloworld for ARM on Windows

I am using a Xilinx Zedboard. I cross compiled a c project that required the math.h library. When I run it on the Zedboard, I get a ./my_binary: not found error. I am able to cross compile with the -

Show Detail

Qt Linux/Windows cross compilation. Compile qmake for Windows binaries on Linux for Qt Creator

I think I have a big misunderstanding about how to use Qt Creator and qmake to compile Windows binaries on a Linux host. I set up a Debian 11 VM on my server to compile some tools originally writte...

Show Detail

Queries on Cross compiling, from Windows to Linux and from Linux to Windows,

I am working on a C, project which uses ffmpeg library. Currently I'm working on windows platform, and I'll be cross compiling the project for Linux ARM. With that background, I have few basic ques...

Show Detail

Should I cross-compile in Linux or Windows?

To create a .exe in Linux using Qt SDK, should I cross compile my application in Linux or cross-compile my application in Windows?

Show Detail