尝试使用以下命令行构建wxWidgets 3.1.0库时:
mingw32-make -f makefile.gcc BUILD = release SHARED = 1 CFLAGS =“ - O2 -flto” CXXFLAGS =“ - O2 -flto”LDFLAGS =“ - O2 -flto”
我收到此警告(31次)
lto1.exe: warning: -fPIC ignored for target (all code is position independent)
其次是:
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x13c4): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x1418): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x3792): undefined reference to `wx_regerror'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x37c1): undefined reference to `wx_regerror'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x3a7d): undefined reference to `wx_re_exec'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x47de): undefined reference to `wx_re_comp'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x4cf4): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x4f94): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x57c): undefined reference to `deflateEnd'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x88d): undefined reference to `deflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x8ba): undefined reference to `deflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x947): undefined reference to `deflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x4830): undefined reference to `deflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x59f4): undefined reference to `deflateInit2_'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans14.ltrans.o:<artificial>:(.text+0x3354): undefined reference to `deflateReset'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans14.ltrans.o:<artificial>:(.text+0x38db): undefined reference to `inflateReset'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x21d): undefined reference to `inflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x24a): undefined reference to `inflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x266): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x27d): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x2d0): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x121c): undefined reference to `inflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x1924): undefined reference to `inflateEnd'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x20b7): undefined reference to `inflateInit2_'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x3694): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x5534): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x5813): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x773e): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x7c5b): undefined reference to `crc32'
collect2.exe: error: ld returned 1 exit status
makefile.gcc:5299: recipe for target '..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll' failed
mingw32-make: *** [..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll] Error 1
编译器和链接器发出的最后一行,导致所有这些错误,如下所示:
g++ -c -o gcc_mswudll\basedll_main.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I..\..\lib\gcc_dll\mswu -I..\..\include -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswudll\basedll_main.o -MFgcc_mswudll\basedll_main.o.d -MD -MP ../../src/msw/main.cpp
g++ -c -o gcc_mswudll\basedll_volume.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I..\..\lib\gcc_dll\mswu -I..\..\include -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswudll\basedll_volume.o -MFgcc_mswudll\basedll_volume.o.d -MD -MP ../../src/msw/volume.cpp
g++ -shared -fPIC -o ..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll gcc_mswudll\basedll_dummy.o gcc_mswudll\basedll_version_rc.o gcc_mswudll\basedll_any.o gcc_mswudll\basedll_appbase.o gcc_mswudll\basedll_arcall.o gcc_mswudll\basedll_arcfind.o gcc_mswudll\basedll_archive.o gcc_mswudll\basedll_arrstr.o gcc_mswudll\basedll_base64.o gcc_mswudll\basedll_clntdata.o gcc_mswudll\basedll_cmdline.o gcc_mswudll\basedll_config.o gcc_mswudll\basedll_convauto.o gcc_mswudll\basedll_datetime.o gcc_mswudll\basedll_datetimefmt.o gcc_mswudll\basedll_datstrm.o gcc_mswudll\basedll_dircmn.o gcc_mswudll\basedll_dynarray.o gcc_mswudll\basedll_dynlib.o gcc_mswudll\basedll_dynload.o gcc_mswudll\basedll_encconv.o gcc_mswudll\basedll_evtloopcmn.o gcc_mswudll\basedll_extended.o gcc_mswudll\basedll_ffile.o gcc_mswudll\basedll_file.o gcc_mswudll\basedll_fileback.o gcc_mswudll\basedll_fileconf.o gcc_mswudll\basedll_filefn.o gcc_mswudll\basedll_filename.o gcc_mswudll\basedll_filesys.o gcc_mswudll\basedll_filtall.o gcc_mswudll\basedll_filtfind.o gcc_mswudll\basedll_fmapbase.o gcc_mswudll\basedll_fs_arc.o gcc_mswudll\basedll_fs_filter.o gcc_mswudll\basedll_hash.o gcc_mswudll\basedll_hashmap.o gcc_mswudll\basedll_init.o gcc_mswudll\basedll_intl.o gcc_mswudll\basedll_ipcbase.o gcc_mswudll\basedll_languageinfo.o gcc_mswudll\basedll_list.o gcc_mswudll\basedll_log.o gcc_mswudll\basedll_longlong.o gcc_mswudll\basedll_memory.o gcc_mswudll\basedll_mimecmn.o gcc_mswudll\basedll_module.o gcc_mswudll\basedll_mstream.o gcc_mswudll\basedll_numformatter.o gcc_mswudll\basedll_object.o gcc_mswudll\basedll_platinfo.o gcc_mswudll\basedll_powercmn.o gcc_mswudll\basedll_process.o gcc_mswudll\basedll_regex.o gcc_mswudll\basedll_stdpbase.o gcc_mswudll\basedll_sstream.o gcc_mswudll\basedll_stdstream.o gcc_mswudll\basedll_stopwatch.o gcc_mswudll\basedll_strconv.o gcc_mswudll\basedll_stream.o gcc_mswudll\basedll_string.o gcc_mswudll\basedll_stringimpl.o gcc_mswudll\basedll_stringops.o gcc_mswudll\basedll_strvararg.o gcc_mswudll\basedll_sysopt.o gcc_mswudll\basedll_tarstrm.o gcc_mswudll\basedll_textbuf.o gcc_mswudll\basedll_textfile.o gcc_mswudll\basedll_threadinfo.o gcc_mswudll\basedll_time.o gcc_mswudll\basedll_timercmn.o gcc_mswudll\basedll_timerimpl.o gcc_mswudll\basedll_tokenzr.o gcc_mswudll\basedll_translation.o gcc_mswudll\basedll_txtstrm.o gcc_mswudll\basedll_unichar.o gcc_mswudll\basedll_uri.o gcc_mswudll\basedll_ustring.o gcc_mswudll\basedll_variant.o gcc_mswudll\basedll_wfstream.o gcc_mswudll\basedll_wxcrt.o gcc_mswudll\basedll_wxprintf.o gcc_mswudll\basedll_xlocale.o gcc_mswudll\basedll_xti.o gcc_mswudll\basedll_xtistrm.o gcc_mswudll\basedll_zipstrm.o gcc_mswudll\basedll_zstream.o gcc_mswudll\basedll_fswatchercmn.o gcc_mswudll\basedll_fswatcherg.o gcc_mswudll\basedll_basemsw.o gcc_mswudll\basedll_crashrpt.o gcc_mswudll\basedll_debughlp.o gcc_mswudll\basedll_dde.o gcc_mswudll\basedll_dir.o gcc_mswudll\basedll_dlmsw.o gcc_mswudll\basedll_evtloopconsole.o gcc_mswudll\basedll_mimetype.o gcc_mswudll\basedll_power.o gcc_mswudll\basedll_regconf.o gcc_mswudll\basedll_registry.o gcc_mswudll\basedll_snglinst.o gcc_mswudll\basedll_stackwalk.o gcc_mswudll\basedll_stdpaths.o gcc_mswudll\basedll_thread.o gcc_mswudll\basedll_timer.o gcc_mswudll\basedll_utils.o gcc_mswudll\basedll_utilsexc.o gcc_mswudll\basedll_fswatcher.o gcc_mswudll\basedll_event.o gcc_mswudll\basedll_fs_mem.o gcc_mswudll\basedll_msgout.o gcc_mswudll\basedll_utilscmn.o gcc_mswudll\basedll_main.o gcc_mswudll\basedll_volume.o -mthreads -L..\..\lib\gcc_dll -Wl,--out-implib=..\..\lib\gcc_dll\libwxbase31u.a -O2 -flto -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet
到目前为止我尝试了什么:
向CFLAGS和CXXFLAGS添加-fPIC
,但无济于事。
按照MinGW-w64 Wiki的建议使用-fwhopr
代替-flto
,但 gcc.exe 和 g ++无法识别.EXE 。阅读本文后Linktime optimization in GCC, part 1 - brief history,我假设-fwhopr
选项不再存在,现在是-flto
切换的默认模式。
构建静态配置(SHARED=0
)。它成功构建,但无法使用。请参阅参考#1 。
从LDFLAGS中省略-flto
- 即仅在CFLAGS和CXXFLAGS中使用-flto
。也没有用。
如何解决这些错误,并使用GCC的链接时间优化构建wxWidgets?
我用MinGW-w64构建;线程模型 Win32 ;异常处理 DWARF ; GCC版本5.3.0。
参考编号1:“最小样本”构建命令行的结果
H:\temp\wxwidgets-3.1.0\samples\minimal>mingw32-make -f makefile.gcc BUILD=release SHARED=0 CFLAGS="-O2 -flto" CXXFLAGS="-O2 -flto" LDFLAGS="-O2 -flto"
windres --use-temp-file -i../../samples/sample.rc -ogcc_mswu\minimal_sample_rc.o --define __WXMSW__ --define NDEBUG --define _UNICODE --include-dir .\..\..\lib\gcc_lib\mswu --include-dir ./../../include --include-dir . --include-dir ./../../samples --define NOPCH
g++ -c -o gcc_mswu\minimal_minimal.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I.\..\..\lib\gcc_lib\mswu -I.\..\..\include -W -Wall -I. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswu\minimal_minimal.o -MFgcc_mswu\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswu\minimal.exe gcc_mswu\minimal_sample_rc.o gcc_mswu\minimal_minimal.o -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows -O2 -flto -lwxmsw31u_core -lwxbase31u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x191): undefined reference to `wxDefaultPosition'
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x197): undefined reference to `wxDefaultPosition'
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x1a8): undefined reference to `wxDefaultSize'
(Many, many other "undefined reference" errors - probably one for every function the code ever depends on) and then...
collect2.exe: error: ld returned 1 exit status
makefile.gcc:221: recipe for target 'gcc_mswu\minimal.exe' failed
mingw32-make: *** [gcc_mswu\minimal.exe] Error 1
答案 0 :(得分:0)
我之前从未尝试过将LTO与DLL一起使用,但显然存在漏洞,请参阅例如this one。不确定是否使用建议的解决方法可以帮助您。
我认为肯定的工作应该是同时编译你的应用程序源和wxWidgets,这类似于构建静态库但不应该优化库中未使用的东西 - 但在应用程序代码中使用。
最后,我真的不确定你是否会在wxWidgets案例中使用LTO取得很大成就。没有那么多&#34;慢&#34;要在库中优化的代码...