Linker fail when compiling C++ program in XCode

Hi,


I am getting failing to build a XCode C++ project and am getting the following Link error that I don't understand:


ld: cannot link directly with /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/ SDKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)


This is the commands used by Xcode for the compilation, as shown in the build log:


Ld /Users/mako/Library/Developer/Xcode/DerivedData/cronStats-hhmlskhkokicccbbjwvap vprlyos/Build/Products/Development/cronStatsDaemon normal x86_64

cd /Users/mako/2017/statsProject/cronstats/trunk

export MACOSX_DEPLOYMENT_TARGET=10.9

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/ SDKs/MacOSX10.9.sdk -L/Users/mako/Library/Developer/Xcode/DerivedData/cronStats-hhmlskhkokicccbbjwv apvprlyos/Build/Products/Development -F/Users/mako/Library/Developer/Xcode/DerivedData/cronStats-hhmlskhkokicccbbjwv apvprlyos/Build/Products/Development -filelist /Users/mako/Library/Developer/Xcode/DerivedData/cronStats-hhmlskhkokicccbbjwvap vprlyos/Build/Intermediates/cronStatsDaemon.build/Development/cronStatsDaemon.** ild/Objects-normal/x86_64/cronStatsDaemon.LinkFileList -mmacosx-version-min=10.9 -framework IOKit -lcrypto.0.9.7 -framework Security -framework CoreFoundation -framework SystemConfiguration -Xlinker -dependency_info -Xlinker /Users/mako/Library/Developer/Xcode/DerivedData/cronStats-hhmlskhkokicccbbjwvap vprlyos/Build/Intermediates/cronStatsDaemon.build/Development/cronStatsDaemon.** ild/Objects-normal/x86_64/cronStatsDaemon_dependency_info.dat -o /Users/mako/Library/Developer/Xcode/DerivedData/cronStats-hhmlskhkokicccbbjwvap vprlyos/Build/Products/Development/cronStatsDaemon


Do you know what my error may be?


Many thanks


Mag

iMac

Posted on Oct 10, 2017 3:16 AM

Reply
12 replies

Oct 16, 2017 12:04 PM in response to mparkitsky

Is this something that requires that specific version of libcrypto? Can you use the OS version from the Security framework instead? Or could you link to a modern, static version of OpenSSL? That particular build of OpenSSL is just a can-o-worms, as you have discovered. At some point, whoever had that project before you hacked it. As with most such hacks, now it is your problem.


I can tell you that you should link with the Xcode SDK libraries, wherever those happen to be. At runtime, it will find and load the appropriate dynamic library (hence the "dynamic" part).


Don't attempt to change anything on disk. Just change the library being referenced in Xcode. Remove the "0.9.7" part and maybe you'll get lucky.

Oct 17, 2017 4:46 AM in response to mparkitsky

It is a different file. The SDK is what you build against. Then, at runtime, you link to whatever the system finds, wherever it finds it. /usr/lib is one such location, but there could be others. That particular library is a royal mess. Be careful with it. This app that you are building is not something that you ever want to distribute publicly.

Oct 12, 2017 3:33 AM in response to etresoft

Thanks.

I am using XCode Version 6.2 (6C131e) running on a mid-2009 macbook pro with Mac OSX 10.9.5

This is the output of the file command:


$ file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/ SDKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/S DKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib: Mach-O universal binary with 2 architectures

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/S DKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library stub x86_64

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/S DKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib (for architecture i386): Mach-O dynamically linked shared library stub i386


Thanks for any suggestions.

Mag

Oct 14, 2017 1:01 AM in response to etresoft

Thanks. I'll try your first suggestion first and remove the 0.9.7 from the library name.


However, I don't understand where the link library name is entered in XCode.

It appears as


-lcrypto.0.9.7


in the compliation command line if I look in the Report Navigator, but in the build options of the application target, I can see it nowhere in the Linking section ("Other Linker Flags" is empty in the project I'm trying to compile).

Where is it stored in the XCode Build options?

Many thanks

M.

Oct 16, 2017 10:07 AM in response to etresoft

Hi,


Thanks again. I can't find the "Linked Frameworks and Libraries" section you mention nor the General tab, maybe because I'm using such an old version of Xcode.

But on the left pane, under my project I have a folder called "Linked Frameworks and Libraries" under which appears Security.framework containing the libcrypto.dylib. When I select the libcrypto.dylib and look at the Utilities pane, the absolute path appears as: /usr/lib/libcrypto.0.9.7.dylib


However, the path appearing in the Linker error is different:


ld: cannot link directly with /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/ SDKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib for architecture x86_64


I also noticed that my /usr/lib folder contains a second version of the library called libcrypto.0.9.8.dylib (apart from the 0.9.7 version) and a libcrypto.dylib file which is in fact an alias pointing at the 0.9.8 version.


QUESTION1: When you suggested dropping the 0.9.7, do you mean dropping it from the file name of /usr/lib/libcrypto.0.9.7.dylib


or from:


/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/S DKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib


QUESTION2: What should I do with libcrypto.dylib alias pointing at the 0.9.8 version?

Mny thanks,

Mag

Oct 17, 2017 2:22 AM in response to etresoft

From what I can tell, the libcryto.dylib library is used for not much at all: just to encrypt and then decrypt some data using BF_ecb_encrypt (for which I get a deprecation warning).

I'll follow your advice and try to link to a new static version of OpenSSL.

Just one basic question:


Is the /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/ S DKs/MacOSX10.9.sdk/usr/lib/libcrypto.0.9.7.dylib an alias to /usr/lib/libcrypto.0.9.7.dylib or is it actually a different file, and which one of the two are used in compilation and runtime?


Thanks again.


M.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Linker fail when compiling C++ program in XCode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.