Welcome, Guest Login

Support Center

Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

duplicate symbol _main error with SDK in iOS

Dylan Reynolds Apr 26, 2014 10:43AM EDT

I am receiving the following compiler error when I include the SDK in my iOS project:

duplicate symbol _main in:
[...]/main.o
[...]/AppBlade/libAppBladeUniversal.a(main.o)

How can this be fixed?

Up -4 rated Down
Michael Johnson Apr 26, 2014 10:46AM EDT AppBlade Agent
Quick answer: try removing the linker setting "-all_load" from your project. If this causes different errors, you will need to use "-force_load" to explicitly load any missing libraries.

The AppBlade SDK includes some open source code that has its own main() functions. The modules including main() are not intended to be linked into your project, but when using the "-all_load" linker setting in XCode, every library in the workspace is linked automatically.

If this is what is causing the problem for you and removing "-all_load" causes errors due to missing modules, it can be fixed by using "-force_load" instead. For example, Cordova projects use "-all_load" by default, but you can switch to "-force_load $(BUILT_PRODUCTS_DIR)/libCordova.a", as described at http://stackoverflow.com/questions/16683090/cordova-build-without-all-load).

If you look at http://stackoverflow.com/questions/2567498/objective-c-categories-in-static-library, one of the answers suggests that both -all_load and -force_load are no longer necessary, because the libraries you need can just be flagged with -ObjC. We haven't tested this approach yet.
Up 0 rated Down
Steven Bakondi May 21, 2014 07:45AM EDT
My attempts to use _force_load and -ObjC on my other third party (no access to source) library didn’t work, so I had to do some minor surgery on the libAppBladeUniversal.a file.

Here’s how I did it (and my answer is based on http://atnan.com/blog/2012/01/12/avoiding-duplicate-symbol-errors-during-linking-by-removing-classes-from-static-libraries)

cp libAppBladeUniversal.a /tmp
pushd /tmp

lipo -info libAppBladeUniversal.a

# extract each architecture of the static library
lipo -thin armv7 libAppBladeUniversal.a -output libAppBladeUniversal-armv7.a
lipo -thin armv7s libAppBladeUniversal.a -output libAppBladeUniversal-armv7s.a
lipo -thin i386 libAppBladeUniversal.a -output libAppBladeUniversal-i386.a
lipo -thin x86_64 libAppBladeUniversal.a -output libAppBladeUniversal-x86_64.a
lipo -thin arm64 libAppBladeUniversal.a -output libAppBladeUniversal-arm64.a

# make folders to hold the .o files
mkdir libAppBladeUniversal-arm64 libAppBladeUniversal-armv7 libAppBladeUniversal-armv7s libAppBladeUniversal-i386 libAppBladeUniversal-x86_64

# now extract the .o files, remove main, and re-pack the archive
cd libAppBladeUniversal-armv7
ar -x ../libAppBladeUniversal-armv7.a ; rm main.o ; libtool -static -o ../libAppBladeUniversal-armv7.a *.o

# and we’ll do it for the other architectures
cd ../libAppBladeUniversal-armv7s ;
ar -x ../libAppBladeUniversal-armv7s.a ; rm main.o ; libtool -static -o ../libAppBladeUniversal-armv7s.a *.o

cd ../libAppBladeUniversal-arm64
ar -x ../libAppBladeUniversal-armv64.a ; rm main.o ; libtool -static -o ../libAppBladeUniversal-arm64.a *.o

cd ../libAppBladeUniversal-i386
ar -x ../libAppBladeUniversal-i386.a ; rm main.o ; libtool -static -o ../libAppBladeUniversal-i386.a *.o

cd ../libAppBladeUniversal-x86_64
ar -x ../libAppBladeUniversal-x86_64.a ; rm main.o ; libtool -static -o ../libAppBladeUniversal-x86_64.a *.o

# at the end, you lipo the whole thing back together again…
cd ..
ls
lipo -create libAppBladeUniversal-arm64.a libAppBladeUniversal-armv7.a libAppBladeUniversal-armv7s.a libAppBladeUniversal-i386.a libAppBladeUniversal-x86_64.a -output libAppBladeUniversal.a

echo “done… no more main; let’s copy it somewhere useful”

This question has received the maximum number of answers.

support@appblade.com
https://cdn.desk.com/
false
appblade
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete