# cxx_demo **Repository Path**: zhangxinyuhahaha/cxx_demo ## Basic Information - **Project Name**: cxx_demo - **Description**: No description available - **Primary Language**: Rust - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-03-15 - **Last Updated**: 2021-03-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 我要实现如下功能: 我在Rust中 使用cpp的一个模块"handle2", 这个"handle2" 中需要动态链接库"handle1"的一些函数, 但是我尝试好久, 在使用 ffi::handle2(123) 的时候, 一直出现异常 "undefined reference to `handle1'" ## 如果仅有include文件夹中的文件, 我们没有"handle1"源码的情况下, 如何在rust中通过"cxx"使用 "handle2" 呢? ## build.rs > 这里做的就是编译"handle1" 并copy一些文件到include 文件夹, 模拟环境 ``` shell cd {:?} && cd ../handle1 && cmake . && make && rm -r CMakeFiles && rm cmake_install.cmake && rm CMakeCache.txt && rm Makefile && cp ./handle1.h {:?}/include/handle1.h && cp ./libhandle1.so {:?}/include/libhandle1.so && cd ../handle2 && cp ./handle2.h {:?}/include/handle2.h && cp ./handle2.cpp {:?}/include/handle2.cpp ``` ``` shell ├── handle1 │   ├── CMakeLists.txt │   ├── handle1.cpp │   ├── handle1.h │   └── libhandle1.so ├── handle2 │   ├── CMakeLists.txt │   ├── handle2.cpp │   └── handle2.h ├── README.en.md ├── README.md └── rust_part ├── build.rs ├── Cargo.toml ├── include │   ├── handle1.h │   ├── handle2.cpp │   ├── handle2.h │   └── libhandle1.so └── src └── main.rs ```