Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 78cb4f3

Browse files
committed
修复无法编译成静态库的问题;
1 parent c624e48 commit 78cb4f3

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ target_link_libraries(${PROJECT_NAME} nlohmann_json nlohmann_json::nlohmann_json
4848
target_link_libraries(${PROJECT_NAME} CURL::libcurl)
4949
#target_link_libraries(${PROJECT_NAME} INTERFACE ${BOOST_LIBRARIES})
5050

51-
if(MSVC)
52-
if(BUILD_SHARED_LIBS)
53-
target_compile_definitions(${PROJECT_NAME} PRIVATE WIN_EXPORT)
54-
target_compile_definitions(${PROJECT_NAME} PRIVATE SHARED_LIB)
51+
if(BUILD_SHARED_LIBS)
52+
if(WIN32)
53+
target_compile_definitions(${PROJECT_NAME} PRIVATE WIN_EXPORT)
5554
endif()
56-
endif(MSVC)
55+
else()
56+
target_compile_definitions(${PROJECT_NAME} PRIVATE MIRAICPP_STATICLIB)
57+
endif()
58+
5759

5860

5961
option(MIRAI_CPP_BUILD_EXAMPLES "Build examples" ON)

examples/RepeatMessage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <iostream>
2+
// 使用静态库必须要在引入 mirai.h 前定义这个宏
3+
#define MIRAICPP_STATICLIB
24
#include <mirai.h>
35

46
int main()

include/defs/qq_types.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <exception>
66
#include "serializable.hpp"
7+
#include "exported.h"
78

89
namespace Cyan
910
{
@@ -107,7 +108,7 @@ namespace Cyan
107108
};
108109

109110
// 预先声明 MiraiBot 类
110-
class MiraiBot;
111+
class EXPORTED MiraiBot;
111112

112113
}
113114

include/exported.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22

3-
// Define EXPORTED for any platform
4-
#if defined(_WIN32)
5-
# if defined(WIN_EXPORT) && defined(SHARED_LIB)
3+
#if defined(MIRAICPP_STATICLIB)
4+
# define EXPORTED
5+
#elif defined(_WIN32)
6+
# if defined(WIN_EXPORT)
67
# define EXPORTED __declspec( dllexport )
78
# else
89
# define EXPORTED __declspec( dllimport )

0 commit comments

Comments
 (0)