IUP - Windows SDK 静态 link

IUP - Windows SDK static link

我想用 C 语言编写一个多平台的本地桌面应用程序。经过一番搜索,我在 Code::Blocks 中找到了 IUP to be the perfect fit. Unfortunately, I'm struggling to link the Windows SDK. For now, I just want to statically compile the x64 version for Windows 8.1. When I compile this 示例,我得到以下错误:

g++.exe -LC:\MinGW\iup -o "bin-debug\EVE Editor.exe" obj-debug\main.o   -lgdi32 -luser32 -lkernel32 -lcomctl32 -lole32 -lfreetype6 -liup -liup_mglplot -liup_plot -liup_scintilla -liupcd -liupcontrols -liupgl -liupglcontrols -liupim -liupimglib -liupmatrixex -liupole -liuptuio -lz
C:\MinGW\iup/libiup.a(iupwin_font.o):iupwin_font.c:(.text+0x1db): undefined reference to `__imp_CreateFontW'
C:\MinGW\iup/libiup.a(iupwin_font.o):iupwin_font.c:(.text+0x224): undefined reference to `__imp_SelectObject'
C:\MinGW\iup/libiup.a(iupwin_font.o):iupwin_font.c:(.text+0x240): undefined reference to `__imp_GetTextMetricsW'
C:\MinGW\iup/libiup.a(iupwin_font.o):iupwin_font.c:(.text+0x684): undefined reference to `__imp_SelectObject'
C:\MinGW\iup/libiup.a(iupwin_font.o):iupwin_font.c:(.text+0x734): undefined reference to `__imp_GetTextExtentPoint32W'

等等等等。 Here the IUP documentation says "For Windows, if you statically link the application with IUP you must link also with the libraries ole32.lib and comctl32.lib (provided with the compilers)." So I obtained the Windows SDK from here 并使用 ole32 和 comctl32 重新编译。我得到了同样的错误。我也在同一页上查看了 Code::Blocks 指南,但它是用于动态链接的。

我以前从未链接过 Windows SDK,所以我很茫然。这是我的 Code::Blocks 项目:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
    <FileVersion major="1" minor="6" />
    <Project>
        <Option title="EVE Editor" />
        <Option pch_mode="2" />
        <Option compiler="gcc" />
        <Build>
            <Target title="Debug">
                <Option output="bin-debug/EVE Editor" prefix_auto="1" extension_auto="1" />
                <Option object_output="obj-debug/" />
                <Option type="1" />
                <Option compiler="gcc" />
                <Compiler>
                    <Add option="-g" />
                </Compiler>
            </Target>
            <Target title="Release">
                <Option output="bin/EVE Editor" prefix_auto="1" extension_auto="1" />
                <Option object_output="obj/" />
                <Option type="0" />
                <Option compiler="gcc" />
                <Compiler>
                    <Add option="-O2" />
                </Compiler>
                <Linker>
                    <Add option="-s" />
                </Linker>
            </Target>
        </Build>
        <Compiler>
            <Add option="-Wall" />
            <Add directory="C:/MinGW/iup/include" />
        </Compiler>
        <ResourceCompiler>
            <Add directory="C:/MinGW/iup/etc" />
        </ResourceCompiler>
        <Linker>
            <Add library="gdi32" />
            <Add library="user32" />
            <Add library="kernel32" />
            <Add library="comctl32" />
            <Add library="ole32" />
            <Add library="libfreetype6.a" />
            <Add library="libiup.a" />
            <Add library="libiup_mglplot.a" />
            <Add library="libiup_plot.a" />
            <Add library="libiup_scintilla.a" />
            <Add library="libiupcd.a" />
            <Add library="libiupcontrols.a" />
            <Add library="libiupgl.a" />
            <Add library="libiupglcontrols.a" />
            <Add library="libiupim.a" />
            <Add library="libiupimglib.a" />
            <Add library="libiupmatrixex.a" />
            <Add library="libiupole.a" />
            <Add library="libiuptuio.a" />
            <Add library="libz.a" />
            <Add directory="C:/MinGW/iup" />
        </Linker>
        <Unit filename="main.c">
            <Option compilerVar="CC" />
        </Unit>
        <Extensions>
            <code_completion />
            <envvars />
            <debugger />
            <lib_finder disable_auto="1" />
        </Extensions>
    </Project>
</CodeBlocks_project_file>

尝试更改链接完成的顺序。依赖顺序必须颠倒,我的意思是最后依赖最少的库。例如:

        <Add library="libiupcontrols.a" />   -- optional
        <Add library="libiupcd.a" />         -- optional
        <Add library="libcd.a" />         -- optional
        <Add library="libfreetype6.a" />  -- optional
        <Add library="libz.a" />  -- optional
        <Add library="libiup.a" />
        <Add library="gdi32" />
        <Add library="user32" />
        <Add library="kernel32" />
        <Add library="comctl32" />
        <Add library="ole32" />

而且您不需要包括所有 IUP 库,只需包括您实际使用的库。