【问题标题】:Assimp cmake build windows big .lib filesAssimp cmake 构建 Windows 大 .lib 文件
【发布时间】:2021-09-24 05:26:51
【问题描述】:

我正在尝试使用 cmake 为 Windows 构建 assimp。感谢这里的一些好人,我已经解决了 /MD 的一些早期问题。目前的问题是输出文件(.lib 和 DLL)很大。

我已遵循有关缩小文件大小的一般建议。禁用测试、导出和使用 -Os。这是 CMakeLists 文件的一部分:

# All supported options ###############################################

OPTION( BUILD_SHARED_LIBS
  "Build package with shared libraries."
  OFF
)
OPTION( ASSIMP_BUILD_FRAMEWORK
  "Build package as Mac OS X Framework bundle."
  OFF
)
OPTION( ASSIMP_DOUBLE_PRECISION
  "Set to ON to enable double precision processing"
  OFF
)
OPTION( ASSIMP_OPT_BUILD_PACKAGES
  "Set to ON to generate CPack configuration files and packaging targets"
  OFF
)
OPTION( ASSIMP_ANDROID_JNIIOSYSTEM
  "Android JNI IOSystem support is active"
  OFF
)
OPTION( ASSIMP_NO_EXPORT
  "Disable Assimp's export functionality."
  ON
)
OPTION( ASSIMP_BUILD_ZLIB
  "Build your own zlib"
  OFF
)
OPTION( ASSIMP_BUILD_ASSIMP_TOOLS
  "If the supplementary tools for Assimp are built in addition to the library."
  OFF
)
OPTION ( ASSIMP_BUILD_SAMPLES
  "If the official samples are built as well (needs Glut)."
  OFF
)
OPTION ( ASSIMP_BUILD_TESTS
  "If the test suite for Assimp is built in addition to the library."
  OFF
)
OPTION ( ASSIMP_COVERALLS
  "Enable this to measure test coverage."
  OFF
)
OPTION( ASSIMP_INSTALL
  "Disable this if you want to use assimp as a submodule."
  ON
)
OPTION ( ASSIMP_ERROR_MAX
  "Enable all warnings."
  OFF
)
OPTION ( ASSIMP_ASAN
  "Enable AddressSanitizer."
  OFF
)
OPTION ( ASSIMP_UBSAN
  "Enable Undefined Behavior sanitizer."
  OFF
)
OPTION ( ASSIMP_BUILD_DOCS
  "Build documentation using Doxygen."
  OFF
)
OPTION( ASSIMP_INJECT_DEBUG_POSTFIX
  "Inject debug postfix in .a/.so/.dll lib names"
  ON
)

OPTION ( ASSIMP_IGNORE_GIT_HASH
   "Don't call git to get the hash."
   OFF
)

结合下面的cmake命令

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release  -DCMAKE_C_FLAGS="-Os"  -DCMAKE_CXX_FLAGS="/MD /EHsc" ..

这会给出一些警告但不会失败。这是日志:

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.29.30038.1
-- The CXX compiler identification is MSVC 19.29.30038.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Shared libraries disabled
-- Looking for ZLIB...
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could not locate ZLIB
-- compiling zlib from sources
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- Looking for fseeko
-- Looking for fseeko - not found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Build an import-only version of Assimp.
-- Enabled importer formats: AMF 3DS AC ASE ASSBIN B3D BVH COLLADA DXF CSM HMP IRRMESH IRR LWO LWS M3D MD2 MD3 MD5 MDC MDL NFF NDO OFF OBJ OGRE OPENGEX PLY MS3D COB BLEND IFC XGL FBX Q3D Q3BSP RAW SIB SMD STL TERRAGEN 3D X X3D GLTF 3MF MMD
-- Disabled importer formats:
-- Configuring done
-- Generating done

生成高达 122 MB 的 .lib 文件。作为比较,在 Android 上,我得到一个 12 MB 的 .so 文件。已经在不使用 /MD 的情况下尝试过,结果大小相当。

知道如何缩小 .lib 文件吗? VS编译器里面有什么设置可以试试吗?

【问题讨论】:

    标签: c++ windows cmake assimp


    【解决方案1】:

    .lib 文件是或者静态库Windows 上 DLL 的导入库。 Android .so 文件是一个共享对象库,相当于 Windows 上的 DLL。

    根据您的 CMakeLists 文件和生成的库的大小,您正在构建静态库。要构建assimp 的DLL 版本,您需要将BUILD_SHARED_LIBS 设置为ON。这可以在 64 位 Visual Studio 2019 构建的 CMake 命令行上完成,例如如下:

    cmake -S <sourcedir> -B <builddir> -DBUILD_SHARED_LIBS=ON -G "Visual Studio 16 2019" -A x64
    

    【讨论】:

    • 我指的是静态 .lib 文件。我知道如何在 assimp 中在静态和共享之间切换,CMakeLists.txt 非常清楚。我确实偏爱静态链接。但相比之下,Android .a 库为 40 MB。这是可以接受的。恕我直言,120MB 太大了。任何想法如何缩小它?
    • 很遗憾没有。 Assimp 使用 C++ STD 和 STL 特性,标准库和 STL 的 MSVC 实现以生成巨大的静态库而闻名。对不起。
    • 还有一个问题。那么完全相同的构建设置的DLL(当然除了BUILD_SHARED_LIBS)只有5 MB是否也是正常的。这也正常吗?
    • 是的,我希望如此。但是 DLL 的大小取决于你是链接到静态还是动态运行时库,即使用 /MT/MD
    猜你喜欢
    • 1970-01-01
    • 2019-01-11
    • 2021-12-14
    • 2020-01-01
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多