Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6365339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:16:49+00:00 2026-05-25T00:16:49+00:00

I am attempting to cross-compile some C/C++ programs I’ve written on Linux for Windows.

  • 0

I am attempting to cross-compile some C/C++ programs I’ve written on Linux for Windows. I’ve had a lot of experience using both GCC and MSVC.

Normally when compiling a program using gcc, one would use the -l linker argument to specify a library to link against. It seems that this does not work properly when using the MingW-gcc linker.

GCC version:
i586-mingw32msvc-gcc (GCC) 4.4.4

When linking a program that uses (for example, GTK+ or libpng, libz, etc.), using something like:

i586-mingw32msvc-gcc -mwindows -L/opt/xcompile-win32/lib -lmylib -lmylib2 myprog.o -o myprog.exe

Gives numerous errors about undefined references to the library functions. However, if I specify the libraries as additional objects like this:

i586-mingw32msvc-gcc -mwindows -L/opt/xcompile-win32/lib /opt/xcompile-win32/lib/libmylib.a /opt/xcompile-win32/lib/libmylib2.a myprog.o -o myprog.exe

Everything works fine and the resulting program works great! My question is: Is there a way I can get the normal -l library arguments to work correctly? This method seems a bit cumbersome! I can’t seem to find anything online which addresses this issue. Thanks!

Edit:

To clarify: the order of the library arguments on the command-line makes no difference. Also, the program compiles just fine on Linux (gcc) using only the -l arguments. Actual command below:

i586-mingw32msvc-gcc  -mwindows -o win32/vmclient.exe win32/gtk_test.o \
-L/opt/xcompile-win32/lib -latk-1.0 -lpangoft2-1.0 -lpangocairo-1.0 \
-lgdk_pixbuf-2.0 -lm -lcairo -lpng12 -lpango-1.0 -lfreetype -lfontconfig \
-lgmodule-2.0 -lgthread-2.0 -lglib-2.0

win32/gtk_test.o:gtk_test.c:(.text+0x37): undefined reference to `_gtk_init_abi_check'

(and a bunch of similar errors). The program compiles fine for Win32 (using i586-mingw32msvc-gcc) when directly referencing the .a library files in the exact same order.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:16:50+00:00Added an answer on May 25, 2026 at 12:16 am

    The problem here is in the order of the command line arguments. If library linked with the -l the linker will only take the object modules needed to satisfy any unresolved referece seen so far. From info ld, option -l:

    If the archive defines a
    symbol which was undefined in some object which appeared before
    the archive on the command line, the linker will include the
    appropriate file(s) from the archive. However, an undefined
    symbol in an object appearing later on the command line will not
    cause the linker to search the archive again.

    But when you write the full path of the library it is linked wholly.

    So to compile your program simply write:

    i586-mingw32msvc-gcc -mwindows myprog.o -o myprog.exe \
        -L/opt/xcompile-win32/lib -lmylib -lmylib2 
    

    With the libraries at the end.

    BTW, if I’m not mistaken this behavior is no different in the native linux compiler.

    Edit:

    Replying to your edit, you forgot to add a few libraries to your compiler command. You are missing -lgtk-win32-2.0 -lgdk-win32-2.0.

    Personally I find it much more convenient to use the pkg-config tool. When cross-compiling it is just as easy as exporting PKG_CONFIG_LIBDIR=/op/xcompile-win32/pkgconfig.

    In linux it works fine maybe because the missing libraries are brought in automatically by NEEDED records in the other libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While attempting to cross-compile ICU using android-ndk-r7 in Linux, the following error occurs after
I am attempting to cross-compile on AIX with the xlc/xlC compilers. The code compiles
I am attempting to make some cross-DB(SQL Server and PostgreSQL) compatible SQL. What I
I'm attempting to make a cross domain script call to get some JSON data
I am attempting to write a cross-platform GUI application that would be deployed to
When attempting to compile my C# project, I get the following error: 'C:\Documents and
This is already cross-posted at MS Connect: https://connect.microsoft.com/VisualStudio/feedback/details/560451 I am attempting to override the
I am attempting to write a user script that makes a cross domain AJAX
I'm attempting to render a textured quad using the example located here . I
I am attempting to write a file using java.io, where I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.