简体   繁体   English

链接器命令失败,退出代码为1(使用-v查看调用)iOS错误

[英]Linker Command Failed with exit code 1 (Use -v to see invocation) iOS Error

In my application I'm using a static library named ABC.a in that library in ac file named Layout.c there is a function called init() . 在我的应用程序中,我正在使用一个名为ABC.a的静态库,该库位于ac文件Layout.c其中有一个名为init()的函数。 And I linked the library to the projects and added the .h file. 然后我将库链接到项目,并添加了.h文件。 The program is compiled without error but while linking the function its throwing the error. 程序编译时没有错误,但是在链接函数时会抛出错误。 Why? 为什么?

Info: I've added that static library in build phases also. 信息:我还在构建阶段添加了该静态库。

And the library is built for armv7, armv7s and arm64. 并且该库是为armv7,armv7s和arm64构建的。 bitcode enabled: No and Build active architectures : NO 启用位码:否,构建活动体系结构:否

Example error: 错误示例:

Undefined symbols for architecture arm64:
  "AMID_INIT(int*, int*, int)", referenced from:
      -[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
  "amid_Val(float const*, int, int*, int, unsigned int)", referenced from:
      -[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o

Please help two days gone for this. 请帮忙两天。

This is based on the fact that you mention that the .a file is generated from a c file. 这是基于您提到.a文件是从c文件生成的事实。 The linker error: 链接器错误:

  "AMID_INIT(int*, int*, int)", referenced from:
      -[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o

indicates that the AMID_INIT definition came from a C++/Objective-C++ file - this is because C files would not have information about the parameters of the routine. 表示AMID_INIT定义来自C ++ / Objective-C ++文件-这是因为C文件将没有有关例程参数的信息。

From this I was able to surmise that the library header file did not have c++ guards. 由此,我可以推测出库头文件没有c ++防护。

Three approaches in this case - wrap all imports of the library header file in the C++ code with something like: 在这种情况下的三种方法-使用类似以下的代码将所有导入的库头文件包装在C ++代码中:

extern "C" {
#import "lib.h"
}

or create a lib.hpp file, containing: 或创建一个lib.hpp文件,其中包含:

#pragma once
extern "C" {
#import "lib.h"
}

and #import 'lib.hpp' instead, or fix the lib.h file by adding the standard name mangling preventative: #import 'lib.hpp'代替,或者通过添加标准名称lib.h预防性#import 'lib.hpp'来修复lib.h文件:

… near start of lib.h: …接近lib.h的开始:

#ifdef __cplusplus
extern "C" {
#endif

… near end of lib.h: …接近lib.h的结尾:

#ifdef __cplusplus
}
#endif

This allows you to keep using the lib.h with both C and C++ compilers by declaring that all the routines offered by lib.h are exposed using C linkage, rather than C++ linkage. 通过声明lib.h提供的所有例程都是使用C链接而不是C++链接公开的,这使您可以继续将lib.hCC++编译器lib.h使用。

暂无
暂无

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

相关问题 链接器命令失败,退出代码为1(使用-v查看调用)错误? - linker command failed with exit code 1 (use -v to see invocation) error? 错误:链接器命令失败,退出代码为1(使用-v查看调用) - error: linker command failed with exit code 1 (use -v to see invocation) 错误“链接器命令失败,退出代码为1(使用-v查看调用)” - error “linker command failed with exit code 1 (use -v to see invocation)” 错误链接器命令失败,退出代码为 1(使用 -v 查看调用) - Error linker command failed with exit code 1 (use -v to see invocation) Geofire(iOS)clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) - Geofire (iOS) clang: error: linker command failed with exit code 1 (use -v to see invocation) React Native IOS build clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - React Native IOS build clang: error: linker command failed with exit code 1 (use -v to see invocation) clang:错误:链接器命令在删除AdMob后,在iOS应用程序中使用退出代码1(使用-v查看调用)失败 - clang: error: linker command failed with exit code 1 (use -v to see invocation) in iOS app after deleting AdMob Swift 2 IOS 9 = clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - Swift 2 IOS 9 = clang: error: linker command failed with exit code 1 (use -v to see invocation) Paytm集成iOS-链接器命令失败,退出代码为1(使用-v查看调用)错误 - Paytm integration iOS - linker command failed with exit code 1 (use -v to see invocation) error 无法使用boost构建iOS项目:错误:链接器命令失败,退出代码为1(使用-v查看调用) - Can't build iOS project with boost: error: linker command failed with exit code 1 (use -v to see invocation)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM