引入C++库
This commit is contained in:
6
cpp/CMakeLists.txt
Normal file
6
cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 4.1)
|
||||
project(cpp)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_library(cpp STATIC library.cpp)
|
||||
9
cpp/library.cpp
Normal file
9
cpp/library.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "library.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
extern "C" {
|
||||
void hello() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
}
|
||||
}
|
||||
7
cpp/library.h
Normal file
7
cpp/library.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef CPP_LIBRARY_H
|
||||
#define CPP_LIBRARY_H
|
||||
|
||||
extern "C" {
|
||||
void hello();
|
||||
}
|
||||
#endif // CPP_LIBRARY_H
|
||||
23
cpp/toolchain-mingw32.cmake
Normal file
23
cpp/toolchain-mingw32.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
# 目标系统 - 32位Windows
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR i686)
|
||||
|
||||
# 使用32位MinGW编译器
|
||||
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
|
||||
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
|
||||
set(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
|
||||
set(CMAKE_AR i686-w64-mingw32-ar)
|
||||
set(CMAKE_RANLIB i686-w64-mingw32-ranlib)
|
||||
|
||||
# 调整搜索路径
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
# 静态链接运行时库,避免需要额外DLL
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++ -static")
|
||||
|
||||
# 确保是32位
|
||||
set(CMAKE_C_FLAGS_INIT "-m32")
|
||||
set(CMAKE_CXX_FLAGS_INIT "-m32")
|
||||
Reference in New Issue
Block a user