C++ 链接C++;来自Objective-C的库(libtorrent)

C++ 链接C++;来自Objective-C的库(libtorrent),c++,objective-c,xcode,linker-errors,mixing,C++,Objective C,Xcode,Linker Errors,Mixing,我试图使用Xcode 5.0 Objective-C项目中的libtorrent库,但没有成功 我使用LLVM5.0从源代码中构建了Boost1.54和libtorrent rasterbar(最新版本),没有问题。另外,通过MacPorts,我获得了pkg配置,以获得libtorrent rasterbar库的正确cflags。根据我的生成设置,pkgconfig libs和cflags的输出为: -DTORRENT_USE_OPENSSL -DWITH_SHIPPED_GEOIP

我试图使用Xcode 5.0 Objective-C项目中的libtorrent库,但没有成功

我使用LLVM5.0从源代码中构建了Boost1.54和libtorrent rasterbar(最新版本),没有问题。另外,通过MacPorts,我获得了pkg配置,以获得libtorrent rasterbar库的正确cflags。根据我的生成设置,pkgconfig libs和cflags的输出为:

      -DTORRENT_USE_OPENSSL -DWITH_SHIPPED_GEOIP_H 
-DBOOST_ASIO_HASH_MAP_BUCKETS=1021 
    -DBOOST_EXCEPTION_DISABLE -DBOOST_ASIO_ENABLE_CANCELIO 
    -DBOOST_ASIO_DYN_LINK -DTORRENT_LINKING_SHARED -I/usr/local/include 
    -I/usr/local/include/libtorrent 

    -L/usr/local/lib -ltorrent-rasterbar 
当然,我将这些参数添加到Xcode“链接器标志”和“C/C++标志”设置中

不幸的是,我无法使调用的函数正确链接。这是我在testclass.cpp文件中编写的示例类:

#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/create_torrent.hpp"

void testclass::addFilesFromPath(const char* path)
{
    libtorrent::file_storage fs;
    libtorrent::add_files(fs, path);
}
试图从createpackage.mm文件调用:

testclass* pPackage = new testclass();
testclass->addFilesFromPath([_sessionDir UTF8String]);
链接器找不到符号,输出为:

架构x86_64的未定义符号:
“libtorrent::parent_path(std::_1::basic_string,std::_1::allocator>const&”), 引用自: libtorrent::add_files(libtorrent::file_storage&,std::u 1::basic_string, std::_1::分配器>常量(,无符号整数) createpackage.o
“libtorrent::detail::add_files_impl(libtorrent::file_存储&,”, std::_1::基本字符串, std::uu 1::分配器>常量&,std:u 1::基本字符串,std::u 1::分配器>常量&, boost::function,std::\uu 1::allocator>)>,未签名 int)”,引用自: libtorrent::add_files(libtorrent::file_storage&,std::u 1::basic_string, std::_1::分配器>常量(,无符号整数) createpackage.o
“libtorrent::complete(std::_1::basic_string,std::_1::allocator>const&”), 引用自: libtorrent::add_files(libtorrent::file_storage&,std::u 1::basic_string, std::_1::分配器>常量(,无符号整数) createpackage.o
“libtorrent::filename(std::_1::basic_string,std::_1::allocator>const&”), 引用自: libtorrent::add_files(libtorrent::file_storage&,std::u 1::basic_string, std::_1::分配器>常量(,无符号整数) createpackage.o ld:找不到架构x86_64的符号 叮当声:错误:链接器命令失败,退出代码为1(使用-v查看 调用)

我很困惑。已检查libtorrent光栅条体系结构是否为x86_64。另外,boost的构建还可以。我对C++/Objuty- C代码混合方法是新的。 谢谢

编辑1:

我已经求助于最低限度的样本。创建了以下CPP文件:

#include "libtorrent/file.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/create_torrent.hpp"

int main()
{
    libtorrent::file_storage fs;
    libtorrent::add_files(fs, ".");
}
在命令行中,尝试:

c++ test.cpp $(pkg-config /usr/local/lib/pkgconfig/libtorrent-rasterbar.pc --cflags --libs) -lboost_system

构建成功。所以我想知道如何将所有pkg配置数据放入OSX中正确的目标配置中。

最后,问题解决了

让我们通过比较生成的对象文件和libtorrent库中包含的符号来检查符号

nm createpackage.o|grep 'add_files'
                 U __ZN10libtorrent6detail14add_files_implERNS_12file_storageERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEESB_N5boost8functionIFbS9_EEEj
00000000000002a0 S __ZN10libtorrent9add_filesERNS_12file_storageERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEj
00000000000018e0 S __ZN10libtorrent9add_filesERNS_12file_storageERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEj.eh
与之相比:

$ nm libtorrent-rasterbar.a | grep 'add_files'
00000000000002f0 T __ZN10libtorrent6detail14add_files_implERNS_12file_storageERKSsS4_N5boost8functionIFbSsEEEj
0000000000006e68 S __ZN10libtorrent6detail14add_files_implERNS_12file_storageERKSsS4_N5boost8functionIFbSsEEEj.eh
<> P>>输出的不同之处在于,我在LGTRAM中使用LLVTRAM标准的C++库,而LIGBTRAN是用GCC STDLIB编译的,这是不同符号引用字符特征、基本字符串等的原因。

>,XCube构建设置>标准C++库到LISTSTDC + +的更改解决了问题。