【问题标题】:How to embed asmjit into own C++ project?如何将 asmjit 嵌入到自己的 C++ 项目中?
【发布时间】:2018-12-23 18:36:33
【问题描述】:

我是 asmjit 的新手(对 C++ 也有些陌生),现在我正试图让 asmjit 在我的 C++ 项目中工作。我正在使用带有 Visual Studio 17 和 C++17 的 Windows 机器,我第一次尝试使用 cmake 已经很好了。

但是,我宁愿按照here 的建议将 asmjit 嵌入到我的项目中(请参阅配置和构建部分,第一段)。如那里所述,我只是将src 目录复制到我的项目目录中并定义了ASMJIT_EMBEDASMJIT_STATIC 标志(尽管我知道只有一个就足够了,但它不会改变任何东西)。然后我尝试了一个非常简单的测试如下:

#define ASMJIT_EMBED              // Asmjit is embedded (implies ASMJIT_STATIC).
#define ASMJIT_STATIC             // Define to enable static-library build.

#include "src\asmjit\asmjit.h"

int main(int argc, const char* argv[])
{
    asmjit::X86Xmm var1;
}

代码编译正常,但是链接器不断抛出unresolved externals 错误:

1>------ Build started: Project: Project2, Configuration: Debug Win32 ------
1>main.cpp
1>d:\eig\arbeit\local_forschung\project2\src\asmjit\base\operand.h(1500): warning C4804: '~': unsafe use of type 'bool' in operation
1>d:\eig\arbeit\local_forschung\project2\src\asmjit\base\operand.h(1527): note: see reference to class template instantiation 'asmjit::TypeIdOfInt<bool>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\filesystem(2447): note: see reference to class template instantiation 'std::chrono::time_point<std::filesystem::_File_time_clock,std::filesystem::_File_time_clock::duration>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\type_traits(520): note: see reference to class template instantiation 'std::basic_string_view<wchar_t,std::char_traits<wchar_t>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\type_traits(1358): note: see reference to class template instantiation 'std::is_convertible<const _StringViewIsh &,std::basic_string_view<wchar_t,std::char_traits<wchar_t>>>' being compiled
1>        with
1>        [
1>            _StringViewIsh=const wchar_t *
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\type_traits(1364): note: see reference to class template instantiation 'std::conjunction<std::is_convertible<const _StringViewIsh &,std::basic_string_view<wchar_t,std::char_traits<wchar_t>>>,std::negation<std::is_convertible<const _StringViewIsh &,const _Elem *>>>' being compiled
1>        with
1>        [
1>            _StringViewIsh=const wchar_t *,
1>            _Elem=wchar_t
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\xstring(2105): note: see reference to variable template 'const bool conjunction_v<std::is_convertible<wchar_t const * const &,std::basic_string_view<wchar_t,std::char_traits<wchar_t> > >,std::negation<std::is_convertible<wchar_t const * const &,wchar_t const *> > >' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\xstring(2264): note: see reference to alias template instantiation '_Is_string_view_ish<const wchar_t*>' being compiled
1>d:\eig\arbeit\local_forschung\project2\src\asmjit\base\operand.h(1500): warning C4804: '<': unsafe use of type 'bool' in operation
1>   Creating library D:\eig\Arbeit\local_Forschung\Project2\Debug\Project2.lib and object D:\eig\Arbeit\local_Forschung\Project2\Debug\Project2.exp
1>main.obj : error LNK2001: unresolved external symbol "struct asmjit::X86OpData const asmjit::x86OpData" (?x86OpData@asmjit@@3UX86OpData@1@B)
1>D:\eig\Arbeit\local_Forschung\Project2\Debug\Project2.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Project2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

可能,我做错了什么 - 但这是什么?

【问题讨论】:

  • 您还需要将复制的文件添加到解决方案/项目中,以便 MSVS 实际构建它们。
  • 你没有链接 asmjit(可能是静态的)库
  • @orhtej2 你完全正确,这解决了问题!谢谢!如果您将其作为答案,我会接受(并投票:-))。
  • @VTT 我不确定你的意思,据我了解,嵌入应该使链接库变得不必要。
  • 在单个文件中定义 ASMJIT_STATIC 或 ASMJIT_EMBED 是错误的做法。首先,你只需要其中一个(不管是哪一个,因为它们主要在 cmake 级别区分),其次你必须为每个项目定义它——所有使用 asmjit 的文件都应该定义它,但是它必须一致。如果您要嵌入 asmjit,只需为每个项目定义它就可以了。

标签: c++ jit asmjit


【解决方案1】:

根据 orhtej2 的评论

您还需要将复制的文件添加到解决方案/项目中,以便 MSVS 实际构建它们。

这就是我所做的:只需右键单击项目 ==> 添加 ==> 现有项,然后从 asmjit 目录中选择所有源文件。这很好用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 2014-07-25
    • 2017-12-22
    • 2021-03-09
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多