So this is kind of a follow-up to my last issue with making a "minimal" rust library that links against a C/C++ library: https://users.rust-lang.org/t/workspace-link-static-c-c-library-release-vs-debug/ but that specific issue was solved. On to the next issue encountered!
TL;DR; Building in debug fails with an error about debug library linking because C++ is allocating now, building in release works fine.
Repository still the same one as last time, now on a branch for the issue: Github Repository
I changed my C++ file to include this:
#include <string>
size_t print_int_val(int value)
{
#ifdef _DEBUG
std::string profile = "DEBUG";
#else
std::string profile = "RELEASE";
#endif
printf("Profile is: %s\n", profile.c_str());
auto num_printed = printf("Value is: %d\n", value);
return num_printed;
}
No changes to Rust. That's the only difference between the branch and master. Release builds and runs. The linker error is as follows:
= note: liblink_to_c-ee0db79a9f7fbfea.rlib(RustTestStatic.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:REF' specification
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
liblink_to_c-ee0db79a9f7fbfea.rlib(RustTestStatic.obj) : error LNK2019: unresolved external symbol __imp__invalid_parameter referenced in function "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)
liblink_to_c-ee0db79a9f7fbfea.rlib(RustTestStatic.obj) : error LNK2019: unresolved external symbol __imp__CrtDbgReport referenced in function "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)
C:\Users\Kevin\Source\Rust\workspace_test_public\target\debug\deps\console_test.exe : fatal error LNK1120: 2 unresolved externals
My guess so far is that the debug library for the allocator doesn't link nicely like the release one does, but not sure what the right linking arguments are. I also added more allocations (a vector push/popping, etc) to see if Release was just optimizing away the string allocation, but that doesn't seem to be true.
Any ideas here for the right way to link? this PR came up when googling, but even if that's the right solution, I don't know how to make that work with what I'm doing. I also tried to do , modifiers = "-bundle"
for debug as well, but that didn't help either.