compile:修正win下mingw编译

This commit is contained in:
taynpg 2024-12-24 12:46:52 +08:00
parent cf6168a89a
commit 1e83e393eb
3 changed files with 21 additions and 1 deletions

View File

@ -8,6 +8,12 @@ if (MSVC)
add_compile_options(/source-charset:utf-8)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
MESSAGE(STATUS "Ofen Add MinGW Param.")
add_compile_options(-finput-charset=utf-8)
add_compile_options(-fexec-charset=gbk)
endif()
set(CMAKE_DEBUG_POSTFIX "d")
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}")
@ -30,7 +36,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
add_library(Ofen STATIC ${SRC_FILES})
target_include_directories(Ofen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
# ****************************************************************************************
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OfenConfig.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/Ofen)

View File

@ -73,6 +73,16 @@ ofString COfPath::get_home()
#if defined(_WIN32)
ofChar* value = nullptr;
std::size_t len = 0;
// _dupenv_s() 在 Visual Studio 2008 的 CRT (msvcr90) 中引入的,似乎没有进入系统 CRT (msvcrt)。
// mingw-w64 GCC 通常默认只链接到系统 CRT,所以所以找不到这个符号。
#if defined(__MINGW32__) || defined(__MINGW64__)
ofChar* homedir = getenv("USERPROFILE");
if (homedir) {
return ofString(homedir);
}
return ofT("");
#else
#ifdef UNICODE_OFSTR
auto err = _wdupenv_s(&value, &len, ofT("USERPROFILE"));
#else
@ -85,6 +95,7 @@ ofString COfPath::get_home()
} else {
return ofT("");
}
#endif
#else
ofChar* homedir = getenv("HOME");
if (homedir) {

View File

@ -32,7 +32,11 @@ void CMutBuffer::remove_of(int start_pos, int len)
return;
}
#ifdef _WIN32
#if defined(__MINGW32__) || defined(__MINGW64__)
auto end_pos = std::min(start_pos + len, static_cast<int>(buffer_.size()));
#else
auto end_pos = min(start_pos + len, static_cast<int>(buffer_.size()));
#endif
#else
auto end_pos = std::min(start_pos + len, static_cast<int>(buffer_.size()));
#endif