Home > database >  GCC, GTK on Windows10 ld.exe: cannot find -ldwmapi
GCC, GTK on Windows10 ld.exe: cannot find -ldwmapi

Time:09-26

I'm pretty new to all this so excuse me if I put useless info, or forget useful ones on this post.

I'm trying to code a GUI with GTK in C on Windows10. So I have installed Msys2 in order to use GTK. In Msys2 I have installed the basic pkgs and all the GTK pkgs. Then on VScode I have installed an extension to link external libraries

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\msys64\\mingw32\\include\\gtk-3.0\\",
                "C:\\msys64\\mingw32\\include\\glib-2.0",
                "C:\\msys64\\mingw32\\include\\pango-1.0",
                "C:\\msys64\\mingw32\\include\\harfbuzz",
                "C:\\msys64\\mingw32\\include\\cairo",
                "C:\\msys64\\mingw32\\include\\gdk-pixbuf-2.0",
                "C:\\msys64\\mingw32\\include\\atk-1.0"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "D:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\cl.exe",
            "cStandard": "c17",
            "cppStandard": "c  17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

Here's what it looks like, but I believe this doesn't really matter as I manually compile on the powershell.

Here's how I compile my file (in a .bat file):

gcc main.c -o mikey.exe -LC:\msys64\mingw32\lib\gtk-3.0 -Wl,-luuid -LC:\msys64\mingw32\lib -lgtk-3 -lgdk-3 -lz -lgdi32 -limm32 -lshell32 -lole32 -ldwmapi -lwinmm -lsetupapi -lcfgmgr32 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lharfbuzz -lcairo -lgobject-2.0 -lglib-2.0 -lintl -IC:\msys64\mingw32\include\gtk-3.0 -IC:\\msys64\\mingw32\\include\\glib-2.0 -IC:\\msys64\\mingw32\\include\\pango-1.0 -IC:\\msys64\\mingw32\\include\\harfbuzz -IC:\\msys64\\mingw32\\include\\cairo -IC:\\msys64\\mingw32\\include\\gdk-pixbuf-2.0 -IC:\\msys64\\mingw32\\include\\atk-1.0  

All the -l args come from:

C:\msys64\mingw32\bin\pkg-config.exe --libs gtk -3.0

This looks bad because I failed at trying to put pkg-config on PATH or wtv x)

And the -I were consecutively asked by the compiler.

Sooooo now I get the following error when compiling:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -ldwmapi
collect2.exe: error: ld returned 1 exit status

I know that the dwmapi.dll exists in my System32 folder, but I don't even know if it the subject here.

I am completly lost tbh

My main.c if necessary:

#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
    GtkWidget *window;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show(window);

    gtk_main();

    return 0;
}

CodePudding user response:

Different MinGW versions usually don't play well together.

Since MSYS2 ships it's own MinGW, you should uninstall the other version you have in C:\mingw, or at least remove it from PATH.

  • Related