Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C+编译错误+;Swift项目中包含的静态库 < >我创建了一个静态库,其中包含以下C++文件: //TestClass.h File: #ifndef TESTCLASS_H_ #define TESTCLASS_H_ using namespace std; #include <string> class TestClass { public: TestClass(); virtual ~TestClass(); int sum(int x, int y) const; string chain(const string& x, const string& y) const; }; #endif /* TESTCLASS_H_ */ //TestClass.cpp File: #include<iostream> #include "TestClass.h" TestClass::TestClass() { } TestClass::~TestClass() { } int TestClass::sum(int x, int y) const { return x+y; } //Test.cpp File: string TestClass::chain(const string& x, const string& y) const { return x+y; } int main(int argc, char* argv[]) { TestClass test; cout << "1+1 = " << test.sum(1,1) << endl; cout << "Dog+Cat = " << test.chain("Dog","Cat") << endl; return 0; }_C++_Ios_Objective C_Swift_Static Libraries - Fatal编程技术网

使用C+编译错误+;Swift项目中包含的静态库 < >我创建了一个静态库,其中包含以下C++文件: //TestClass.h File: #ifndef TESTCLASS_H_ #define TESTCLASS_H_ using namespace std; #include <string> class TestClass { public: TestClass(); virtual ~TestClass(); int sum(int x, int y) const; string chain(const string& x, const string& y) const; }; #endif /* TESTCLASS_H_ */ //TestClass.cpp File: #include<iostream> #include "TestClass.h" TestClass::TestClass() { } TestClass::~TestClass() { } int TestClass::sum(int x, int y) const { return x+y; } //Test.cpp File: string TestClass::chain(const string& x, const string& y) const { return x+y; } int main(int argc, char* argv[]) { TestClass test; cout << "1+1 = " << test.sum(1,1) << endl; cout << "Dog+Cat = " << test.chain("Dog","Cat") << endl; return 0; }

使用C+编译错误+;Swift项目中包含的静态库 < >我创建了一个静态库,其中包含以下C++文件: //TestClass.h File: #ifndef TESTCLASS_H_ #define TESTCLASS_H_ using namespace std; #include <string> class TestClass { public: TestClass(); virtual ~TestClass(); int sum(int x, int y) const; string chain(const string& x, const string& y) const; }; #endif /* TESTCLASS_H_ */ //TestClass.cpp File: #include<iostream> #include "TestClass.h" TestClass::TestClass() { } TestClass::~TestClass() { } int TestClass::sum(int x, int y) const { return x+y; } //Test.cpp File: string TestClass::chain(const string& x, const string& y) const { return x+y; } int main(int argc, char* argv[]) { TestClass test; cout << "1+1 = " << test.sum(1,1) << endl; cout << "Dog+Cat = " << test.chain("Dog","Cat") << endl; return 0; },c++,ios,objective-c,swift,static-libraries,C++,Ios,Objective C,Swift,Static Libraries,“编译源代码”中的标志和 “Info.plist其他预处理器标志”中的标志 当我链接我刚创建的静态库(带有Objective C包装文件)时,我收到以下4个错误,我不知道如何修复它: Undefined symbols for architecture arm64: "vtable for __cxxabiv1::__class_type_info", referenced from: typeinfo for TestClass in libPredictionComplete

“编译源代码”中的标志和

“Info.plist其他预处理器标志”中的标志

当我链接我刚创建的静态库(带有Objective C包装文件)时,我收到以下4个错误,我不知道如何修复它:

Undefined symbols for architecture arm64:
  "vtable for __cxxabiv1::__class_type_info", referenced from:
      typeinfo for TestClass in libPredictionComplete.a(TestClass.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "operator delete(void*)", referenced from:
      TestClass::~TestClass() in libPredictionComplete.a(TestClass.o)
  "___gxx_personality_v0", referenced from:
      -[CppObject init] in libPredictionComplete.a(CppObject.o)
      -[PredictionComplete init] in libPredictionComplete.a(PredictionComplete.o)
      -[PredictionComplete chain::] in libPredictionComplete.a(PredictionComplete.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我很感激你能给我一些建议。


你应该有-xc++,而不是Objul-C++。但是,如果您命名C++ SoCe*.CP../P>< P>,我不需要指定这个标志。当我在SWIFT项目本身中添加“-LSTD+++”编译标志到“其他链接标志”部分时,它就固定了,而不仅仅是在带有C++文件的静态库项目中。P> >根据我的经验,当顶级项目中没有C++源时,XCODEL将无法链接到C++库。这在纯Obj-C项目中也是如此,以及在链接C++代码的静态库时也是如此。

一个较具侵入性的解决方案是简单地在项目中包含一个空C++源文件(这里是一个),它被编译成了最终的.app二进制文件。它实际上不发射任何代码,但是它使XCODEL知道存在C++代码,导致C++库被链接到。p>


此解决方案的优点是,它避免了修改Xcode中的项目设置,因此无需添加特殊的链接器标志来强制Xcode执行正确的操作。

-lstdc++
应位于“其他链接器标志”(或
其他链接器标志
)中。请注意,只有当“C++标准库”设置为
libstdc++
时,这才有效


还注意到,如果目标中有任何C++源代码,XCORE通常是足够聪明的,包括标准C++库,所以不需要明确地链接到<代码> LBSTDC++< /COD>或 LBC++。可能是因为源文件的扩展名为*.cpp,这在我放入Swift项目(而不仅仅是库)时修复了它。引用的

-lstdc++
就是您需要的!
-lstdc++
Undefined symbols for architecture arm64:
  "vtable for __cxxabiv1::__class_type_info", referenced from:
      typeinfo for TestClass in libPredictionComplete.a(TestClass.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "operator delete(void*)", referenced from:
      TestClass::~TestClass() in libPredictionComplete.a(TestClass.o)
  "___gxx_personality_v0", referenced from:
      -[CppObject init] in libPredictionComplete.a(CppObject.o)
      -[PredictionComplete init] in libPredictionComplete.a(PredictionComplete.o)
      -[PredictionComplete chain::] in libPredictionComplete.a(PredictionComplete.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)