additional c++ sources generating errors in Xcode - c++

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.

Related

LLVM symbol lookup difficulties

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

How to fix ncurses? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I'm a mac user, and I'm using the XCode developer tools and using CLion as a compiler. When I try to use ncurses and its functions, specifically getch(), I get the following error.
Undefined symbols for architecture x86_64:
"_stdscr", referenced from:
_main in main.cpp.o
"_wgetch", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
I've tried to go online and reinstall ncurses, but it hasn't fixed anything. I would greatly appreciate any help.
First of all, CLion isn't a compiler. It's an IDEA (integrated development
environment). As I remember using it last time it uses CMake as a build tool. And CMake uses GCC, Clang, MSVC, whatever under the hood.
As you don't post any code sample I will try to guess the problem. Usually
when using ncurses you need to link with it as: -lncurses. For more info you
should look man ncurses on your platform. Also check that you don't forget to include the required header. E.g. on my system it's #include <curses.h>.
How to link with ncurses via CMake

Compiling and using a C++ static library in an objective C iOS app

I've tried literally everything on the planet and am about to pull my hair out...
I'm trying to write and build a static library in C++, and then include and call it from an app in Objective C. Simple enough. I get the following linker error when trying to run the app:
Undefined symbols for architecture armv7:
"spmEstimatorMobile::spmCalculate(double*, double*, double*)", referenced from:
-[RecordViewController outputAccelerationData:] in RecordViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've tried EVERYTHING. The app calling file has the .mm extension, I've made sure the compilers that are set for both the library and the app are the same, I've ensured that I build the library for the same architecture (armv7) that I'm building the app for, I've included the library by adding it in the build phase settings page, I'm compiling all sources when building the library as well, I've tried running lipo etc. to make a universal binary just in case ... I just can't figure this out...
If it helps, this is on XCode 6.2., I'm trying to deploy to my iPhone 5 running iOS 8.1. I've double checked all the deployment targets too.
Any ideas??? Anyone!
EDIT: I'm using STL stuff in the C++ static lib (i.e. vectors, etc.) .. not sure if that makes a difference...

linking error: undefined reference for architecture x86_64 for Xcode 5

For the new OSX 10.9 and Xcode 5 / 5.01, I start to have a problem of linking error when using Qt (4.7), the error msg is like:
ld: '......' in ___.o contains undefined reference for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I double-checked many times and it seems my codes are all correct, and the project has been successfully built many many times before using lower version of XCode (and on other OSs as well).
After I checked many websites, there is no luck how to solve this problem.
So my question is: is there a way to figure out what is exactly the missing "undefined reference" complained by the linker?
We have seen the same problem doing iOS development. For some it went away after turning off link time optimisation for all linked libraries. Make sure that all binary dependencies were built without them as well.
One way of finding the culprit is to list all undefined symbols in an .o file using nm -u. Then eliminating things from common and system libraries like NS* UI*. Then you look at what's left and try to deduce what can be missing.

Why can't I compile SDL on Mac for x86_64 using C++?

I'm running on a Mac Mini, late 2012 (The latest), 64 bit, Intel Core i7 2.3 gHz HyperThreading x86_64, or so says my computer. I'm also using Code::blocks for the time being because help in Xcode (which I would prefer) is even more sparse because I am using C++. That said, programming language of choice is C++, and will eventually expand into Objective-C++, but that's for another day.
The problem is this: I am trying to compile a program that will do I'm not quite sure what yet (it's a template, let's just say it's a game for now.) using SDL 1.2.15, which I have compiled from source on my Mac. (I did try using SDLmain.m and SDL.h, but that was full of Objective-C code, and as I could find no good information on whether I could code in C++ with these on the internet, I gave up.) The source I compiled seems to work just fine, Code::Blocks can compile it's tutorial just fine and it runs ok. However, I cannot seem to get my game template to work. It compiles fine, with no errors or warnings, but the linker does not do the same. Now, I'm really not sure what ld does, I just know that it links together code. (Anyone want to elaborate on that?) When Code::Blocks gets to it's linking step it fails with this message:
-------------- Clean: Debug in PyroLauncher ---------------
Cleaned "PyroLauncher - Debug"
-------------- Build: Debug in PyroLauncher ---------------
Compiling: App.cpp
Compiling: OnCleanup.cpp
Compiling: OnEvent.cpp
Compiling: OnInit.cpp
Compiling: OnLoop.cpp
Compiling: OnRender.cpp
Linking console executable: bin/Debug/PyroLauncher
Undefined symbols for architecture x86_64:
"_SDL_GetError", referenced from:
App::OnInit() in OnInit.o
"_SDL_Init", referenced from:
App::OnInit() in OnInit.o
"_SDL_PollEvent", referenced from:
App::OnExecute() in App.o
"_SDL_Quit", referenced from:
App::OnCleanup() in OnCleanup.o
"_SDL_SetVideoMode", referenced from:
App::OnInit() in OnInit.o
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
Which has me seriously confused. I just know that ld can't find for my native architecture x86_64. If anyone can help me, it would be greatly appreciated.
What I think the solutions may be: (I don't know how to do them, however.)
SDL is not compiled for 64 bit, and therefore cannot be compiled against with 64 bit code.
SDL is compiled for Objective-C, and therefore cannot be used with code in C++.
My code is 32 bit, SDL is 64 bit, and they are not compatible.
Do you understand what is happening here? Your code is calling functions which the linker (ld) can't find.
The two main probabilities are that you either need to include some more files in your project, or that you need to define some macros.
Search through the project for the definition of SDL_GetError() (and the others). If you don't find it, then you need to find the file which declares it and include that.
If you do find it, then it will probably be surrounded by #ifdef XXXX and you will have to define xxxx in your project options (not in your code). Most good IDEs (I use NetBeans, with Cygwin for C+ development) will grey out the then contents of an ifdef if it isn't defined, so you can imemdiately see if that is the case.
Btw, have a look around the SDL website for installation instructions. Alternatively, your download might have a file called "Install" or "Install.txt", and may also have a Makefile. If it does, then in your IDE look for an option Project/New ... from existing makefile.
Hope this helps.
You need to add the files SDLMain.m and SDLMain.h to your project. The SDLMain files contain glue code so SDL code can run on Mac OS X. You also need to link the Cocoa framework to your project. The Mac version of SDL is written in Cocoa so you need to link to Cocoa. Linking the Cocoa framework does not force you to use Objective-C. You can write your game in C++.
If you're looking for information on setting up SDL with Xcode 4, read the following article:
Using SDL with Xcode 4