问题
I have a project that I'm been fighting to build for Windows (XP) for a month solid now. The project uses gtkmm-3, C++, and the latest GCC-TDM compiler. My IDE is CodeBlocks 13.14.
I'm making progress, however, I am now getting hung up on this error message...
ld.exe cannot find -ldwmapi
Now, DWMAPI is a DLL only available on Windows Vista and above. According to my research, you can Delay Loading of certain DLLs in cases where they are present on some systems, but not on others.
The problem is, I have no clue how to do this on CodeBlocks. The -z lazy
option does not accomplish this. If Delay Loading is impossible, how do I get around the dwmapi
dependency. There has to be a way!
Full Build Command: (errors at bottom)
-------------- Clean: Debug in infiltrator (compiler: GNU GCC Compiler)---------------
Cleaned "infiltrator - Debug"
-------------- Build: Debug in infiltrator (compiler: GNU GCC Compiler)---------------
mingw32-g++-dw2.exe -std=c++11 -Wall -mms-bitfields -pthread -IC:/dev/MinGW/include/glibmm-2.4 -IC:/dev/MinGW/lib/glibmm-2.4/include -IC:/dev/MinGW/include/sigc++-2.0 -IC:/dev/MinGW/lib/sigc++-2.0/include -IC:/dev/MinGW/include/glib-2.0 -IC:/dev/MinGW/lib/glib-2.0/include -IC:/dev/MinGW/include/gtkmm-3.0 -IC:/dev/MinGW/lib/gtkmm-3.0/include -IC:/dev/MinGW/include/atkmm-1.6 -IC:/dev/MinGW/include/giomm-2.4 -IC:/dev/MinGW/lib/giomm-2.4/include -IC:/dev/MinGW/include/pangomm-1.4 -IC:/dev/MinGW/lib/pangomm-1.4/include -IC:/dev/MinGW/include/gtk-3.0 -IC:/dev/MinGW/include/cairomm-1.0 -IC:/dev/MinGW/lib/cairomm-1.0/include -IC:/dev/MinGW/include/gdk-pixbuf-2.0 -IC:/dev/MinGW/include/gdkmm-3.0 -IC:/dev/MinGW/lib/gdkmm-3.0/include -IC:/dev/MinGW/include/atk-1.0 -IC:/dev/MinGW/include/pango-1.0 -IC:/dev/MinGW/include/cairo -IC:/dev/MinGW/include/pixman-1 -IC:/dev/MinGW/include -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include -IC:/dev/MinGW/include/freetype2 -IC:/dev/MinGW/include/libpng16 -IC:/dev/MinGW/include/harfbuzz -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl -std=c++11 -Wall -g -mms-bitfields -pthread -IC:/dev/MinGW/include/glibmm-2.4 -IC:/dev/MinGW/lib/glibmm-2.4/include -IC:/dev/MinGW/include/sigc++-2.0 -IC:/dev/MinGW/lib/sigc++-2.0/include -IC:/dev/MinGW/include/glib-2.0 -IC:/dev/MinGW/lib/glib-2.0/include -IC:/dev/MinGW/include/gtkmm-3.0 -IC:/dev/MinGW/lib/gtkmm-3.0/include -IC:/dev/MinGW/include/atkmm-1.6 -IC:/dev/MinGW/include/giomm-2.4 -IC:/dev/MinGW/lib/giomm-2.4/include -IC:/dev/MinGW/include/pangomm-1.4 -IC:/dev/MinGW/lib/pangomm-1.4/include -IC:/dev/MinGW/include/gtk-3.0 -IC:/dev/MinGW/include/cairomm-1.0 -IC:/dev/MinGW/lib/cairomm-1.0/include -IC:/dev/MinGW/include/gdk-pixbuf-2.0 -IC:/dev/MinGW/include/gdkmm-3.0 -IC:/dev/MinGW/lib/gdkmm-3.0/include -IC:/dev/MinGW/include/atk-1.0 -IC:/dev/MinGW/include/pango-1.0 -IC:/dev/MinGW/include/cairo -IC:/dev/MinGW/include/pixman-1 -IC:/dev/MinGW/include -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include -IC:/dev/MinGW/include/freetype2 -IC:/dev/MinGW/include/libpng16 -IC:/dev/MinGW/include/harfbuzz -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl -z lazy -std=c++11 -mms-bitfields -pthread -IC:/dev/MinGW/include/glibmm-2.4 -IC:/dev/MinGW/lib/glibmm-2.4/include -IC:/dev/MinGW/include/sigc++-2.0 -IC:/dev/MinGW/lib/sigc++-2.0/include -IC:/dev/MinGW/include/glib-2.0 -IC:/dev/MinGW/lib/glib-2.0/include -IC:/dev/MinGW/include/gtkmm-3.0 -IC:/dev/MinGW/lib/gtkmm-3.0/include -IC:/dev/MinGW/include/atkmm-1.6 -IC:/dev/MinGW/include/giomm-2.4 -IC:/dev/MinGW/lib/giomm-2.4/include -IC:/dev/MinGW/include/pangomm-1.4 -IC:/dev/MinGW/lib/pangomm-1.4/include -IC:/dev/MinGW/include/gtk-3.0 -IC:/dev/MinGW/include/cairomm-1.0 -IC:/dev/MinGW/lib/cairomm-1.0/include -IC:/dev/MinGW/include/gdk-pixbuf-2.0 -IC:/dev/MinGW/include/gdkmm-3.0 -IC:/dev/MinGW/lib/gdkmm-3.0/include -IC:/dev/MinGW/include/atk-1.0 -IC:/dev/MinGW/include/pango-1.0 -IC:/dev/MinGW/include/cairo -IC:/dev/MinGW/include/pixman-1 -IC:/dev/MinGW/include -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include -IC:/dev/MinGW/include/freetype2 -IC:/dev/MinGW/include/libpng16 -IC:/dev/MinGW/include/harfbuzz -Iinclude -IC:\dev\MinGW\include -c "C:\Documents and Settings\Jason\Desktop\infiltrator\main.cpp" -o obj\Debug\main.o
mingw32-g++-dw2.exe -std=c++11 -Wall -mms-bitfields -pthread -IC:/dev/MinGW/include/glibmm-2.4 -IC:/dev/MinGW/lib/glibmm-2.4/include -IC:/dev/MinGW/include/sigc++-2.0 -IC:/dev/MinGW/lib/sigc++-2.0/include -IC:/dev/MinGW/include/glib-2.0 -IC:/dev/MinGW/lib/glib-2.0/include -IC:/dev/MinGW/include/gtkmm-3.0 -IC:/dev/MinGW/lib/gtkmm-3.0/include -IC:/dev/MinGW/include/atkmm-1.6 -IC:/dev/MinGW/include/giomm-2.4 -IC:/dev/MinGW/lib/giomm-2.4/include -IC:/dev/MinGW/include/pangomm-1.4 -IC:/dev/MinGW/lib/pangomm-1.4/include -IC:/dev/MinGW/include/gtk-3.0 -IC:/dev/MinGW/include/cairomm-1.0 -IC:/dev/MinGW/lib/cairomm-1.0/include -IC:/dev/MinGW/include/gdk-pixbuf-2.0 -IC:/dev/MinGW/include/gdkmm-3.0 -IC:/dev/MinGW/lib/gdkmm-3.0/include -IC:/dev/MinGW/include/atk-1.0 -IC:/dev/MinGW/include/pango-1.0 -IC:/dev/MinGW/include/cairo -IC:/dev/MinGW/include/pixman-1 -IC:/dev/MinGW/include -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include -IC:/dev/MinGW/include/freetype2 -IC:/dev/MinGW/include/libpng16 -IC:/dev/MinGW/include/harfbuzz -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl -std=c++11 -Wall -g -mms-bitfields -pthread -IC:/dev/MinGW/include/glibmm-2.4 -IC:/dev/MinGW/lib/glibmm-2.4/include -IC:/dev/MinGW/include/sigc++-2.0 -IC:/dev/MinGW/lib/sigc++-2.0/include -IC:/dev/MinGW/include/glib-2.0 -IC:/dev/MinGW/lib/glib-2.0/include -IC:/dev/MinGW/include/gtkmm-3.0 -IC:/dev/MinGW/lib/gtkmm-3.0/include -IC:/dev/MinGW/include/atkmm-1.6 -IC:/dev/MinGW/include/giomm-2.4 -IC:/dev/MinGW/lib/giomm-2.4/include -IC:/dev/MinGW/include/pangomm-1.4 -IC:/dev/MinGW/lib/pangomm-1.4/include -IC:/dev/MinGW/include/gtk-3.0 -IC:/dev/MinGW/include/cairomm-1.0 -IC:/dev/MinGW/lib/cairomm-1.0/include -IC:/dev/MinGW/include/gdk-pixbuf-2.0 -IC:/dev/MinGW/include/gdkmm-3.0 -IC:/dev/MinGW/lib/gdkmm-3.0/include -IC:/dev/MinGW/include/atk-1.0 -IC:/dev/MinGW/include/pango-1.0 -IC:/dev/MinGW/include/cairo -IC:/dev/MinGW/include/pixman-1 -IC:/dev/MinGW/include -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include -IC:/dev/MinGW/include/freetype2 -IC:/dev/MinGW/include/libpng16 -IC:/dev/MinGW/include/harfbuzz -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl -z lazy -std=c++11 -mms-bitfields -pthread -IC:/dev/MinGW/include/glibmm-2.4 -IC:/dev/MinGW/lib/glibmm-2.4/include -IC:/dev/MinGW/include/sigc++-2.0 -IC:/dev/MinGW/lib/sigc++-2.0/include -IC:/dev/MinGW/include/glib-2.0 -IC:/dev/MinGW/lib/glib-2.0/include -IC:/dev/MinGW/include/gtkmm-3.0 -IC:/dev/MinGW/lib/gtkmm-3.0/include -IC:/dev/MinGW/include/atkmm-1.6 -IC:/dev/MinGW/include/giomm-2.4 -IC:/dev/MinGW/lib/giomm-2.4/include -IC:/dev/MinGW/include/pangomm-1.4 -IC:/dev/MinGW/lib/pangomm-1.4/include -IC:/dev/MinGW/include/gtk-3.0 -IC:/dev/MinGW/include/cairomm-1.0 -IC:/dev/MinGW/lib/cairomm-1.0/include -IC:/dev/MinGW/include/gdk-pixbuf-2.0 -IC:/dev/MinGW/include/gdkmm-3.0 -IC:/dev/MinGW/lib/gdkmm-3.0/include -IC:/dev/MinGW/include/atk-1.0 -IC:/dev/MinGW/include/pango-1.0 -IC:/dev/MinGW/include/cairo -IC:/dev/MinGW/include/pixman-1 -IC:/dev/MinGW/include -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include -IC:/dev/MinGW/include/freetype2 -IC:/dev/MinGW/include/libpng16 -IC:/dev/MinGW/include/harfbuzz -Iinclude -IC:\dev\MinGW\include -c "C:\Documents and Settings\Jason\Desktop\infiltrator\src\agentDatabase.cpp" -o obj\Debug\src\agentDatabase.o
mingw32-g++-dw2.exe -LC:\dev\MinGW\lib -o bin\Debug\infiltrator.exe obj\Debug\main.o obj\Debug\src\agentDatabase.o obj\Debug\src\agentWindow.o obj\Debug\src\customWidgets.o obj\Debug\src\fileEncryption.o obj\Debug\src\gameWindow.o obj\Debug\src\infoWindow.o obj\Debug\src\keyGen.o obj\Debug\src\playerList.o obj\Debug\src\primaryWindow.o obj\Debug\src\setupWindow.o -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl -Wl,-luuid -LC:/dev/MinGW/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lgtk-3 -lglibmm-2.4 -lcairomm-1.0 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -lwinmm -ldwmapi -lz -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lsigc-2.0 -lgobject-2.0 -lglib-2.0 -lintl
C:/dev/MinGWOld/bin/../lib/gcc/mingw32/5.1.0-dw2/../../../../mingw32/bin/ld.exe: cannot find -ldwmapi
C:/dev/MinGWOld/bin/../lib/gcc/mingw32/5.1.0-dw2/../../../../mingw32/bin/ld.exe: cannot find -ldwmapi
C:/dev/MinGWOld/bin/../lib/gcc/mingw32/5.1.0-dw2/../../../../mingw32/bin/ld.exe: cannot find -ldwmapi
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (1 minute(s), 42 second(s))
3 error(s), 7 warning(s) (1 minute(s), 42 second(s))
回答1:
Lazy linking, -z lazy
, is the GNU linker's default on unix-like systems and
is not supported in the MinGW Windows ports. (This has nothing to do with
Code::Blocks)
I cannot fathom the hope that you repose in lazy linking to overcome this problem, but it doesn't matter. If you can't count on some shared library to be available on all target systems of your project one customary course is to link the library statically in your executable. You can do that here.
The 32-bit TDM GCC that you are now using does not ship dwmapi
in a static
library but the corresponding 64-bit toolchain does ship both 64- and 32-bit
builds of it, respectively:
<TDM-GCC-64-install-dir>/x86_64-w64-mingw32/lib/libdwmapi.a
and
<TDM-GCC-64-install-dir>/x86_64-w64-mingw32/lib32/libdwmapi.a
Those paths are among the linker defaults for the toolchain, so it
will link the library if you simply mention -ldwmapi
in the linker options
(as you have done).
The absence of libdwmapi.a
in the 32-bit toolchain may just be an anomaly, or
it may be a decision based on the fact that this library was not around until
Windows had transitioned to 64-bit in the mainstream.
You have 3 options then:
If you have no committment to building 32-bit you can swap to the corresponding 64-bit toolchain (and 64-bit libraries accross the board)
Swap to the 64-bit toolchain but continue to build 32-bit by adding the option
-m32
for the compiler and linkerInstall the 64-bit toolchain, continue using the 32-bit toolchain, but add
-L<TDM-GCC-64-install-dir>/x86_64-w64-mingw32/lib32
to your linker search paths, after all those you have already specified.
A couple of unrelated observations:-
In this and your previous question all of your g++ commandline options appear 3 times each! - yielding 4K commandlines that make very tiresome parsing. With the Code::Blocks IDE, the only way in which you can have produced this triplication is by setting all of these options once in the global Settings -> Compiler, then again in the overall project settings infiltrator -> Build options -> infiltrator, and yet again in the project Debug/Release configuration settings infiltrator -> Build options -> infiltrator -> Debug/Release.
These 3 levels of settings form an inheritance hierarchy. Do not make any project specific settings globally for any compiler. Doing so makes them properties of the compiler and they will be applied to every other project that you build with that compiler. Project settings that are invariant between project configurations (Debug/Release) should be made only once at the project level. Debug and Release options should be set only at the project configuration level.
Lastly I see that you have chosen to install the TDM-GCC-32 variant with Dwarf2 style exception handling, rather than the default package (per the executable installer) with setjump-longjump style exception handling. This carries a risk. While DW2 exception handling is significantly more efficient that SJLJ, it is foreign to Windows and will fail if an exception must propagate through a Windows library not built in the same way. The setjump-longjump mechamism, though slower, relies on primtive, long standardized C library facilities that any C or C++ compiler implements.
来源:https://stackoverflow.com/questions/32919083/delay-loading-dwmapi-on-windows-xp-and-codeblocks