笔记
This commit is contained in:
19
笔记/C++.md
Normal file
19
笔记/C++.md
Normal file
@ -0,0 +1,19 @@
|
||||
## 基础配置
|
||||
#### 1.编码及输出
|
||||
```cpp
|
||||
#if WIN32
|
||||
system("chcp 65001");
|
||||
setbuf(stdout, NULL);//解决Clion内置控制台debug时不显示打印的问题
|
||||
#endif
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
## 字符串检查函数
|
||||
![[Pasted image 20250213092216.png]]
|
||||
|
||||
---
|
||||
## 异常
|
||||
![[Pasted image 20250213171955.png]]
|
||||
|
||||
---
|
||||
61
笔记/CMakeLists-Qt.md
Normal file
61
笔记/CMakeLists-Qt.md
Normal file
@ -0,0 +1,61 @@
|
||||
```python
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(MyAppClient)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
|
||||
set(CMAKE_PREFIX_PATH "C:/Path/QT15/5.15.2/mingw81_64")
|
||||
|
||||
find_package(Qt5 COMPONENTS
|
||||
Core
|
||||
Gui
|
||||
Widgets
|
||||
REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
#1. **检查平台和工具链文件**:如果当前平台是Windows且未定义`CMAKE_TOOLCHAIN_FILE`,则执行后续操作。
|
||||
if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
#2. **设置调试后缀**:如果使用的是MSVC编译器且构建类型为Debug,则设置`DEBUG_SUFFIX`为"d",否则为空。
|
||||
set(DEBUG_SUFFIX)
|
||||
if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||
set(DEBUG_SUFFIX "d")
|
||||
endif ()
|
||||
#3. **确定Qt安装路径**:尝试找到Qt的安装路径,如果默认路径不存在,则向上查找两级目录。
|
||||
set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
|
||||
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
|
||||
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
|
||||
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
|
||||
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
|
||||
endif ()
|
||||
endif ()
|
||||
#4. **复制qwindows.dll**:如果存在`qwindows${DEBUG_SUFFIX}.dll`,则在项目构建完成后将其复制到目标目录的`plugins/platforms/`子目录中。
|
||||
if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
|
||||
endif ()
|
||||
#5. **复制Qt库文件**:对于每个指定的Qt库,在项目构建完成后将其对应的DLL文件复制到目标目录。
|
||||
foreach (QT_LIB Core Widgets Gui Network)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
|
||||
endforeach (QT_LIB)
|
||||
endif ()
|
||||
|
||||
#自动复制配置文件
|
||||
#file(COPY ${CMAKE_SOURCE_DIR}/ DESTINATION ${CMAKE_BINARY_DIR})
|
||||
```
|
||||
75
笔记/CMakeLists.md
Normal file
75
笔记/CMakeLists.md
Normal file
@ -0,0 +1,75 @@
|
||||
```python
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(Ant)
|
||||
|
||||
# 定义默认编译器
|
||||
set(DEFAULT_BYL "dg")
|
||||
# 检查自定义编译器参数
|
||||
if (NOT DEFINED BYL)
|
||||
set(BYL ${DEFAULT_BYL})
|
||||
endif ()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
if (BYL STREQUAL "jr")#菁蓉
|
||||
set(CMAKE_C_COMPILER "/opt/jr-gcc-aarch64-7.5.0/bin/aarch64-linux-gnu-gcc")
|
||||
set(CMAKE_CXX_COMPILER "/opt/jr-gcc-aarch64-7.5.0/bin/aarch64-linux-gnu-g++")
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build.${PROJECT_NAME}/lib/jr)
|
||||
elseif (BYL STREQUAL "lj")#两江
|
||||
set(CMAKE_C_COMPILER "/opt/lj-gcc-aarch64-10.3/bin/aarch64-none-linux-gnu-gcc")
|
||||
set(CMAKE_CXX_COMPILER "/opt/lj-gcc-aarch64-10.3/bin/aarch64-none-linux-gnu-g++")
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build.${PROJECT_NAME}/lib/lj)
|
||||
elseif (BYL STREQUAL "dg")#典格
|
||||
set(CMAKE_C_COMPILER "/opt/dg-gcc-aarch64-7.4.1/bin/aarch64-linux-gnu-gcc")
|
||||
set(CMAKE_CXX_COMPILER "/opt/dg-gcc-aarch64-7.4.1/bin/aarch64-linux-gnu-g++")
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build.${PROJECT_NAME}/lib/dg)
|
||||
endif ()
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build.${PROJECT_NAME}/lib/mingw810_64)
|
||||
endif ()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
#导入库
|
||||
include_directories(build.mbf/include build.mpcr/include)
|
||||
link_libraries(mpcr mbf)
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
link_directories(build.mpcr/lib/mingw810_64 build.mbf/lib/mingw810_64)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
if (BYL STREQUAL "jr")#菁蓉
|
||||
link_directories(build.mpcr/lib/jr build.mbf/lib/jr)
|
||||
elseif (BYL STREQUAL "lj")#两江
|
||||
link_directories(build.mpcr/lib/lj build.mbf/lib/lj)
|
||||
elseif (BYL STREQUAL "dg")#典格
|
||||
link_directories(build.mpcr/lib/dg build.mbf/lib/dg)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
include_directories(.)
|
||||
aux_source_directory(. SRC_lIST)
|
||||
|
||||
#add_library(Ant STATIC ${SRC_lIST})
|
||||
add_library(Ant SHARED ${SRC_lIST})
|
||||
#链接系统库
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(${PROJECT_NAME} ws2_32)
|
||||
endif ()
|
||||
|
||||
# 复制头文件
|
||||
# 设置源文件夹和目标文件夹
|
||||
set(SOURCE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
set(TARGET_DIR "${CMAKE_SOURCE_DIR}/build.${PROJECT_NAME}/include")
|
||||
# 确保目标文件夹存在
|
||||
file(MAKE_DIRECTORY ${TARGET_DIR})
|
||||
# 复制 include 文件夹下的所有文件到 build.${PROJECT_NAME}/include 目录
|
||||
file(GLOB INCLUDE_FILES "${SOURCE_DIR}/*.h")
|
||||
file(COPY ${INCLUDE_FILES} DESTINATION ${TARGET_DIR})
|
||||
```
|
||||
---
|
||||
|
||||
``` bash
|
||||
# 交叉编译
|
||||
cmake .. \
|
||||
-DCMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabihf-gcc \
|
||||
-DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ \
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
7
笔记/GitHub.md
Normal file
7
笔记/GitHub.md
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
[acwj](https://github.com/DoctorWkt/acwj)
|
||||
[Tinyhttpd](https://github.com/EZLippi/Tinyhttpd)
|
||||
[TinyWebServer](https://github.com/qinguoyi/TinyWebServer)
|
||||
[CPlusPlusThings](https://github.com/Light-City/CPlusPlusThings)
|
||||
[C-Plus-Plus](https://github.com/TheAlgorithms/C-Plus-Plus)
|
||||
[推出一系列重磅项目,带大家实战学习C++,配合本开源项目学习,成长飞快!](https://github.com/Light-City/CPlusPlusThings/blob/master/proj/README.md)
|
||||
16
笔记/QT.md
Normal file
16
笔记/QT.md
Normal file
@ -0,0 +1,16 @@
|
||||
在Clion环境变量中添加,以显示qDebug的输出
|
||||
```
|
||||
QT_ASSUME_STDERR_HAS_CONSOLE=1
|
||||
```
|
||||
|
||||
在对应目录下执行以生成所需库
|
||||
```
|
||||
windeployqt ${NAME}
|
||||
```
|
||||
|
||||
---
|
||||
qDebug显示中文
|
||||
```cpp
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
```
|
||||
Reference in New Issue
Block a user