undefined reference to `GdiplusStartup#12' - c++

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...

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.

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.

This worked for me. If you are using CodeBlocks
add
-mwindows -lgdiplus
on the other linker options
Step 1
Step 2

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.

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.

Related

c++ SDL2 - ld||cannot find -lmingw32|

I was creating program on windows with SDL2 and the program worked fine, but when I changed my os to linux mint (and install code::blocks, gcc, g++, SDL2), I run into troubles with compiling my code.
I have one error:
- ld||cannot find -lmingw32|
I guess that I don't have mingw32 library, where can I get it? Or is the problem diferent?
BTW: I also tryed to google it.
Thank for response.
Read the manual.
On linux you don't need -lmingw32. Instead, use
`sdl2-config --libs`
to get the list of all needed linker flags.
Example usage:
gcc -o myprogram myprogram.o `sdl2-config --libs`
Problem was solved by removing linker on mingw32 and lib rotozoom.h.

Embedding SpiderMonkey JS

I'm working on a C++ application. I would like to embed SpiderMonkey in the application.
I'm working with CMake, but I couldn't get that build. So, in an attempt to reduce complications, I tried the example code on this page. This wouldn't link using cmake or gcc from the command line.
So, even simpler, just to ensure I can link properly I am trying to get the following to work.
From the command line with gcc:
g++ --std=c++11
-I/home/thetasinner/moz/js/src/build_DBG.OBJ/dist/include
-L/home/thetasinner/moz/js/src/build_DBG.OBJ/js/src -DDEBUG
-Wl,--verbose -lmozjs-54a1 -lm -lz -ldl test.cpp -o test
On the following minimal code example:
#include <iostream>
#include <stdexcept>
#include "jsapi.h"
#include "js/Initialization.h"
int main(int argc, char** args) {
if (!JS_Init()) {
throw std::runtime_error("failed to initialise.");
}
std::cout << "It's alive!\n";
JS_ShutDown();
return 0;
}
Even this doesn't link. I get the errors
/tmp/ccqjx5RY.o: In function `main':
custom.cpp:(.text+0xf2): undefined reference to `JS_ShutDown()'
/tmp/ccqjx5RY.o: In function `JS_Init()':
custom.cpp:(.text._Z7JS_Initv[_Z7JS_Initv]+0xa): undefined reference to
'JS::detail::InitWithFailureDiagnostic(bool)'
collect2: error: ld returned 1 exit status
The headers are found and the linker is finding the mozjs library
attempt to open /home/thetasinner/moz/js/src/custom_build_DBG.OBJ/js/src
/libmozjs-54a1.so succeeded
-lmozjs-54a1 (/home/thetasinner/moz/js/src/custom_build_DBG.OBJ/js/src
/libmozjs-54a1.so)
I am working on Linux (Ubuntu 16.04 and Debian 8.7 tried) because that's where the build tools are. I don't even want to touch Window's yet.
The 'js' executable built in the spidermonkey build works fine, which I assume has the lib I'm trying to link inside it. So I would have thought the lib itself is built okay.
Can anybody help me resolve these linker errors? There are lots of answers to questions about much older versions of SpiderMonkey, but there's nothing for more recent versions. I'm interested in version 45 (which I've tried with very similar errors) or the tip version 52.
I'm comfortable enough digging around in the code working out how to do what I want with it once it builds, hence the interest in the latest version which isn't properly documented, I'm just completely stumped with the building step.
I suspect it's just an ordering problem on the command line:
g++ --std=c++11
-I/home/thetasinner/moz/js/src/build_DBG.OBJ/dist/include
-L/home/thetasinner/moz/js/src/build_DBG.OBJ/js/src -DDEBUG
test.cpp -o test
-Wl,--verbose -lmozjs-54a1 -lm -lz -ldl
Compilation first, followed by linking, with libraries in order of dependency. (My first guess was you'd neglected to mention mozjs on the command line. It took a second look to see it was just in the wrong place.)

mingw and SDL command line

Now I see that this is not a unique problem and has been raised plenty of times before, but I have followed the advice given in other stack overflow questions and nothing seems to help.
My problem is pretty straight forward, I can not compile my project (a basic c++ gui) and include SDL, because I get: Undefined reference to WinMain#16
I started using code::blocks but it didn't work so moved to trying to compile the simplest implementation on the command line in windows 7, 64 bit, in an attempt to understand whats going on in the background.
The command I am running:
g++ test.cpp -L C:\Projects\C++\tester\SDL\lib -lmingw32 -LSDLmain -LSDL -mwindows
I had a weird issue with the -l parameter in that I had added in a path to the SDL includes folder, C:\Projects\C++\tester\SDL\includes but if I do it chucks a error saying it cannot find this directory, obviously I checked and rechecked the path to make sure it was correct, but leaving it out removes the error. Most likely the cause of my problem now I thing about it.
The answer in this question is pretty comprehensive and helps understand the problem further
but seems to suggest that the issue is that there is no main function defined, that seems to make sense, but doesn't SDL redefine main to SDL_main in SDL_main.h?
#define main SDL_main
I'd like to point out I am a c++ noob.
#include <string.h>
#include "SDL\include\SDL.h"
#include <iostream>
int main(int argc, char*argv[])
{
return 0;
}
Ok I spotted your error.
As you probably know, -L specifies link path while -l specifies the library to be linked. Your command says:
-L C:\Projects\C++\tester\SDL\lib -lmingw32 -LSDLmain -LSDL -mwindows
^^ ^^
Which mistakenly uses -L instead of -l. You meant to write:
-L C:\Projects\C++\tester\SDL\lib -lmingw32 -lSDLmain -lSDL -mwindows
Edit: regarding libSDL2.
First of all, you need to include <SDL2/SDL.h>. You also need to link against -lSDL2main and -lSDL2.
But the main problem here is that you are linking against -lmingw32, which expects a 32-bit architecture, while you are building and linking against the 64-bit version of libSDL2. If you build and link against the 32-bit version of libSDL2, all would be ok.
If your MinGW installation is 32-bits, then you are stuck with 32-bit builds and you need to use 32-bit libraries. If it is 64-bits, -lmingw32 needs to be replaced. Perhaps with -lmingw64, but I don't have a 64-bit MinGW installed to test it and I don't know if -lmingw64 actually exists or not.

V8 "Hello World" Example - Compiling on Ubuntu 13.10 - tons of undefined reference errors "icu_46"

I am trying to follow the basic "hello world" example for Google's V8 as found here. I'm on Ubuntu 13.10, gcc version 4.8.1; this should be straighforward, no?
After building v8 itself and creating the hello world .cpp file,
I run (exactly** as Google suggests)
** Update: Okay, per my comments on the accepted answer below, I unwittingly wasn't running it exactly as Google suggests, because I thought the braces in the file name were an instruction to the reader to choose one option, not a
syntax that g++ would understand. Nontheless, it still doesn't work except with the additions suggested in the answer below
g++ -Iinclude helloworld.cpp -o hello_world out/x64.debug/obj.target/tools/gyp/libv8_base.x64.a -lpthread
And get bombarded with compile errors. There are too many to print here, but nearly all the errors are of the form:
undefined reference to 'icu_46 ...'
for example (some sample lines)
/home/ray/Playground/v8/out/../src/i18n.cc:138: undefined reference to `icu_46::UnicodeString::~UnicodeString()'
/home/ray/Playground/v8/out/../src/i18n.cc:125: undefined reference to `icu_46::UnicodeString::~UnicodeString()'
/home/ray/Playground/v8/out/../src/i18n.cc:147: undefined reference to `icu_46::UnicodeString::~UnicodeString()'
After much Googling I can figure out this has something to do with something called ICU (see http://userguide.icu-project.org/howtouseicu) but why I'm getting the error, and what I can do about it, I don't know.
While the majority of errors are icu_46 related, there are some like this as well, from the 'bootstrapper.o':
/home/ray/Playground/v8/out/x64.debug/obj.target/v8_base.x64/src/bootstrapper.o: In function `v8::internal::Bootstrapper::NativesSourceLookup(int)':
/home/ray/Playground/v8/out/../src/bootstrapper.cc:77: undefined reference to `v8::internal::NativesCollection<(v8::internal::NativeType)0>::GetBuiltinsCount()'
/home/ray/Playground/v8/out/../src/bootstrapper.cc:81: undefined reference to `v8::internal::NativesCollection<(v8::internal::NativeType)0>::GetRawScriptSource(int)'
/home/ray/Playground/v8/out/x64.debug/obj.target/v8_base.x64/src/bootstrapper.o: In function `v8::internal::Genesis::CompileBuiltin(v8::internal::Isolate*, int)':
/home/ray/Playground/v8/out/../src/bootstrapper.cc:1448: undefined reference to `v8::internal::NativesCollection<(v8::internal::NativeType)0>::GetScriptName(int)'
I'm Googled endlessly on this and have found signs that other people have run into the issue but no solutions. Any help will be hugely appreciated. Thank you.
I had the same problem on Ubuntu 12.04, g++ 4.6.3 and v8 3.22.18.
To compile hello_world.cc successfully it is necessary to add icu .a libraries and link to rt library too. As you have built v8 with make x64.debug your completed command should be:
g++ -Wall -Iinclude -o hello_world hello_world.cc ./out/x64.debug/obj.target/tools/gyp/libv8_{base.x64,snapshot}.a ./out/x64.debug/obj.target/third_party/icu/libicu{i18n,uc,data}.a -lrt

Howto compile sqlite3 in my C++ app?

SOLUTION: I just added -lpthread -ldl flags to my makefile and it works! Have no idea why, but I'm lucky enough to avoid compiling of sqlite3 by hand as I was trying.. Hmm, anyway some answers where pretty good. Thanks guys, will go and drink some tea for you.
Three months ago I was able to find how to do that but now it is not working. I have a huge C++ app, where I need to embed the sqlite3 code, but I can't compile it. I use something like this:
gcc sqlite3.c -lpthread -ldl -o ./sqlite3.o
But it does not work; I have tried a lot of variations. I have a makefile, where I added sqlite3.h and sqlite3.c files. When I do make && make install in my app's particular folder, it shows errors:
.libs/sqlite3.o: In function `pthreadMutexTry':
/home/.../client/sqlite3.c:17769: undefined reference to `pthread_mutex_trylock'
.libs/sqlite3.o: In function `pthreadMutexAlloc':
/home/.../client/sqlite3.c:17637: undefined reference to `pthread_mutexattr_init'
/home/.../client/sqlite3.c:17638: undefined reference to `pthread_mutexattr_settype'
/home/.../client/sqlite3.c:17640: undefined reference to `pthread_mutexattr_destroy'
This means that I need to add the -lpthread flag, when trying to compile sqlite3 separately from the app. Well, I am stuck.
The order of the libraries on the command line when linking matters. Put the libraries (-lpthread -ldl) last.
You need -c flag to produce an object file and not link. And skip the libraries — you pass them when linking the entire application.
gcc -c -o sqlite3.o sqlite3.c