我正在使用cmake编译一个CMake项目,该项目依赖并编译其他CMake项目
这是我的build.rs
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
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
上的这些库,如下所示:
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
生成的,而且我不认为硬编码到生成它们的路径是个好主意。
我在这里该怎么办?
更新:
错误的例子:
/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()'
发布于 2021-03-05 01:09:38
在CMakeLists.txt上,我在做:
install(TARGETS libopenvpn3 DESTINATION .)
但后来我做了
install(TARGETS libopenvpn3 crypto ssl lzo lz4 tins DESTINATION .)
所以它安装了所需的所有库。
然后,这个build.rs
工作:
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中,因为它们是静态的,不是吗?
https://stackoverflow.com/questions/66469387
复制相似问题