TL;DR;
プロジェクトプロパティのランタイムライブラリの設定を確認
Debugビルドでは、MTdかMDd(DLL)にする。
普通にプロジェクトを作っていれば、デフォで正しく設定されていると思うのですが。適当に拾ってきたPJで狂っていたのでハマりました…(MSが公開してるサンプルだったんだけどなぁ)
エラー内容
エラー LNK2019 未解決の外部シンボル
__imp__invalid_parameter が関数
"void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64)"
(??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPEAX_K@Z)
で参照されました。
エラーでは_Allocate_manually_vector_aligned
が槍玉にあげられていますが、これに限った原因ではないと思うので、別のシンボルでエラーが出る可能性もあると思います。
余談
余談ですが、少し気になったので_Allocate_manually_vector_aligned
について。
xmemory.h
に実装されています。
// FUNCTION _Allocate_manually_vector_aligned
template <class _Traits>
_DECLSPEC_ALLOCATOR void* _Allocate_manually_vector_aligned(const size_t _Bytes) {
// allocate _Bytes manually aligned to at least _Big_allocation_alignment
const size_t _Block_size = _Non_user_size + _Bytes;
if (_Block_size <= _Bytes) {
_Throw_bad_array_new_length(); // add overflow
}
const uintptr_t _Ptr_container = reinterpret_cast<uintptr_t>(_Traits::_Allocate(_Block_size));
_STL_VERIFY(_Ptr_container != 0, "invalid argument"); // validate even in release since we're doing p[-1]
void* const _Ptr = reinterpret_cast<void*>((_Ptr_container + _Non_user_size) & ~(_Big_allocation_alignment - 1));
static_cast<uintptr_t*>(_Ptr)[-1] = _Ptr_container;
#ifdef _DEBUG
static_cast<uintptr_t*>(_Ptr)[-2] = _Big_allocation_sentinel;
#endif // _DEBUG
return _Ptr;
}
このxmemoryの関数もvectorも、ヘッダに直に実装されているので「ヘッダがIncludeできた時点でリンクできないなんてことはない」と思ったのですが…🤔🤔🤔