1

I am new to asmjit (and somewhat new to C++), and right now I am trying to just get asmjit working within my C++ project. I am using a Windows machine with Visual Studio 17 and C++17, and my first attempt using cmake already worked fine.

However, I'd rather have asmjit embedded into my project as suggested here (see section Configuring & Building, first paragraph). As described there, I just copied the src directory into my project directory and defined the ASMJIT_EMBED and ASMJIT_STATIC flags (though I'm aware that only one would suffice, but it doesn't change anything). Then I tried a very simple test as follows:

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

The code compiles fine, however, the linker keeps throwing unresolved externals errors:

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 ==========

Probably, I am doing something horribly wrong - but what is it?

Duke
  • 410
  • 7
  • 15
  • 2
    You also need to add the files you copied to the solution/project so that MSVS actually builds them. – orhtej2 Jul 16 '18 at 09:00
  • 1
    You are not linking asmjit (probably static) library – user7860670 Jul 16 '18 at 09:10
  • 1
    @orhtej2 You were perfectly right, that solved the problem! Thanks! If you make it an answer, I'll accept it (and vote up :-) ). – Duke Jul 16 '18 at 19:57
  • @VTT I'm not sure what you mean, as I understand, the embedding should make it unnecessary to link a library. – Duke Jul 16 '18 at 19:59
  • 1
    Defining ASMJIT_STATIC or ASMJIT_EMBED in a single file is the wrong way of doing it. Firstly, you just need one of them (it doesn't matter which one as they are mostly distinguished at cmake level) and secondly you have to define it per-project - all files that use asmjit should have it defined or not, but it must be consistent. If you are embedding asmjit just define it per project and you will be fine. – Petr Jul 21 '18 at 23:48

1 Answers1

-1

Based on orhtej2's comment

You also need to add the files you copied to the solution/project so that MSVS actually builds them.

this is what I did: Just right click on the project ==> Add ==> Existing Item, and then select all the source files from the asmjit directories. This worked fine.

Duke
  • 410
  • 7
  • 15