【问题标题】:Using ttmath in CMake project compiled with the Visual Studio 2013 64-bit compiler在使用 Visual Studio 2013 64 位编译器编译的 CMake 项目中使用 ttmath
【发布时间】:2015-04-19 16:43:00
【问题描述】:

当包含标题时

#include "ttmath/ttmath.h"

ttmath's web page 中所述(其中库包含在项目文件夹内的文件夹 ttmath 中),我得到了一些编译器错误,如下所示:

main.cpp.obj:-1: error: LNK2019: unresolved external symbol ttmath_adc_x64 referenced in function "public: unsigned __int64 __cdecl ttmath::UInt<28>::Add(class ttmath::UInt<28> const &,unsigned __int64)" (?Add@?$UInt@$0BM@@ttmath@@QEAA_KAEBV12@_K@Z)

我使用的是 QT Creator 3.3.1,它生成了 CMakeLists.txt 文件

project(my_project)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

【问题讨论】:

    标签: c++ visual-studio cmake qt-creator linker-errors


    【解决方案1】:

    here 所述,问题在于Visual Studio 64 位不支持汇编代码文件ttmathuint_x86_64_msvc.asm 的内联。因此,选项是

    1. 通过添加禁用程序集

      #define TTMATH_NOASM 1
      

      在包含ttmath.h 之前。这将花费大约两倍的性能。

    2. 手动组装和包含文件:

      • 运行命令"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64\ml64.exe" /c ttmathuint_x86_64_msvc.asm(在ttmath文件夹内)。

      • 通过将CMakeLists.txt 中的最后一行替换为

        ,将目标文件包含在编译中

        add_executable(${PROJECT_NAME} ${SRC_LIST} ttmath/ttmathuint_x86_64_msvc.obj)

    【讨论】:

    • 对于使用 VS IDE 而不是 CMake 的任何人:您只需在运行上述汇编程序后将 .obj 文件拖到 VS 解决方案资源管理器中的源文件夹中即可。另外,我的 ml64.exe 位于 "%PROGRAMFILES(x86)%\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64 \" 用于 VS2017,这需要编辑包含的 win64_assemble.bat 文件。 (推荐 Notepad++ 或类似的在 Windows 上编辑,因为包含的文件使用 POSIX 换行符,而记事本不喜欢它们。)
    猜你喜欢
    • 1970-01-01
    • 2018-03-22
    • 2011-05-01
    • 1970-01-01
    • 2017-01-21
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    相关资源
    最近更新 更多