PDA

View Full Version : Using SecKeychainAddGenericPassword




Ben.Key
May 29, 2011, 09:39 PM
Hello,

I have a question about using SecKeychainAddGenericPassword and related functions in the Keychain Services API. I am attempting to build the example programs provided on the Keychain Services Tasks for Mac OS X web page but I am getting several linker errors due to undefined symbols including CFRelease, SecKeychainItemFreeContent, SecKeychainFindGenericPassword, SecKeychainItemModifyAttributesAndData, and SecKeychainAddGenericPassword. What library do I need to link to in order to resolve these errors? The Keychain Services Tasks for Mac OS X and Keychain Services Reference web pages do not appear to provide an answer to this question.



jiminaus
May 29, 2011, 10:30 PM
CFRelease is CoreFoundation.framework. The others are in Security.framework, I think. I'm away from my beloved Mac so can't confirm this.

chown33
May 30, 2011, 12:21 AM
First hit searching for SecKeychainAddGenericPassword site:developer.apple.com is this:
http://developer.apple.com/library/mac/#documentation/Security/Reference/keychainservices/Reference/reference.html

Top of the page says:
Framework Security/Security.h


There's a link embedded on the first word Security, leads to this:
http://developer.apple.com/library/mac/#documentation/Security/Reference/SecurityFrameworkReference/_index.html%23//apple_ref/doc/uid/TP40004330

jiminaus
May 30, 2011, 01:14 AM
First hit searching for SecKeychainAddGenericPassword site:developer.apple.com is this:
http://developer.apple.com/library/mac/#documentation/Security/Reference/keychainservices/Reference/reference.html

Top of the page says:
Framework Security/Security.h


There's a link embedded on the first word Security, leads to this:
http://developer.apple.com/library/mac/#documentation/Security/Reference/SecurityFrameworkReference/_index.html%23//apple_ref/doc/uid/TP40004330


Nice one chown33. I'd never acknowledged there was link there. I'd always just gone with the convention to determine which framework I was dealing with.

Ben.Key
May 30, 2011, 02:11 AM
Hello,

I would like to thank jiminaus and chown33 for their quick replies. But I am not certain how to link against the Security.framework.

I am not using XCode. I am attempting to build using Make because that is what I am familiar with and that is what a project my code will eventually need to go into uses and I am not certain what linker option to use to tell it to link against the Security.framework.

I tried -lSecurity.framework, -lSecurity, -lsecurity, and -lsecurity.framework and I get library not found errors. I am compiling using GCC.

jiminaus
May 30, 2011, 02:46 AM
Hello,

I would like to thank jiminaus and chown33 for their quick replies. But I am not certain how to link against the Security.framework.

I am not using XCode. I am attempting to build using Make because that is what I am familiar with and that is what a project my code will eventually need to go into uses and I am not certain what linker option to use to tell it to link against the Security.framework.

I tried -lSecurity.framework, -lSecurity, -lsecurity, and -lsecurity.framework and I get library not found errors. I am compiling using GCC.

Use the -framework option to gcc to compile against and link to a framework. For example.


gcc -framework CoreFramework -framework Security -o sectest sectest.c


Note that you don't need set include paths or lib paths. A framework is directory containing the dynamic lib library (.dylib file) for linking and running, header files for compiling, documentation for coding, and any resource files need by the library during runtime. So the -framework will do the work of -I, -L and -l.

The other Apple specific gcc flag you might be interested in is -arch. -arch i386 will compile 32-bit Intel code. -arch x86_64 will compile 64-bit Intel code. -arch ppc will compile PowerPC code. If you include multiple -arch options, you'll get a universal binary.

Ben.Key
May 30, 2011, 03:38 AM
Hello,

I posted a message saying I figured it out and that the linker option is -framework. Then I noticed a reply from jiminaus telling me the same thing.

Thanks!