What happen if a static library (.a) contains duplicated object files (.o)? - ios

AFAIK, older version of Xcode failed to link a static library if it has been linked multiple times. I think there's a kind of duplicated object-file or symbol issue.
Recently, I realized Xcode5 is not reporting related error anymore on duplicated link of a static library. Here's my test.
I wrote 3 Objective-C classes are named as s1, s2, s3 in separated projects.
Each of them is compiled into s1.o, s2.o, s3.o,
and finally archived into s1.a, s2.a, s3.a.
s2 linked (merged) with s1, and s3 is linked (merged) with s2 and s1.
Finally I got these .a files.
Eonil$ ar -tv libs1.a
rw-r--r-- 501/20 64 Aug 3 18:38 2014 __.SYMDEF SORTED
rw-r--r-- 501/20 5528 Aug 3 18:38 2014 s1.o
Eonil$ ar -tv libs2.a
rw-r--r-- 501/20 120 Aug 3 18:38 2014 __.SYMDEF SORTED
rw-r--r-- 501/20 5872 Aug 3 18:38 2014 s2.o
rw-r--r-- 501/20 5528 Aug 3 18:38 2014 s1.o
Eonil$ ar -tv libs3.a
rw-r--r-- 501/20 224 Aug 3 18:38 2014 __.SYMDEF
rw-r--r-- 501/20 5872 Aug 3 18:38 2014 s3.o
rw-r--r-- 501/20 5528 Aug 3 18:38 2014 s1.o
rw-r--r-- 501/20 5872 Aug 3 18:38 2014 s2.o
rw-r--r-- 501/20 5528 Aug 3 18:38 2014 s1.o
Those same named .o files are all duplicated.
I wrote a p1 project which is a command line executable, and linked it with all the s1.a, s2.a, s3.a. I expected some duplication error, but it just built and working well!
What's happening in Xcode for these duplicated linking of static libraries?

Confirmed; the linker stops looking for symbols once it finds it in the first library.
If you use the -all_load option, however it will fail:
$ clang -all_load -o prog main.o -L. -lone -ltwo -lthree
duplicate symbol _func in:
./libone.a(file.o)
./libtwo.a(file.o)
duplicate symbol _func in:
./libone.a(file.o)
./libthree.a(file.o)
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This was tested using C, not that that matters:
$ cat main.c
extern void func();
int main(int argc, const char **argv)
{
func();
return 0;
}
$ cat file.c
#include <stdio.h>
void func()
{
printf("func()\n");
}

Related

Can't upload iOS app to store with specific framework

The last week I've been dealing with properly adding frameworks into my iOS app so that I can upload it to the app store. I took out some dynamic frameworks, and replaced them with static ones. However, one of the frameworks I'm using is static (which I've double checked using the method explained here), but the app store is still not allowing me to upload with it. I'm getting the following message when doing so:
UserInfo={NSLocalizedDescription=Item at "/Users/aaronmednick/Library/Developer/Xcode/Archives/2018-06-20/myApp 6-20-18, 3.01 PM.xcarchive/Products/Applications/myapp.app/Python.framework/Versions/2.7" did not contain a "archived-expanded-entitlements.xcent" resource.}
For reference here's my output for checking that the Python.framework I'm using is a static one:
Aarons-MacBook-Air:Python.framework aaronmednick$ ls -l
total 0
lrwxr-xr-x 1 aaronmednick staff 24 Jun 19 20:58 Headers -> Versions/Current/Headers
lrwxr-xr-x 1 aaronmednick staff 23 Jun 19 20:58 Python -> Versions/Current/Python
lrwxr-xr-x 1 aaronmednick staff 26 Jun 19 20:58 Resources -> Versions/Current/Resources
drwxr-xr-x# 4 aaronmednick staff 128 Jun 19 20:58 Versions
Aarons-MacBook-Air:Python.framework aaronmednick$ file Python
Python: Mach-O universal binary with 5 architectures: [i386:current ar archive] [arm64]
Python (for architecture i386): current ar archive
Python (for architecture armv7): current ar archive
Python (for architecture armv7s): current ar archive
Python (for architecture x86_64): current ar archive
Python (for architecture arm64): current ar archive
Any help with this issue would be much appreciated!

iOS is it a static or a dynamic framework?

This might sound like a silly question but If you have a thirdParty.framework file, can you tell if it's static or dynamic? I mean, do they look different if you look inside?
It can be either.
Only iOS8+ will allow dynamic frameworks in the app bundle, however.
The way to find out is to look in the .framework and use the file command on the main file:
$ cd iOS/Crashlytics.framework
$ ls -l
total 9984
-rwxr-xr-x 1 andy staff 4710656 11 Sep 17:11 Crashlytics
drwxr-xr-x 8 andy staff 272 11 Sep 17:11 Headers
-rw-r--r-- 1 andy staff 1553 11 Sep 17:11 Info.plist
drwxr-xr-x 3 andy staff 102 11 Sep 17:11 Modules
-rwxr-xr-x 1 andy staff 146164 11 Sep 17:11 run
-rwxr-xr-x 1 andy staff 241688 11 Sep 17:11 submit
$ file Crashlytics
Crashlytics: Mach-O universal binary with 5 architectures
Crashlytics (for architecture armv7): current ar archive random library
Crashlytics (for architecture armv7s): current ar archive random library
Crashlytics (for architecture i386): current ar archive random library
Crashlytics (for architecture x86_64): current ar archive random library
Crashlytics (for architecture arm64): current ar archive random library
Where ar archive means "static library".
Alternatively, a "dynamic" framework will look like this and explicitly state that it's dynamically linked.
$ cd /Library/Frameworks/iTunesLibrary.framework/
$ ls -l
total 40
lrwxr-xr-x 1 root wheel 24 10 Sep 17:38 Headers -> Versions/Current/Headers
lrwxr-xr-x 1 root wheel 24 10 Sep 17:38 Modules -> Versions/Current/Modules
lrwxr-xr-x 1 root wheel 26 10 Sep 17:38 Resources -> Versions/Current/Resources
drwxr-xr-x 4 root wheel 136 10 Sep 17:41 Versions
lrwxr-xr-x 1 root wheel 22 10 Sep 17:38 XPCServices -> Versions/A/XPCServices
lrwxr-xr-x 1 root wheel 30 10 Sep 17:38 iTunesLibrary -> Versions/Current/iTunesLibrary
$ file Versions/Current/iTunesLibrary
Versions/Current/iTunesLibrary: Mach-O universal binary with 2 architectures
Versions/Current/iTunesLibrary (for architecture i386): Mach-O dynamically linked shared library i386
Versions/Current/iTunesLibrary (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
I use this command to list all STATIC Frameworks from a path with a list of frameworks:
find -E . -type f -iregex ".*\.framework\/[^./]*" -exec file {} \; | grep ': current ar archive' | sed 's/.*\/\(.*.framework\).*/\1/'

Almost naked iOS8.4 --> how to get a linker?

EDIT 2015-29-10. II. In fact -arch armv7 instead of -arch arm64 and without lowering optimization, worked perfectly.
EDIT 2015-29-10. I. I tried to add
export CFLAGS="-O1"
export CXXFLAGS="-O1"
before configure, and had the same error, with a different file missing this time :
"/usr/local/cctools-arm64-port/bin/ld" -demangle -dynamic -arch arm64 -iphoneos_version_min 5.0.0 -syslibroot /usr/local/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-4f79ac.o -lstdc++ -lSystem
ld: file not found: N?L
I also tried with -O0 optimization instead of -01, same result.
EDIT 2015-28-10. II. I did this :
./autogen.sh
export CC="clang -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
export CXX="clang++ -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
./configure -v --host=arm-apple-darwin11 --prefix=/usr/local/lvm-cross/cctools-arm64-port
unset CC CXX
make && sudo make install
Then I tried a simple hello world on iDevice, with testcpp.cpp containing :
#include <iostream>
int main()
{
std::cout << "oijo" << std::endl;
return 0;
}
compiled with
clang++ -v -isysroot /usr/local/iPhoneOS8.4.sdk -target arm64-apple-darwin11 testcpp.cpp -o testcpp
which gave me :
clang version 3.7.0 (tags/RELEASE_370/final)
Target: arm64-apple-darwin11
Thread model: posix
"/usr/local/llvm-ios/bin/clang++" -cc1 -triple arm64-apple-ios5.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name testcpp.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -target-cpu generic -target-feature +neon -target-abi darwinpcs -target-linker-version 253.3.3 -v -dwarf-column-info -resource-dir /usr/local/llvm-ios/bin/../lib/clang/3.7.0 -isysroot /usr/local/iPhoneOS8.4.sdk -fdeprecated-macro -fdebug-compilation-dir /var/mobile/Documents/CODING/MY/TESTS_0/CPP -ferror-limit 19 -fmessage-length 108 -stack-protector 1 -mstackrealign -fallow-half-arguments-and-returns -fblocks -fobjc-runtime=ios-5.0.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/tmp/testcpp-f1de66.o -x c++ testcpp.cpp
clang -cc1 version 3.7.0 based upon LLVM 3.7.0 default target arm-apple-darwin14.0.0
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1/arm64-apple-darwin10/"
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/usr/local/include"
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1
/usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1/backward
/usr/local/llvm-ios/bin/../lib/clang/3.7.0/include
/usr/local/iPhoneOS8.4.sdk/usr/include
/usr/local/iPhoneOS8.4.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/usr/local/cctools-arm64-port/bin/ld" -demangle -dynamic -arch arm64 -iphoneos_version_min 5.0.0 -syslibroot /usr/local/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-f1de66.o -lstdc++ -lSystem
ld: file not found: ?4
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I also tried without the unset CC CXX, with the same "success"...
EDIT 2015-28-10. I. Using cydia solutions as suggested indeed worked, but I definitely want to build it myself, so I followed the https://github.com/tpoechtrager/cctools-port way. As it is way too boring to get/build libtool for mac os, I switched to a vitual box ubuntu 15.10 64 bits, where I sudo apt-get install'ed the following packages : automake, autogen, libtool, clang-3.7, uuid-dev and llvm-3.7-dev. Then I cd'ed to the cctools directory and did :
./autogen.sh
export CC="clang-3.7 -arch arm64"
export CXX="clang++-3.7 -arch arm64"
./configure --prefix=/home/lvm-ubuntu/Desktop/iPad/cctools-produced/ --host=arm-apple-darwin11
make
(The complete output is in the new following gist.) make produced the following warnings and errors :
clang: warning: argument unused during compilation: '-arch arm64'
../include/foreign/libkern/arm/OSByteOrder.h:11:10: error: redefinition of
'_OSSwapInt16'
uint16_t _OSSwapInt16(uint16_t data)
^
../include/foreign/libkern/i386/_OSByteOrder.h:46:1: note: previous definition
is here
_OSSwapInt16(
^
and analogue errors for _OSSwapInt32 and _OSSwapInt64... I must be for sure doing something wrong.
Initial question.
I succeed in cross-building clang+llvm for iOS8.4 on a jailbroken iPad mini 3 wifi, mainly thanks to the two following questions :
https://stackoverflow.com/questions/32808144/how-to-cross-compile-clang-llvm-3-7-0-for-ios8-x-on-ipad-mini-3/
and
https://stackoverflow.com/questions/23946851/how-to-cross-compile-clang-llvm-for-ios/
Set all paths etc, and tried a clang++ -v testcpp.cpp -o testcpp where testcpp.cppcontains :
int main()
{
return 0;
}
and got this :
clang++: error: unable to execute command: Executable "ld" doesn't exist!
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
(the whole verbose output is in this gist.)
Obviously I don't have GNU's ld nor any real "remplacement" of it (by llvm-clang), so that I am asking myself : what is my strategy in this case ? (Having no linker, I can't even try to build binutils on my iPad to use its ld).
Precision : I would like the linking to be done behind the scene, so that I could keep doing clang++ -v testcpp.cpp -o testcpp, that is, I don't want to do the linking "manually" myself in several steps. (But a script could be ok, even if I find more elegant to have a real ld replacement...)
Remark : in llvm-clang bin folder I have this :
XXXXs-iPad:/usr/local/llvm-ios/bin mobile$ ls -l
total 274412
-rwxr-xr-x 1 root wheel 205456 Oct 18 12:49 FileCheck*
-rwxr-xr-x 1 root wheel 7704096 Oct 18 12:48 bugpoint*
-rwxr-xr-x 1 root wheel 122036 Oct 18 12:48 c-index-test*
-rwxr-xr-x 1 root wheel 40802004 Oct 18 12:48 clang*
-rwxr-xr-x 1 root wheel 40802004 Oct 18 12:49 clang++*
-rwxr-xr-x 1 root wheel 31252792 Oct 18 12:49 clang-check*
-rwxr-xr-x 1 root wheel 1225352 Oct 18 12:49 clang-format*
-rwxr-xr-x 1 root wheel 671500 Oct 18 12:49 clang-tblgen*
-rwxr-xr-x 1 root wheel 49684 Oct 18 12:49 count*
-rwxr-xr-x 1 root wheel 22439396 Oct 18 12:49 llc*
-rwxr-xr-x 1 root wheel 10351388 Oct 18 12:49 lli*
-rwxr-xr-x 1 root wheel 208140 Oct 18 12:49 lli-child-target*
-rwxr-xr-x 1 root wheel 9144692 Oct 18 12:49 llvm-ar*
-rwxr-xr-x 1 root wheel 1619592 Oct 18 12:49 llvm-as*
-rwxr-xr-x 1 root wheel 155080 Oct 18 12:49 llvm-bcanalyzer*
-rwxr-xr-x 1 root wheel 120864 Oct 18 12:49 llvm-config*
-rwxr-xr-x 1 root wheel 92232 Oct 18 12:49 llvm-config-host*
-rwxr-xr-x 1 root wheel 1604600 Oct 18 12:49 llvm-cov*
-rwxr-xr-x 1 root wheel 1472656 Oct 18 12:49 llvm-cxxdump*
-rwxr-xr-x 1 root wheel 1471516 Oct 18 12:49 llvm-diff*
-rwxr-xr-x 1 root wheel 1225632 Oct 18 12:49 llvm-dis*
-rwxr-xr-x 1 root wheel 18342488 Oct 18 12:49 llvm-dsymutil*
-rwxr-xr-x 1 root wheel 419892 Oct 18 12:49 llvm-dwarfdump*
-rwxr-xr-x 1 root wheel 1686496 Oct 18 12:49 llvm-extract*
-rwxr-xr-x 1 root wheel 1800856 Oct 18 12:49 llvm-link*
-rwxr-xr-x 1 root wheel 10140692 Oct 18 12:49 llvm-mc*
-rwxr-xr-x 1 root wheel 138552 Oct 18 12:49 llvm-mcmarkup*
-rwxr-xr-x 1 root wheel 9144172 Oct 18 12:49 llvm-nm*
-rwxr-xr-x 1 root wheel 11554352 Oct 18 12:49 llvm-objdump*
-rwxr-xr-x 1 root wheel 220840 Oct 18 12:49 llvm-pdbdump*
-rwxr-xr-x 1 root wheel 469920 Oct 18 12:49 llvm-profdata*
-rwxr-xr-x 1 root wheel 9144692 Oct 18 12:49 llvm-ranlib*
-rwxr-xr-x 1 root wheel 1768528 Oct 18 12:49 llvm-readobj*
-rwxr-xr-x 1 root wheel 8388100 Oct 18 12:50 llvm-rtdyld*
-rwxr-xr-x 1 root wheel 1489124 Oct 18 12:50 llvm-size*
-rwxr-xr-x 1 root wheel 2106052 Oct 18 12:50 llvm-stress*
-rwxr-xr-x 1 root wheel 1610176 Oct 18 12:50 llvm-symbolizer*
-rwxr-xr-x 1 root wheel 1422732 Oct 18 12:50 llvm-tblgen*
-rwxr-xr-x 1 root wheel 1455516 Oct 18 12:50 macho-dump*
-rwxr-xr-x 1 root wheel 71184 Oct 18 12:50 not*
-rwxr-xr-x 1 root wheel 1620520 Oct 18 12:50 obj2yaml*
-rwxr-xr-x 1 root wheel 23007212 Oct 18 12:50 opt*
-rwxr-xr-x 1 root wheel 1768416 Oct 18 12:50 verify-uselistorder*
-rwxr-xr-x 1 root wheel 402360 Oct 18 12:50 yaml2obj*
Install org.coolstar.cctools and org.coolstar.ld64 via Cydia.
Or, alternatively, build https://github.com/tpoechtrager/cctools-port by hand.
CXX="clang++ -arch arm64" CC="clang -arch arm64" ./configure --host=arm-apple-darwin11

idlj parameter invalid argument -td mac?

Im trying to follow a tutorial to do a CORBA assignment.
project
-Client/HelloClient.java
-Server/HelloServer.java
-Hello.idl
I do the first step, trying to compile the IDL (from the project root), and it fails.
$ idlj –td Client –fclient Hello.idl
com.sun.tools.corba.se.idl.InvalidArgument: Invalid argument: –td.
java version "1.8.0_11"
$ ls -l
total 16
drwxr-xr-x 3 juliusskye staff 102 Oct 28 20:14 Client
-rw-r-----# 1 juliusskye staff 85 Oct 28 17:49 Hello.idl
drwxr-xr-x 3 juliusskye staff 102 Oct 28 17:52 Server
-rw-r--r-- 1 juliusskye staff 425 Oct 29 13:45 idljintro.iml
drwxr-xr-x 2 juliusskye staff 68 Oct 29 13:45 src
I found this which says CORBA has problems parsing paths with / in front. But mine doesn't have a /
apparently the Lecturer's instructions were wrong or outdated or the compiler is not fully working but compilation of all files is achieved by
idlj -fall hello.idl

Leopard => Snow Leopard architecture woes with nokogiri / rails

I'm confused. It's a regular state of affairs for me but specifically in this case I felt I could reach out to fellow stackoverflowers (that is, stackoverflow-ers, not stackover-flowers).
uname -a
Darwin macbookpro 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386
set
bash-3.2$ set
...
HOSTTYPE=x86_64
...
MACHTYPE=x86_64-apple-darwin10.0
...
I'm having a nightmare rebuilding some native ruby gems and I'm wondering whether this is part of the problem -- part of this machine says its 64 bit but another part 32 ... as far as I can tell?
Under 'About this Mac' it says 'Intel Core 2 Duo' which Apple says is 64 bit. So why, after doing
sudo gem pristine --all
am I still getting this kind of error?
dlopen(/Applications/Rails/ruby/lib/ruby/gems/1.8/gems/nokogiri-1.4.2/lib/nokogiri/nokogiri.bundle, 9): no suitable image found. Did find:
/Applications/Rails/ruby/lib/ruby/gems/1.8/gems/nokogiri-1.4.2/lib/nokogiri/nokogiri.bundle: mach-o, but wrong architecture - /Applications/Rails/ruby/lib/ruby/gems/1.8/gems/nokogiri-1.4.2/lib/nokogiri/nokogiri.bundle
Specifically I had removed nokogiri and reinstalled it. No errors in output.
bash-3.2$ sudo gem install nokogiri
Building native extensions. This could take a while...
Successfully installed nokogiri-1.4.2
1 gem installed
thanks for any thoughts!
UPDATE
I've found a useful post by Chris Noos on a similar problem. This is where I am:
cd /usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.4.2/
then made a file called wem_extconf.rb:
require 'mkmf'
find_library('xml2', 'xmlParseDoc')
dir_config('any-string-here', '/opt/local/include', '/opt/local/lib')
find_library('xml2', 'xmlParseDoc')
Running sudo web_extconf.rb produces
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -lxml2... no
???? But hang on, it is there:
$ port installed | grep libxml2.*active
libxml2 #2.7.7_0+universal (active)
$ ls -l /opt/local/lib | grep libxml2
-rwxr-xr-x 2 root admin 2623276 31 May 20:09 libxml2.2.dylib
-rw-r--r-- 2 root admin 3643928 31 May 20:09 libxml2.a
lrwxr-xr-x 1 root admin 15 31 May 20:09 libxml2.dylib -> libxml2.2.dylib
-rwxr-xr-x 2 root admin 975 31 May 20:09 libxml2.la
And it does appear I have several copies of the thing -- but not sure which one port installed is using (I'm assuming given it's macports, it's /opt?)
$ ls -l /usr/lib | grep libxml2
lrwxr-xr-x 1 root wheel 15 23 May 16:07 libxml2.2.7.3.dylib -> libxml2.2.dylib
-rwxr-xr-x 1 root wheel 3758272 22 Sep 2009 libxml2.2.dylib
lrwxr-xr-x 1 root wheel 15 23 May 16:07 libxml2.dylib -> libxml2.2.dylib
$ ls -l /usr/local/lib | grep libxml2
-rwxr-xr-x 1 root admin 1456292 30 Oct 2009 libxml2.2.dylib
-rw-r--r-- 1 root admin 4812456 30 Oct 2009 libxml2.a
-rwxr-xr-x 1 root admin 1456292 30 Oct 2009 libxml2.dylib
-rwxr-xr-x 1 root admin 951 30 Oct 2009 libxml2.la
On Snow Leopard, gcc has a misleading behavior; even if you are running a i386 kernel, gcc will produce 64 bits binaries by default.
Have you looked at the GEM documentation to see how to specify the targeted architecture ?
Have you installed the XCode Development tools?

Resources