Symbols not found error when linking iPhone app in Xcode - c++

Whenever I try to compile my iPhone app which i am porting I get linking errors. The app uses a scripting language called Squirrel (to read the level files, fine by the SDK, no user input). I have linked all the libraries including libsquirrel.a. What am I doing wrong?
(App is SuperTux, source code at supertux.lethargik.org for computer version).
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_12AmbientSoundEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_12ThunderstormEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_13DisplayEffectEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_14ScriptedObjectEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_4TextEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_4WindEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_6CameraEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_6CandleEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_6PlayerEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_7SSectorEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_7TileMapEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_8PlatformEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_9LevelTimeEb", referenced from:
Line Location Tool:0: "__ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_9WillOWispEb", referenced from:
Line Location Tool:0: "__ZN9Scripting25register_supertux_wrapperEP4SQVM", referenced from:
Line Location Tool:0: __ZN9Scripting13expose_objectINS_12AmbientSoundEEEvP4SQVMiPT_RKSsb in ambient_sound.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_12ThunderstormEEEvP4SQVMiPT_RKSsb in thunderstorm-02078462.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_13DisplayEffectEEEvP4SQVMiPT_RKSsb in display_effect.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_14ScriptedObjectEEEvP4SQVMiPT_RKSsb in scripted_object.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_4TextEEEvP4SQVMiPT_RKSsb in text_object.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_4WindEEEvP4SQVMiPT_RKSsb in wind-9E10B675.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_6CameraEEEvP4SQVMiPT_RKSsb in camera-A3560D66.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_6CandleEEEvP4SQVMiPT_RKSsb in candle-06462D68.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_6PlayerEEEvP4SQVMiPT_RKSsb in player.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_7SSectorEEEvP4SQVMiPT_RKSsb in sector.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_7TileMapEEEvP4SQVMiPT_RKSsb in tilemap-8DC8046A.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_8PlatformEEEvP4SQVMiPT_RKSsb in platform-E187A570.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_9LevelTimeEEEvP4SQVMiPT_RKSsb in level_time-2C8E1157.o
Line Location Tool:0: __ZN9Scripting13expose_objectINS_9WillOWispEEEvP4SQVMiPT_RKSsb in willowisp.o
Line Location Tool:0: __ZN9Scripting13init_squirrelEb in squirrel_util.o
Line Location Tool:0: collect2: ld returned 1 exit status
Line Location Tool:0: symbol(s) not found
When I looked at the build output:
Ld "/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/Debug-iphonesimulator/SuperTux.app/SuperTux" normal i386
cd "/Users/Thomas/Documents/iPhone Dev Projects./SuperTux"
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk "-L/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/Debug-iphonesimulator" "-L/Users/Thomas/Documents/iPhone Dev Projects./SuperTux" "-L/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/../../../Library/Frameworks/SDL.framework/Headers" "-L/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/../../../Downloads/SQUIRREL2/lib" -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/lib/gcc/i686-apple-darwin9/4.0.1 "-F/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/Debug-iphonesimulator" "-F/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/../../../Library/Frameworks" "-F/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/../../../Downloads" "-F/Users/Thomas/Documents/iPhone Dev Projects./SuperTux" -F/Applications/SuperTux.app/Contents/Frameworks "-F/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/../../../Desktop/SDL2" -filelist <b>"/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/SuperTux.LinkFileList" -Wl,--no-demangle -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -framework SDL_image -framework Ogg -framework Vorbis -lSDLSimulator -lSDLiPhoneOS -framework SDL -framework OpenAL -lphysfsdevice "/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/English.lproj/lphysfssimulator.a" -loggdevice -loggsim -lSDL_imagedevice -lSDL_imagesim -lvorbisdevice -lvorbisencdevice -lvorbisfiledevice -lvorbisencsim -lvorbisfilesim -lvorbissim -lminiswigdevice -lminiswigsim -lsqstdlib -framework SDL_mixer -framework SDL_image -lSDL_mixer -lSDL_mixersim -lstdc++-static -lstdc++ -lz -lSDLmain -framework CoreGraphics -framework CoreAudio -framework AudioToolbox -lsquirrelsim -lsquirreldevice -prebind -o "/Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/Debug-iphonesimulator/SuperTux.app/SuperTux"</b>
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libSDLiPhoneOS.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libphysfsdevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/liboggdevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libSDL_imagedevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libvorbisdevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libvorbisencdevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libvorbisfiledevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libminiswigdevice.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libSDL_mixer.a, file is not of required architecture
ld warning: in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libsquirreldevice.a, file is not of required architecture
ld warning: __ZTVSt11range_error has different visibility (hidden) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libstdc++-static.a(stdexcept.o) and (default) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTISt11range_error has different visibility (hidden) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libstdc++-static.a(stdexcept.o) and (default) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTSSt11range_error has different visibility (hidden) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libstdc++-static.a(stdexcept.o) and (default) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTISt11range_error has different visibility (hidden) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libstdc++-static.a(functexcept.o) and (default) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTVSt11range_error has different visibility (hidden) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libstdc++-static.a(functexcept.o) and (default) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTSSt11range_error has different visibility (hidden) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/libstdc++-static.a(functexcept.o) and (default) in /Users/Thomas/Documents/iPhone Dev Projects./SuperTux/build/SuperTux.build/Debug-iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
Something strange might be going on with libstdc++-static.a. Not even sure what it is.

C++filt is your friend it will unmangle those names to show you what is missing:
> c++filt __ZN9Scripting24create_squirrel_instanceEP4SQVMPNS_12AmbientSoundEb
Scripting::create_squirrel_instance(SQVM*, Scripting::AmbientSound*, bool)
The first line from above seems to indicate that it can't find the definition of the method create_squirrel_instace from the class Scripting.
So the order the libraries are presented to g++ (which is the compiler used on a mac) is important. So have a look at the build output and see if you can find the line where the libraries are linked:
It should look like this:
g++ <STUFF> -l<lib1> -l<lib2> etc.
I reformated the abovre output so it is readable:
In the text I replace
/Users/Thomas/Documents/iPhone Dev Projects./SuperTux with <DIR> to help readability:
A whole bunch of the libraries are not being used becuase they are the wrong architecture:
ld warning: in <DIR>/SuperTux/libSDLiPhoneOS.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libphysfsdevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/liboggdevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libSDL_imagedevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libvorbisdevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libvorbisencdevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libvorbisfiledevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libminiswigdevice.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libSDL_mixer.a,
file is not of required architecture
ld warning: in <DIR>/SuperTux/libsquirreldevice.a,
file is not of required architecture
Then you also have some warning you should look at:
ld warning: __ZTVSt11range_error
has different visibility
(hidden) in <DIR>/SuperTux/libstdc++-static.a(stdexcept.o)
and (default) in <DIR>/SuperTux/build/SuperTux.build/Debug iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTISt11range_error
has different visibility
(hidden) in <DIR>/SuperTux/libstdc++-static.a(stdexcept.o)
and (default) in <DIR>/SuperTux/build/SuperTux.build/Debug iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTSSt11range_error
has different visibility
(hidden) in <DIR>/SuperTux/libstdc++-static.a(stdexcept.o)
and (default) in <DIR>/SuperTux/build/SuperTux.build/Debug iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTISt11range_error
has different visibility
(hidden) in <DIR>/SuperTux/libstdc++-static.a(functexcept.o)
and (default) in <DIR>/SuperTux/build/SuperTux.build/Debug iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTVSt11range_error
has different visibility
(hidden) in <DIR>/SuperTux/libstdc++-static.a(functexcept.o)
and (default) in <DIR>/SuperTux/build/SuperTux.build/Debug iphonesimulator/SuperTux.build/Objects-normal/i386/font.o
ld warning: __ZTSSt11range_error
has different visibility
(hidden) in <DIR>/SuperTux/libstdc++-static.a(functexcept.o)
and (default) in <DIR>/SuperTux/build/SuperTux.build/Debug iphonesimulator/SuperTux.build/Objects-normal/i386/font.o

Related

Error code while compiling a project: Undefined symbol for architecture arm64

I'm trying to compile a projet with a makefile but I get this error message :
g++ testVecteur2D.o Vecteur2D.o -o testVecteur2D
ld: warning: ignoring file Vecteur2D.o, building for macOS-arm64 but attempting to link with file built for unknown-x86_64
ld: warning: ignoring file testVecteur2D.o, building for macOS-arm64 but attempting to link with file built for unknown-x86_64
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [testVecteur2D] Error 1
my code is working on other computer so I don't understand why it is not on mine. For information I'm using de new m1 Mac maybe it has something to do with it.

Opencv on OSX, Undefined symbols for architecture x86_64: cv::imwrite not found

I installed opencv by brew, I tried to reinstall for several times and it didn't help. I have googled for a lot of time but didn't find a valid way to solve this.
I copied a valid opencv from my friend's mac, but the imwrite function is still not found on my mac
Please help.
bash: g++ $(pkg-config --cflags --libs opencv) BoxFilter.cc -o BoxFilter
In file included from /usr/local/Cellar/opencv/3.3.0_3/include/opencv2/core.hpp:54:0,
from /usr/local/Cellar/opencv/3.3.0_3/include/opencv2/opencv.hpp:52,
from BoxFilter.cc:2:
/usr/local/Cellar/opencv/3.3.0_3/include/opencv2/core/base.hpp:354:35: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
# pragma GCC diagnostic ignored "-Winvalid-noreturn"
^
Undefined symbols for architecture x86_64:
"cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)",referenced from:
_main in ccO7bsE6.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Undefined symbols for architecture armv7 but lipo -info shows ok

I think you guys have seen this kind of errors before, but mine is special.
I have a few static libs in my Xcode project, when I tried to build it I got this error. But I have checked all my libs with command xcrun -sdk iphoneos lipo -info $libname, it gave me Architectures in the fat file: /Users/kiwi/Documents/Development/SourceCode/prj/lib.a are: armv7 i386 x86_64 arm64.
Undefined symbols for architecture armv7: "_SSLv2_server_method",
referenced from:
CSSLctx::Create(bool, CSSLctx::sslProtocol) in libudp.a(SSLStream.o) "_SSLv2_client_method", referenced from:
CSSLctx::Create(bool, CSSLctx::sslProtocol) in libudp.a(SSLStream.o) ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see
invocation)

gnu ld (mac) not working, linker command fail with error code 1

I have the following problem with my ld.
$ ld
ld: warning: -arch not specified
ld: warning: -macosx_version_min not specified, assuming 10.9
ld: no object files specified for inferred architecture x86_64
What shall I do?
I got the following errors when I compile CUDD:
libmtr.a ../st/libst.a ../util/libutil.a ../epd/libepd.a -lm
Undefined symbols for architecture x86_64:
"_edata", referenced from:
_util_print_cpu_stats in libutil.a(cpu_stats.o)
"_end", referenced from:
_util_print_cpu_stats in libutil.a(cpu_stats.o)
"_etext", referenced from:
_util_print_cpu_stats in libutil.a(cpu_stats.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [nanotrav] Error 1
make: *** [build] Error 2
PS: I am using
$ xcodebuild -version
Xcode 7.1
Build version 7B91b
my ld is /usr/bin/ld.

Apple Mach-O linker error: Undefined symbols for architecture i386 Google Protobuf

I am trying to use Protobuf 2.6 with Xcode version 6.3. I've added the libprotobuf-lite.a to my Demo application and added the path to the Header files in the Header Search Paths., but I am getting this error.
Undefined symbols for architecture i386:
"google::protobuf::io::StringOutputStream::StringOutputStream(std::string*)",
referenced from:
attributes::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)
in attributes.pb.o ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see
invocation)