如何将ASMJIT嵌入到自己的C++项目中? 我是ASMJIT新手,对C++有点新的,现在我正试图让ASMJIT在我的C++项目中工作。我使用的是一台Windows机器,带有Visual Studio 17和C++17,我的第一次尝试使用cmake已经很好地工作了

如何将ASMJIT嵌入到自己的C++项目中? 我是ASMJIT新手,对C++有点新的,现在我正试图让ASMJIT在我的C++项目中工作。我使用的是一台Windows机器,带有Visual Studio 17和C++17,我的第一次尝试使用cmake已经很好地工作了,c++,jit,asmjit,C++,Jit,Asmjit,然而,我更愿意按照建议将asmjit嵌入到我的项目中,请参见第1段的“配置和构建”一节。如上所述,我只是将src目录复制到我的项目目录中,并定义了ASMJIT_EMBED和ASMJIT_静态标志,尽管我知道只有一个就足够了,但它不会改变任何东西。然后我尝试了一个非常简单的测试,如下所示: #define ASMJIT_EMBED // Asmjit is embedded (implies ASMJIT_STATIC). #define ASMJIT_STATIC

然而,我更愿意按照建议将asmjit嵌入到我的项目中,请参见第1段的“配置和构建”一节。如上所述,我只是将src目录复制到我的项目目录中,并定义了ASMJIT_EMBED和ASMJIT_静态标志,尽管我知道只有一个就足够了,但它不会改变任何东西。然后我尝试了一个非常简单的测试,如下所示:

#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;
}
代码编译良好,但是链接器不断抛出未解决的外部错误:


也许,我做错了一些可怕的事情——但这是什么呢?

根据orhtej2的评论


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


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

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