CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2008
    Location
    Oregon, USA
    Posts
    63

    Linker problems in MinGW

    I just started on Windows programming, and I'm having some problems compiling simple code.

    I'm using MinGW on Windows XP and when I try to compile code with either of the three functions:

    Code:
    TextOut()
    MoveToEx()
    LineTo()
    My linker gives me an error:

    Code:
    C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc4SQ5gM.o:test.cpp:(.text+0x1da): undefined reference to `MoveToEx@16'
    C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc4SQ5gM.o:test.cpp:(.text+0x1f8): undefined reference to `LineTo@12'
    C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc4SQ5gM.o:test.cpp:(.text+0x216): undefined reference to `LineTo@12'
    collect2: ld returned 1 exit status
    I included <windows> just fine, so does that mean I'm missing a library file or do I need to include something else?
    (the function DrawText() works fine)

  2. #2
    Join Date
    Jun 2002
    Location
    Colorado, U.S.A.
    Posts
    980

    Re: Linker problems in MinGW

    Those functions are defined in Gdi32.lib, you have to link to that.

    DrawText is defined in User32.lib, which would explain why that function works for you.

    Whenever you have a linker problem with a specific function, look it up in the MSDN. At the bottom of the page, all of the requirements necessary to use the function are listed, including what library you need to link to.

    Kelly

  3. #3
    Join Date
    Jun 2008
    Location
    Oregon, USA
    Posts
    63

    Re: Linker problems in MinGW

    Thank you. I downloaded Gdi32.lib and placed it in my lib folder. However, I get the same linking error, so the file wasn't found by the linker.
    Next I tried playing with options for the linker, trying to include the file, and had no luck. So how do I make ld.exe see my file?

    Code:
    c++ -Xlinker -L C:/MinGW/lib test.cpp
    
    C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot open output file -Xlinker -L C:/MinGW/lib test.exe: Invalid argument
    collect2: ld returned 1 exit status
    Last edited by Bluefox815; June 3rd, 2008 at 10:54 PM.

  4. #4
    Join Date
    Jun 2002
    Location
    Colorado, U.S.A.
    Posts
    980

    Re: Linker problems in MinGW

    I've never used MinGW, so I don't know how to specify which libraries to link to. I'm not sure what you mean by "downloaded Gdi32.lib." If you're going to be writing windows programs, you should download and install the Windows SDK, which will have all of the libraries you should need.

    Kelly

  5. #5
    Join Date
    Jun 2008
    Location
    Oregon, USA
    Posts
    63

    Re: Linker problems in MinGW

    Yes, I downloaded the SDK. I tried to specify the libraries to include but the linker failed to locate them. I tried using forward and backward slashes, different directory combinations, is there anything else you might be able to suggest? Or does someone know how to properly inlcude libraries in MinGW?

  6. #6
    Join Date
    Jun 2008
    Location
    Oregon, USA
    Posts
    63

    Re: Linker problems in MinGW

    I found out how to fix my problem. MinGW already has required libraries (libgdi32.a) and the compiler automatically includes them when the switch '-mwindows' is used.

  7. #7
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: Linker problems in MinGW

    May be a bit late reply, but specify a library to be linked, especially the one your require

    -lgdi32

    it will automaticaly link libgdi32.a.

    I hope it helps to next readers,

    regards
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  8. #8
    Join Date
    Jun 2008
    Location
    Oregon, USA
    Posts
    63

    Re: Linker problems in MinGW

    I tried that so many times, only I typed -libgdi32 or -libgdi32.a, I can't believe I was so close. Oh well, the other way links everything for you, so I think I like that one better

    Thank you, I probably would have never got that, and likely had other problems with libraries in the future that I can't solve without that.

  9. #9
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: Linker problems in MinGW

    One more thing, you might need in future.

    Some library file for example libabc.a, and it is in the folder that contaions your code and is not in library folder. you will supply just the name of the file in linker tab without any -l option

    just abc.a

    Am glad it helped.

    regards
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured