c++ - 在使用 Visual Studio 2013 64 位编译器编译的 CMake 项目中使用 ttmath

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

包含标题时

#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})

最佳答案

如上所述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)

关于c++ - 在使用 Visual Studio 2013 64 位编译器编译的 CMake 项目中使用 ttmath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29732727/

相关文章:

ios - 在 IOS 中哪里可以找到 CMAKE_OSX_SYSROOT

c++ - 在共享库中使用 fastcall 安全吗?

visual-studio - Visual Studio 不支持包含目录

c++ - 不能包含/usr/include/linux 文件

visual-studio - Eclipse 的旋风之旅?

c# - 配置 Visual Studio 自动完成以列出命名空间之外的类?

python-2.7 - Linux CentOS 7上的CMake,如何强制系统使用cmake3?

c++ - Windows xp 上的 SystemTimeToTzSpecificLocalTime 崩溃

c++ - 将 long long 除以 int 会遇到什么问题?

c++ - 为什么 ncurses 小部件在单独的函数中创建时不能正常工作?