LLVM symbol lookup difficulties - c++

I'm following along with the tutorial LLVM provides to get familiar with its IR that can be found here.
Unfortunately, it seems that when I add in the JIT support, the linker has some difficulty following along. Namely, I get a number of undefined symbols,
Undefined symbols for architecture x86_64:
"_LLVMInitializeX86AsmParser", referenced from:
llvm::InitializeNativeTargetAsmParser() in lexer.cc.o
"_LLVMInitializeX86AsmPrinter", referenced from:
llvm::InitializeNativeTargetAsmPrinter() in lexer.cc.o
etc.
I'm building using CMAKE using the LLVM config and can find the headers in my include directories, so I'm unsure why the symbols can't be fine. My code is here, but isn't too specific to the problem. I'm on MacOS.
How can I make the linker find the header files or why is it not working?

If you are using CMake, you need to add some LLVM components. Here is an excerpt from my CMakeLists.txt for the same chapter.
llvm_map_components_to_libnames(llvm_libs analysis core executionengine instcombine object orcjit runtimedyld scalaropts support native)
Relevant links:
The official CMakeLists.txt for the chapter
A StackOverflow question about a similar problem
The example CMakeLists.txt from the documentation

Related

Building a Unity exported Xcode project with LLVM and libc++

I'm currently attempting to build an Xcode project exported from Unity with LLVM against libc++ (the LLVM C++ standard library). The project compiles and links against libstdc++ (the GNU C++ standard library).
If I include "/usr/lib/libstdc++.dylib" amongst the Other Linker Flags this resolves most of the issues but leaves one problem:
Undefined symbols for architecture i386:
"__Z21UnityKeyboard_GetTextPSs", referenced from:
__ZNK16KeyboardOnScreen7getTextEv in libiPhone-lib.a(iPhoneKeyboard.o)
It seems to be looking for the method void UnityKeyboard_GetText(std::string* text) as part of Keyboard.mm.
When I dump the symbols for Keyboard.o I get
00002900 T __Z21UnityKeyboard_GetTextPNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
000161c0 S __Z21UnityKeyboard_GetTextPNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE.eh
So the mangled names seem to be incompatible when I use libc++. Is there any possible of way of resolving this issue?

Linker errors when using a c++/Objective C++ library

I am trying to build a static library for iOS. I have 4 C++ classes with Objective-C++ wrappers. It seems to be building fine but when I try to run my unit tests I get a bunch of linker errors similar to the one below. Is there some command I need to add in order to use my library?
(null): "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
edit:
I solved this by adding the libc++.dylib framework to both targets.
A hunch: The library and the unit test targets disagree on which C++ Standard Library they use. Double check the build setting in both targets.
In Xcode 4.6 the setting is found under the heading "Apple LLVM compiler 4.2 - Language"
In Xcode 5 the setting is found under the heading "Apple LLVM 5.0 - Language - C++"
In both cases the setting is named "C++ Standard Library" (duh!) and the two targets should agree on whether they use libstdc++ or libc++.

duplicate symbols when importing c++ file

I have a project in XCode that uses some C++ code (openCV to be exact). One of my files, AdjustVC.mm importing this file (it's called image_processing.mm). Everything works fine. But when I import image_processing.mm in another file, TestVC.mm, I get errors:
ld: 14 duplicate symbols for architecture armv7
It's not a problem about your code base, ld is the tool for the linking phase, most likely you are using your libraries in the wrong way.
you should add more details about the libraries involved in your project or just verify them.

link error __stack_chk_fail (using libs with xcode)

I'm trying to compile a C++ app in xcode using gcc 4.0 and and the 10.4u SDK.
I get the following linker error.
"_stack_chk_fail", referenced from:
_read_frame_ in libAudioDecoder.a(stream_decoder.o)
_read_metadata_ in libAudioDecoder.a(stream_decoder.o)
"_stack_chk_guard", referenced from:
___stack_chk_guard$non_lazy_ptr in libAudioDecoder.a(stream_decoder.o)
(maybe you meant: ___stack_chk_guard$non_lazy_ptr)
ld: symbol(s) not found
Other help threads suggest that all I need to do is add...
-fno-stack-protector
...to the 'Other C Flags', which is what I've done, but the problem persists. I've done cleans, rebuilds and even restarted XCode (because it's been known to get confused sometimes), but the problem persists.
Note that libAudioDecoder is my own library that I'm trying to link with. stream_decoder.o is apart of the FLAC library which libAudioDecoder links to.
Essentially my project links with libAudioDecoder which links with libFlac, where libFlac has also been compile using an xcode project.
For each three xcode projects, I'm using gcc 4.0 and and the 10.4u SDK and have 'Other C Flags' and 'Other C++ Flags' set with -fno-stack-protector.
I'm all out of ideas at the moment, so would appreciate some help with this.
Cheers.
Symbol _stack_chk_fail is referenced from symbol _read_frame_ in your libAudioDecoder.a library, not the Xcode project from which you are linking against libAudioDecoder.a. Try to go back and rebuild libAudioDecoder.a with the -fno-stack-protector flag?
It sounds like you may have compiled the library linking against a newer version of libc and are now compiling with an older version, or some other mismatch like that. Searching for "_stack_chk_fail" on StackOverflow will lead you to a ton of other tips.

additional c++ sources generating errors in Xcode

I have some source written by one of my colleagues in C++. They are stuffs for numerical analysis. I wish them to be included in my Objective-C/Cocoa project. Building seems not to be accomplished... with a kinda error message:
Undefined symbols for architecture x86_64:
"_calcThomas", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm a novice in Xcode or clang. I have a lot of Xcode documentation, and can't find a related one to solve my own. How to achieve my project to work with c++?
Additionally,
The original c++ sources are pure c++ code composed of c++ sources and headers.
They are compiled perfectly in case the project is created only with c++ code template, not with Foundation template.
Thanks hopefully.