链接器命令失败,退出代码为 1(使用 -v 查看调用)iOS 错误
Linker Command Failed with exit code 1 (Use -v to see invocation) iOS Error
在我的应用程序中,我在名为 Layout.c
的 c 文件中使用了一个名为 ABC.a
的静态库,其中有一个名为 init()
的函数。我将库链接到项目并添加了 .h
文件。该程序编译无误,但在链接函数时抛出错误。为什么?
信息:我也在构建阶段添加了静态库。
并且该库是为 armv7、armv7s 和 arm64 构建的。启用位码:否和构建活动架构:否
示例错误:
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
两天过去了,请帮忙。
这是基于您提到 .a
文件是从 c
文件生成的事实。链接器错误:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
表示 AMID_INIT
定义来自 C++/Objective-C++ 文件 - 这是因为 C
文件没有关于例程参数的信息。
据此我推测库头文件没有 c++ 保护。
本例中的三种方法 - 将库头文件的所有导入包装在 C++ 代码中,例如:
extern "C" {
#import "lib.h"
}
或创建一个 lib.hpp
文件,其中包含:
#pragma once
extern "C" {
#import "lib.h"
}
和 #import 'lib.hpp'
,或者通过添加标准名称修改预防措施来修复 lib.h
文件:
…接近 lib.h 的开始:
#ifdef __cplusplus
extern "C" {
#endif
…lib.h 接近尾声:
#ifdef __cplusplus
}
#endif
通过声明 lib.h
提供的所有例程都使用 [=18 公开,这允许您继续将 lib.h
与 C
和 C++
编译器一起使用=]联动,而不是C++
联动。
在我的应用程序中,我在名为 Layout.c
的 c 文件中使用了一个名为 ABC.a
的静态库,其中有一个名为 init()
的函数。我将库链接到项目并添加了 .h
文件。该程序编译无误,但在链接函数时抛出错误。为什么?
信息:我也在构建阶段添加了静态库。
并且该库是为 armv7、armv7s 和 arm64 构建的。启用位码:否和构建活动架构:否
示例错误:
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
两天过去了,请帮忙。
这是基于您提到 .a
文件是从 c
文件生成的事实。链接器错误:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
表示 AMID_INIT
定义来自 C++/Objective-C++ 文件 - 这是因为 C
文件没有关于例程参数的信息。
据此我推测库头文件没有 c++ 保护。
本例中的三种方法 - 将库头文件的所有导入包装在 C++ 代码中,例如:
extern "C" {
#import "lib.h"
}
或创建一个 lib.hpp
文件,其中包含:
#pragma once
extern "C" {
#import "lib.h"
}
和 #import 'lib.hpp'
,或者通过添加标准名称修改预防措施来修复 lib.h
文件:
…接近 lib.h 的开始:
#ifdef __cplusplus
extern "C" {
#endif
…lib.h 接近尾声:
#ifdef __cplusplus
}
#endif
通过声明 lib.h
提供的所有例程都使用 [=18 公开,这允许您继续将 lib.h
与 C
和 C++
编译器一起使用=]联动,而不是C++
联动。