简体   繁体   English

如何链接使用C ++向量的iOS静态库,以便在Delphi XE7中使用?

[英]How to link an iOS static library that uses C++ vectors, for use in Delphi XE7?

I build a static library in xCode that I must use in Delphi XE7 for the iOS platform. 我在xCode中构建了一个静态库,我必须在Delphi XE7中为iOS平台使用它。 The library is written in C++ and uses vectors. 该库是用C ++编写的,并使用向量。 The functions I need to use in Delphi are all pure C functions (export "C"). 我需要在Delphi中使用的函数都是纯C函数(导出“C”)。 They are recognized by the linker, but there is one linking error I can't get rid of : 它们被链接器识别,但有一个链接错误,我无法摆脱:

"  Undefined symbols for architecture armv7:    __ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv", referenced from:..."

To distinguish this problem from other possible issues, I made a simple project, that uses vectors and got the same problem. 为了将这个问题与其他可能的问题区分开来,我做了一个简单的项目,它使用向量并得到了同样的问题。 If I remove the use of vectors in that simple project, all goes well, linking and running on my iPad through a FireMonkey project in Delphi with iOS target. 如果我在这个简单的项目中删除了向量的使用,一切顺利,通过带有iOS目标的Delphi中的FireMonkey项目在我的iPad上链接和运行。

I also built a simple application as an xCode project, using the same C++ library. 我还使用相同的C ++库将一个简单的应用程序构建为xCode项目。 The project links and runs in xCode without doing anything special about it (I guess xCode links the application against the correct C++ library automatically). 该项目链接并在xCode中运行,而没有做任何特殊的事情(我猜xCode会自动将应用程序与正确的C ++库链接)。

I tried to add libc++.dylib and/or libstdc++.dylib to the xCode project, but there is the warning that these are dynamic libraries so they are ignored when linking the static library. 我试图将libc ++。dylib和/或libstdc ++。dylib添加到xCode项目中,但是警告这些是动态库,因此在链接静态库时会忽略它们。 I tried to locate a static version of these libraries but couldn't find them anywhere (do they exist ?). 我试图找到这些库的静态版本,但无法在任何地方找到它们(它们是否存在?)。

So my question is : how can I add the C++ library to the static library I build with xCode, so that XE7 will not complain about this ? 所以我的问题是:如何将C ++库添加到我使用xCode构建的静态库中,以便XE7不会抱怨这个?

Edited : I get the following xCode command line for the last file compiled (I do not see any command line with the Build step) : 编辑:我为最后编译的文件获取以下xCode命令行(我没有看到任何带有Build步骤的命令行):

"CompileC /Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/Objects-normal/arm64/Kiss_Wrapper.o Sources/Kiss_Wrapper.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/admin/Documents/iOSTartini/TartiniLib
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch arm64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++11 -stdlib=libc++ -fmodules -fmodules-cache-path=/Users/admin/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/admin/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DUSE_KISS=1 -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/TartiniLib-generated-files.hmap -I/Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/TartiniLib-own-target-headers.hmap -I/Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/TartiniLib-all-target-headers.hmap -iquote /Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/TartiniLib-project-headers.hmap -I/Users/admin/Documents/xCode\ Derived\ Data/Debug-iphoneos/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/DerivedSources/arm64 -I/Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/DerivedSources -F/Users/admin/Documents/xCode\ Derived\ Data/Debug-iphoneos -MMD -MT dependencies -MF /Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/Objects-normal/arm64/Kiss_Wrapper.d --serialize-diagnostics /Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/Objects-normal/arm64/Kiss_Wrapper.dia -c /Users/admin/Documents/iOSTartini/TartiniLib/Sources/Kiss_Wrapper.cpp -o /Users/admin/Documents/xCode\ Derived\ Data/TartiniLib.build/Debug-iphoneos/TartiniLib.build/Objects-normal/arm64/Kiss_Wrapper.o"

You need to use a symbol from the lib in your Delphi code, just so the linker knows about the lib. 您需要在Delphi代码中使用lib中的符号,这样链接器才能知道lib。 You can add this to one of the Delphi units, for example: 您可以将其添加到其中一个Delphi单元,例如:

function nothrow: pointer; 函数nothrow:指针; cdecl; CDECL; external '/usr/lib/libstdc++.dylib'; 外部'/usr/lib/libstdc++.dylib';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM