简体   繁体   English

与我自己的静态库链接的问题

[英]Issues Linking with my own static library

I'm working on a project that involves building three different executables. 我正在从事一个涉及构建三个不同可执行文件的项目。 Rather than creating three separate Xcode projects, I figured I would keep all of the sources in one project and just use different targets for the binaries. 我认为没有创建三个单独的Xcode项目,而是将所有源代码保留在一个项目中,并对二进制文件使用不同的目标。 They all happen to require the same set of source files (an encryption library written in C) and I've added a static library target for them and it seems to be able to compile them just fine. 它们碰巧都需要相同的源文件集(用C编写的加密库),并且我为它们添加了一个静态库目标,并且似乎能够很好地对其进行编译。

My issue is that I'm working on one of the executables and in trying to link with that library, I keep getting the "ld: symbol(s) not found for architecture x86_64" error. 我的问题是,我正在处理其中一个可执行文件,并尝试与该库链接时,我不断收到“ ld:架构x86_64找不到符号”错误。 I've already compiled the library and added it to "Target Dependencies", "Link Binary with Libraries", and "Copy Headers" (or the relevant header anyway) in the build phases settings for the target in question. 我已经编译了该库,并将其添加到有关目标的构建阶段设置中的“目标依赖项”,“使用库链接二进制文件”和“复制标题”(或无论如何相关标题)中。 Xcode lets me include the library (just "encryption.h") but again the build fails. Xcode让我包括该库(只是“ encryption.h”),但是构建再次失败。 Any suggestions? 有什么建议么? I'm rather new to C++ development with Xcode so I could be missing something glaringly obvious. 我对使用Xcode进行C ++开发相当陌生,因此我可能会错过一些显而易见的东西。

There's a couple issues that might be happening here. 这里可能会发生几个问题。

First off, make certain that " x86_64 " is set in your library build settings. 首先,请确保在库构建设置中设置了“ x86_64 ”。

Your build settings should look something like this: 您的构建设置应如下所示:

确保设置了64位

Secondly, if you are trying to include your C++ library in an Objective-C application, you need to add some extra "magic" to your library's .h header files . 其次,如果要在Objective-C应用程序中包括C ++库,则需要在库的.h头文件中添加一些额外的“魔术”

#ifdef __cplusplus
extern "C" {
#endif

Doing this will allow your Objective-C code to find the non-C++-mangled symbols in your library. 这样做可以使您的Objective-C代码在您的库中查找非C ++混杂的符号。

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

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