IUP - Windows SDK静态链接

时间:2017-03-07 23:58:38

标签: c windows sdk codeblocks iup

我想在C中编写一个多平台,本机桌面应用程序。经过一番搜索,我发现IUP非常适合。不幸的是,我很难连接Windows SDK。现在,我只想静态编译Windows 8.1的x64版本。当我在Code :: Blocks中编译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 IUP文档说“对于Windows,如果您将应用程序与IUP静态链接,则还必须链接库ole32.lib和comctl32.lib(随编译器提供)。”所以我从here获得了Windows SDK,并使用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>

1 个答案:

答案 0 :(得分:2)

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

        <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库,只包括您实际使用的库。