首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将锈蚀项目链接到链接到其他cmake项目的cmake项目。

将锈蚀项目链接到链接到其他cmake项目的cmake项目。
EN

Stack Overflow用户
提问于 2021-03-04 05:56:33
回答 1查看 933关注 0票数 0

我正在使用cmake编译一个CMake项目,该项目依赖并编译其他CMake项目

这是我的build.rs

代码语言:javascript
运行
复制
extern crate cmake;
use cmake::Config;

fn main() {
    let dst = Config::new("src/cpp")
        .define("COMPILE_TARGET", "DESKTOP_x86_64")
        .define("FLAVOR", "DESKTOP")
        .define("LIBOPENVPN3_NOT_BUILD_EXAMPLES", "TRUE")
        .build();

    println!("cargo:rustc-link-search=native={}", dst.display());
    println!("cargo:rustc-link-lib=static=libopenvpn3");
    println!("cargo:rustc-link-lib=dylib=stdc++");
}

这就是我的src/cpp/CMakeLists.txt如何编译libopenvpn3

代码语言:javascript
运行
复制
add_library(libopenvpn3 SHARED OpenVpnInstance.cpp)
target_link_libraries(libopenvpn3 crypto ssl lzo lz4 tins)

但是,当我使用cargo build构建时,我从所有这些库crypto ssl lzo lz4 tins获得对对象的未定义引用。

我还试着制作libopenvpn3 STATIC,这样最终的libopenvpn3将包含所有所需的库:crypto, ssl, lzo, lz4, tins,比如:add_library(libopenvpn3 STATIC OpenVpnInstance.cpp),但是我仍然会得到错误。我认为其他库(crypto, ssl, lzo, lz4, tins)只有在它们也是静态的情况下才会包含在libopenvpn3中。还是不想?

无论如何,我认为我应该重新链接到build.rs上的这些库,如下所示:

代码语言:javascript
运行
复制
println!("cargo:rustc-link-lib=dylib=openvpn");
println!("cargo:rustc-link-lib=dylib=crypto");
println!("cargo:rustc-link-lib=dylib=lzo");
println!("cargo:rustc-link-lib=dylib=lz4");
println!("cargo:rustc-link-lib=dylib=tins");

但是我不知道它们在哪里,因为它们是从CMakeLists.txt生成的,而且我不认为硬编码到生成它们的路径是个好主意。

我在这里该怎么办?

更新:

错误的例子:

代码语言:javascript
运行
复制
  /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/openvpn3/openvpn3/openvpn/openssl/util/pem.hpp:66: undefined reference to `BIO_new_mem_buf'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/openvpn3/openvpn3/openvpn/openssl/util/pem.hpp:73: undefined reference to `PEM_read_bio'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/openvpn3/openvpn3/openvpn/openssl/util/pem.hpp:91: undefined reference to `CRYPTO_free'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/openvpn3/openvpn3/openvpn/openssl/util/pem.hpp:92: undefined reference to `CRYPTO_free'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/openvpn3/openvpn3/openvpn/openssl/util/pem.hpp:93: undefined reference to `CRYPTO_free'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/openvpn3/openvpn3/openvpn/openssl/util/pem.hpp:95: undefined reference to `BIO_free'
  /usr/bin/ld: /home/dev/orwell/lab/hyper_vpn/target/debug/deps/liblibopenvpn3-7498dcb6c355a9d6.rlib(OpenVpnInstance.cpp.o): in function `SimplePacketCrafter::replaceSourceAddressIpv4(unsigned char*, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
  /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/SimplePacketCrafter.h:117: undefined reference to `Tins::IP::IP(unsigned char const*, unsigned int)'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/SimplePacketCrafter.h:118: undefined reference to `Tins::IPv4Address::IPv4Address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/SimplePacketCrafter.h:118: undefined reference to `Tins::IP::src_addr(Tins::IPv4Address)'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/SimplePacketCrafter.h:119: undefined reference to `Tins::PDU::serialize()'
  /usr/bin/ld: /home/dev/orwell/lab/hyper_vpn/target/debug/deps/liblibopenvpn3-7498dcb6c355a9d6.rlib(OpenVpnInstance.cpp.o): in function `Tins::IP::~IP()':
  /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/libtins/include/tins/ip.h:63: undefined reference to `vtable for Tins::IP'
  /usr/bin/ld: /home/dev/orwell/liborwell_rust/src/libopenvpn3/src/cpp/libtins/include/tins/ip.h:63: undefined reference to `Tins::PDU::~PDU()'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-05 01:09:38

在CMakeLists.txt上,我在做:

代码语言:javascript
运行
复制
install(TARGETS libopenvpn3 DESTINATION .)

但后来我做了

代码语言:javascript
运行
复制
install(TARGETS libopenvpn3 crypto ssl lzo lz4 tins DESTINATION .)

所以它安装了所需的所有库。

然后,这个build.rs工作:

代码语言:javascript
运行
复制
extern crate cmake;
use cmake::Config;

fn main() {
    let dst = Config::new("src/cpp")
        .define("COMPILE_TARGET", "DESKTOP_x86_64")
        .define("FLAVOR", "DESKTOP")
        .define("LIBOPENVPN3_NOT_BUILD_EXAMPLES", "TRUE")
        .build();

    println!("cargo:rustc-link-search=native={}", dst.display());
    println!("cargo:rustc-link-lib=dylib=stdc++");
    println!("cargo:rustc-link-lib=static=libopenvpn3");
    println!("cargo:rustc-link-lib=static=crypto");
    println!("cargo:rustc-link-lib=static=lzo");
    println!("cargo:rustc-link-lib=static=lz4");
    println!("cargo:rustc-link-lib=static=tins");
    println!("cargo:rustc-link-lib=static=ssl");
}

我不知道,但是,为什么我要把他们再次联系在铁锈。它们应该包含在libopenvpn3中,因为它们是静态的,不是吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66469387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档