undefined reference to `GdiplusStartup@12'
Asked Answered
K

5

7

I'm finding a way to use GDI+ library with g++ compiler, I have read some guildlines on the web and still meet with problem...
Here is my code:

#include "gdiplus.h"  
using namespace Gdiplus;

// Skip Lines

GdiplusStartup(&lpGdiplusToken, &gdiplusStartupInput, &gdiplusStartupOutput);
// Skip Lines  

And I have already used the compiler switch as below:

g++ -Wall -mwindows -lgdiplus -I"C:\MinGW\include" -I"C:\MinGW\include\gdiplus" -L"C:\MinGW\lib" -g3 -finput-charset=GBK "$(FilePath)" -o "$(FileDir)\$(FileNameNoExt).exe"

Still I got such errors:

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccjX3mCb.o: In function `WinMain@16':
D:/Projects/cyau/cyau_pre4_20120226/cyau_main.cpp:65: undefined reference to `GdiplusStartup@12'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccjX3mCb.o: In function `Z15ExitApplicationP6HWND__jjl':
D:/Projects/cyau/cyau_pre4_20120226/cyau_main.cpp:128: undefined reference to `GdiplusShutdown@4'

So what's wrong with it? Is there anything more I need?
Thanks for help...

Kizzie answered 3/3, 2012 at 1:27 Comment(3)
Type "mingw gdiplus" in a google query and take the first hit.Godroon
@Hans Passant: Not that thing, friend. I have read through the article. And even download the library to replace the original one, but errors above remained... Do the compiler setting relates with that?Kizzie
I've got the same problem with cygwin's g++. It is rather frustrating.Commorancy
R
8

I had similar messages as you and after some research I've come to the following: place -lgdiplus after *.cpp files on the command line. Example:

g++ -mwindows program.cpp -lgdiplus

That command compiled my GDI+ program.

Redmund answered 20/4, 2013 at 12:54 Comment(4)
The -l option tells linker to link the file named libgdiplus.o, it works because you HAVE this library file in your physical file system. Maybe you're right but this question leads to a common question which is "How can I use .lib(MSVC static library) while compiling with g++ or gcc" Achieving this goal can be troublesome, due to many requirements must be satisfied... Anyway, thank you for the suggestion.^ω^Kizzie
@cuter44: Little correction: the -l option tells the linker to link file named libgdiplus.a. It is in lib subdirectory of MinGW directory. So why is the *.lib file needed?Redmund
the -l option tells the linker to link file named libgdiplus.a Sorry my mistake m(_ _)m. Because I con only find the .lib on the Web at that moment ^ω^bKizzie
The order of the -lgdiplus flag relative to the source file is important. If -lgdiplus is given first, it doesn't work. I don't know why.Almuce
V
2

This worked for me. If you are using CodeBlocks add

-mwindows -lgdiplus

on the other linker options

Step 1

Step 2

Vieva answered 27/11, 2022 at 9:8 Comment(0)
T
1

I'm using DevCPP, and had the same issue.

Creating a libgdiplus.a from a gdiplus.def using this command solved my problem:

dlltool -k -d gdiplus.def -l libgdiplus.a

Initially i was using the command above without the -k params.

Taillight answered 19/3, 2017 at 17:24 Comment(0)
F
0

I don't have experience with g++, but I believe the problem is with linking.

Either the gdiplus library isn't getting linked, or it isn't compatabile with g++. Hopefully that will help you continue tracking down the problem.

Friedly answered 3/3, 2012 at 2:5 Comment(1)
Emmm... Yes, I noticed that it's due to the linker. But all dependent files mentioned are there except the GdiPlus.lib. But they said g++ does not recongize .lib file. Mess...Kizzie
T
0

I am using VS 2015. One program compiles OK. Another program using the same code gave me the `GdiplusStartup@12'error (and many others). Fixed the problem by adding GdiPlus.lib to the linker input. Do not understand why the two programs behave differently, but it works.

Tokay answered 25/11, 2021 at 15:36 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewPamalapamela

© 2022 - 2025 — McMap. All rights reserved.