Hi! I noticed that cmake doesn’t link C++/CLI dll correctly. The problem is that cmake tries to link static version of library too, but it doesn’t exist.
I write small example to reproduce a problem:
cmake_minimum_required(VERSION 3.5)
project(BugExample LANGUAGES CSharp CXX)
include(CSharpUtilities)
if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1")
string(REPLACE "/RTC1" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
endif()
if(CMAKE_CXX_FLAGS MATCHES "/EHsc")
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
add_library(Class1 SHARED Class1.cpp)
set_property(TARGET Class1 PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
set_property(TARGET Class1 PROPERTY COMMON_LANGUAGE_RUNTIME "")
set_target_properties(Class1 PROPERTIES DEBUG_POSTFIX "d")
set_target_properties(Class1 PROPERTIES VS_GLOBAL_ManagedAssembly "true")
set_target_properties(Class1 PROPERTIES VS_GLOBAL_KEYWORD "ManagedCProj")
set_property(TARGET Class1 PROPERTY VS_DOTNET_REFERENCES
"Microsoft.CSharp"
"System"
"System.Core"
"System.Windows"
"System.Data"
"WindowsBase"
"mscorlib")
add_library(Class2 SHARED Class2.cpp)
set_property(TARGET Class2 PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
set_property(TARGET Class2 PROPERTY COMMON_LANGUAGE_RUNTIME "")
set_target_properties(Class2 PROPERTIES DEBUG_POSTFIX "d")
set_target_properties(Class2 PROPERTIES VS_GLOBAL_ManagedAssembly "true")
set_target_properties(Class2 PROPERTIES VS_GLOBAL_KEYWORD "ManagedCProj")
set_property(TARGET Class2 PROPERTY VS_DOTNET_REFERENCES
"Microsoft.CSharp"
"System"
"System.Core"
"System.Windows"
"System.Data"
"WindowsBase"
"mscorlib")
#target_compile_options(Class2 PRIVATE "/FU$<TARGET_FILE:Class1>")
target_link_libraries(Class2 Class1)
namespace Kek {
public ref class Class1 {};
}
namespace Kek {
public ref class Class2 {
void lol() {
Class1^ x = gcnew Class1();
}
};
}
So, at compilation I get:
LINK : fatal error LNK1104: cannot open file 'Debug\Class1d.lib'
To workaround this problem you can pass /FU flag manually, but it’s not cool:)