Can not build GTK+ Windows application on Fedora Eclipse - c++

I try to build a very simple application for Windows x86 on Fedora x64 Eclipse with MinGW.
Application compiles good, however, it can not link. My link command follows:
i686-w64-mingw32-g++ `mingw32-pkg-config --libs gtk+-2.0` -o "GtkTest" ./main.o
When I run mingw32-pkg-config --libs gtk+-2.0, the output follows:
-Wl,-luuid -L/usr/i686-w64-mingw32/sys-root/mingw/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -limm32 -lshell32 -lole32 -latk-1.0 -lpangocairo-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lfreetype -lfontconfig -lpango-1.0 -lm -lcairo -lgobject-2.0 -lglib-2.0 -lintl
In no doubts folder and library files exist. However, I receive following errors:
./main.o:main.cpp:(.text.startup+0x3e): undefined reference to `gtk_init_abi_check'
./main.o:main.cpp:(.text.startup+0x43): undefined reference to `gtk_builder_new'
./main.o:main.cpp:(.text.startup+0x3d): undefined reference to `gtk_builder_add_from_file'
./main.o:main.cpp:(.text.startup+0x46): undefined reference to `gtk_widget_get_type'
./main.o:main.cpp:(.text.startup+0x58): undefined reference to `gtk_builder_get_object'
./main.o:main.cpp:(.text.startup+0x64): undefined reference to `g_type_check_instance_cast'
./main.o:main.cpp:(.text.startup+0x76): undefined reference to `gtk_builder_connect_signals'
./main.o:main.cpp:(.text.startup+0x86): undefined reference to `g_type_check_instance_cast'
./main.o:main.cpp:(.text.startup+0x8e): undefined reference to `g_object_unref'
./main.o:main.cpp:(.text.startup+0x96): undefined reference to `gtk_widget_show'
./main.o:main.cpp:(.text.startup+0x9b): undefined reference to `gtk_main'
./main.o:main.cpp:(.text.startup+0xcb): undefined reference to `g_log'
./main.o:main.cpp:(.text.startup+0xd7): undefined reference to `g_free'
So, it looks like linker doesn't see libraries at all, even they exist and I reference them in command line.
What may be the reason?

You are missing the --cflags but, above all, The order is wrong. Check out Tor Lillqvist's suggestion for proper flags ordering.

Related

Statically link SDL on Windows (MinGW) / undefined references

I built SDL (2.0.10) using cmake and now I am trying to link it to my application.
For linking I use g++ $(OBJS) -L./Path/To/SDL/LibFolder -lmingw32 -lSDL2main -lSDL2-static -oOut.exe
When I link it dynamically using SDL2, it works without problems. But I would like to link it statically.
I tried including every library that I found in error log (-lkernel32 -ladvapi32 -lgdi32 -limm32 -lmsvcrt -lole32 -loleaut32 -lsetupapi -lshell32 -luser32 -lversion -lwinmm -lmingw32 -lSDL2main -lSDL2-static), but it did nothing. I guess I don't understand how this linking stuff works.
It outputs this: (There is more, but I want to keep it simple. There are more undefined references to libraries that I listed above.)
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windows.c.obj): In function `WIN_CoInitialize':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/core/windows/SDL_windows.c:76: undefined reference to `__imp_CoInitializeEx'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windows.c.obj): In function `WIN_CoUninitialize':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/core/windows/SDL_windows.c:95: undefined reference to `__imp_CoUninitialize'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windowskeyboard.c.obj): In function `IME_SetupAPI':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:650: undefined reference to `ImmGetIMEFileNameA'
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:732: undefined reference to `ImmGetCompositionStringW'
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:737: undefined reference to `ImmGetCompositionStringW'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windowskeyboard.c.obj): In function `IME_HandleMessage':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:901: undefined reference to `ImmReleaseContext'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windowskeyboard.c.obj): In function `IME_ClearComposition':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:716: undefined reference to `ImmGetContext'

Cannot link against GLFW 3 with MinGW-w64

Compiling code that uses GLFW in MinGW-w64, everything goes fine until the linking phase. At this point, ld starts to complain about undefined references to GLFW functions, even though I specified the additional library directories and used libraries. Here's my g++ invocation (I, of course, use a lot of enviroment variables in my batch file to shorten the command, here it is unwrapped):
x86_64-w64-mingw32-g++.exe -I./deps/glfw-3.2.1/include -I./deps/gl3w/include -I./include -L./deps/glfw-3.2.1/lib-mingw-w64/x86_64 -lglfw3 -lopengl32 -lgdi32 -lkernel32 -luser32 -lcomdlg32 -std=c++14 -fpermissive -mwindows -o build\out\windows\Release\x86_64\GemVerse.exe ./deps/gl3w/src/gl3w.c ./src/main.cpp
Here is the same command, broken down:
x86_64-w64-mingw32-g++.exe %INCLUDEDIRS% %LIBDIRS64% %CFLAGS% %LIBS% -o build\out\windows\Release\x86_64\GemVerse.exe %SOURCES%
Where %INCLUDEDIRS%=-I./deps/glfw-3.2.1/include -I./deps/gl3w/include -I./deps/glm-0.9.9.3/include -I./include, %LIBDIRS64%=-L./deps/glfw-3.2.1/lib-mingw-w64/x86_64, %LIBS%=-lglfw3 -lopengl32 -lgdi32 -lkernel32 -luser32 -lcomdlg32, %CFLAGS%=-std=c++14 -fpermissive -mwindows and %SOURCES%=./deps/gl3w/src/gl3w.c ./src/main.cpp
As you can see, the library gets found and linked, but the symbols are still unresolved. How is this possible and how to link GLFW properly?
EDIT 1:I've changed the library order, now it's -lopengl32 -lgdi32 -lkernel32 -luser32 -lcomdlg32 -glfw3, so that GLFW is at the end. That didn't fix the problem, ld still doesn't find the definitions. Here is the g++ log, since I don't seem to have attached one, my fault:
./deps/gl3w/src/gl3w.c: In function 'int open_libgl()':
./deps/gl3w/src/gl3w.c:47:52: warning: invalid conversion from 'FARPROC' {aka 'long long int (*)()'} to 'void*' [-fpermissive]
*(void **)(&wgl_get_proc_address) = GetProcAddress(libgl, "wglGetProcAddress");
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x65): undefined reference to `glfwInit'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x74): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x83): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x92): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x9e): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0xc0): undefined reference to `glfwCreateWindow'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0xd4): undefined reference to `glfwMakeContextCurrent'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x1b): undefined reference to `glfwTerminate'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x3b): undefined reference to `glfwGetKey'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x5c): undefined reference to `glfwSwapBuffers'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x61): undefined reference to `glfwPollEvents'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x66): undefined reference to `glfwTerminate'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x7d): undefined reference to `glfwSetWindowShouldClose'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
Some names are mangled, since the initialization code in my project is incapsulated into a class.
I fixed the problem by putting %SOURCES% before %LIBS% in the g++ invocation, thanks to this answer. That seems to make difference as well: not only the library order is important, but the order of inputs (sources before libraries) too.

Error when building source files with wxWidgets , Linux, C++

I tried to build a source file with following command:
g++ main.cpp `wx-config --cxxflags --libs std`
/usr/bin/ld: cannot find -lgthread-2.0
/usr/bin/ld: cannot find -lX11
/usr/bin/ld: cannot find -lXxf86vm
/usr/bin/ld: cannot find -lSM
/usr/bin/ld: cannot find -lgtk-3
/usr/bin/ld: cannot find -lgdk-3
/usr/bin/ld: cannot find -latk-1.0
/usr/bin/ld: cannot find -lgio-2.0
/usr/bin/ld: cannot find -lpangocairo-1.0
/usr/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/bin/ld: cannot find -lcairo-gobject
/usr/bin/ld: cannot find -lpango-1.0
/usr/bin/ld: cannot find -lcairo
/usr/bin/ld: cannot find -lgobject-2.0
/usr/bin/ld: cannot find -lglib-2.0
/usr/bin/ld: cannot find -lpng
/usr/bin/ld: cannot find -lexpat
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
I guess I didn't install wxWidgets correctly (I installed libwxgtk3.0-dev as described in multiple install tutorials)
EDIT
wx-config --libs std
-L/usr/local/lib -pthread /usr/local/lib/libwx_gtk3u_xrc-3.1.a /usr/local/lib/libwx_gtk3u_qa-3.1.a /usr/local/lib/libwx_baseu_net-3.1.a /usr/local/lib/libwx_gtk3u_html-3.1.a /usr/local/lib/libwx_gtk3u_adv-3.1.a /usr/local/lib/libwx_gtk3u_core-3.1.a /usr/local/lib/libwx_baseu_xml-3.1.a /usr/local/lib/libwx_baseu-3.1.a -pthread -lgthread-2.0 -lX11 -lXxf86vm -lSM -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -lpng -lexpat -lwxregexu-3.1 -lwxtiff-3.1 -lwxjpeg-3.1 -lz -ldl -lm
If you use Ubuntu, you really shouldn't have any problems if you just installed the distribution package.
It looks like you had tried to install wxWidgets from sources before and your wx-config comes from /usr/local/bin and is not the one installed by the package. You can check it using which wx-config and/or using full path to /usr/bin/wx-config when compiling. Just get rid of this one, and all the other traces of wxWidgets under /usr/local, if you're using the system packages.

cUrl: Undefined reference

I am trying to use cUrl in my app but i am getting several errors. I already tried to find a solution on g or here, but nothing helped.
I build and link cUrl as static, have libcurl.a set up in linker, have proper includes but it still doesn't work.
I tried adding -lcurl into build settings but seems like it doesn't know that flag.
I am using cUrl 7.46.0 build with --disable--static and --without--ssl
and Code::Blocks ide & mingw compiler // c++ ofc
Here are those errors:
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_cleanup'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_cleanup'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_init'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_setopt'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_perform'
Compilation command:
mingw32-g++.exe -LC:\WXWID\lib\gcc_lib -o bin\Release\app.exe obj\Release\app.o obj\Release\appMain.o obj\Release\appHistory.o obj\Release\src\HTTPDownloadRequest.o obj\Release\resource.res -s -static-libgcc -static-libstdc++ -static -mthreads -lwxmsw30u_core -lwxbase30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib C:\WXWID\lib\gcc_lib\libwxmsw30u_adv.a "C:\curl\lib\libcurl.a" -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
Errors when used define CURL_STATICLIB
C:\curl\lib\libcurl.a(libcurl_la-connect.o)| undefined reference to `WSAIoctl#36'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)| undefined reference to `_imp__ldap_err2stringA'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)| undefined reference to `_imp__ldap_msgfree'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)|| undefined reference to `_imp__ldap_unbind_s'
...
If you try to link with static libcurl add -DCURL_STATICLIB to gcc arguments or define CURL_STATICLIB macro before including its headers to use correct mangling.
I would do
mingw32-g++.exe -LC:\curl\lib -lcurl ................

OpenCV LDFlags linking issue

I am compiling a program with the following flags and getting errors (running 64 bit os):
g++ -lm -lml -lcvaux -lhighgui -lcv -lcxcore main.o BRIEF.o -o BRIEF_demo
I get a bunch of undefined references:
main.cpp:(.text+0x1f6): undefined reference to `cvInitMatHeader'
main.cpp:(.text+0x218): undefined reference to cvInitMatHeader'
main.o: In function_Z14drawQuadrangleP9_IplImageiiiiiiii8CvScalari.constprop.77':
main.cpp:(.text+0x2d5): undefined reference to cvLine'
main.cpp:(.text+0x333): undefined reference tocvLine'
main.cpp:(.text+0x398): undefined reference to cvLine'
main.cpp:(.text+0x3f2): undefined reference tocvLine'
Anyone have an idea how to circumvent this?
I suppose you are using the newest OpenCV 2.3.x. cvInitMatHeader() and cvLine() are actually defined in libcxcore.so, which I can see you are including.
My guess is that the order of the linking is wrong, so you need to adjust your command to something like:
g++ main.cpp BRIEF.cpp -o BRIEF_demo -lm -lml -lcvaux -lhighgui -lcv -lcxcore