简体   繁体   中英

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. 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.

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. 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. Any suggestions? I'm rather new to C++ development with Xcode so I could be missing something glaringly obvious.

There's a couple issues that might be happening here.

First off, make certain that " x86_64 " is set in your library build settings.

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 .

#ifdef __cplusplus
extern "C" {
#endif

Doing this will allow your Objective-C code to find the non-C++-mangled symbols in your library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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