Link mono in XCode - c++

I am trying to embed the mono runtime in a C++ OS X console app (Will be used for scripting logic in a home-brew game engine, much like Unity3D). I am using XCode as the IDE and am failing spectacularly at linking the mono libraries. I come from the dark side (Windows) and am new to mac libraries and XCode.
I have successfully built mono and referenced the header folder but get a slew of APPLE-MOCH-O linkers errors no matter what .a I add to the project. I have also successfully built this sample project https://github.com/inkdev/Embedded-Mono-Sample for windows. The mono site on the topic http://www.mono-project.com/Embedding_Mono is confusing and of little use to me.
Help would be hugely appreciated.
EDIT:
If I remember correctly, I followed these commands http://www.mono-project.com/Compiling_Mono_on_OSX and got the source from here: https://github.com/mono/mono/tree/master/mono, and used make and make install. I added the /mono/include... folder to XCode's "Header Search Path" and that resolved all the unfound includes. Under /mono/lib/ I have tried several different *.dynlib files ( drag them into XCode ) but none have worked. libmono-2.0.1.dylib says "..file was built for unsupported file format..", and libmonoboehm-2.0.dylib simply says "...Undefined symbols for architecture x86_64..."

To anyone in the future who wants to compile and link the Mono runtime in XCode, here are the steps I followed.
Grab/Extract the latest *.tar.gz from: http://download.mono-project.com/sources/mono/
Follow these instructions: http://www.mono-project.com/Compiling_Mono_on_OSX
Open up /mono and drag /mono/lib/libmono-X.X.dylib into your XCode project ( Make sure it is adde to target ).
In XCode, select your project, select your target, select Build Settings.
Search for "Header Search Paths" and add: /mono/include/mono-X.X
Use this source code to test it out: https://github.com/inkdev/Embedded-Mono-Sample
You may need to copy /mono/etc/mono/X.X to /mono to fix a runtime error.
All your monos are belong to us now, enjoy.

Related

Using ITK with xcode

I am working on an xcode project that requires me to use ITK (a c++ library), I have went through with the installation of ITK, by doing
ccmake InsightToolkit-4.13.1
and then configuring and generating the files, then runing
make
make install
but I do not know how to import the library into the xcode project, where I get the following error every time I try building it:
'itkImage.h' image file not found
I would like to know how could I import it and share it with other people on different computers.
The #include directive comes with two flavors:
With quotes (#include "file.h")
With ankle brackets (#include <file.h>)
The first usually refers to files relative to your project directory. The second is for system libraries.
You can influence the search path in the project setting:
double-click on the project in the project explorer
Click on Build settings
Click on your target
Click on All to view also hidden options
In the section Search Paths you can then update the header search path to include the absolute path of you rlibrary headers. Attention: you have to do this for the Debug and for the Release builds:
This will solve the error that you have reported.
Remark: be careful, because after this is solved, you could experience some other issues related to the good use of the library, as pointed out by drescherjm in the comments (link about registration of custom classes to the library's fatories if Cmake is not used to compile the project)

Xcode : executable does not find SDL2.framework

I'm trying to create an executable from my SDL2-Project, which will run on any Mac that I send it to.
My Program is written in C++, Xcode9.2
Apparently the way to go in XCode is Project->Archive. This works perfectly fine as long as I execute the product on my mac. On a mac that does not have the SDL2.framework installed under /Library/Frameworks/ it throws following error upon execution:
dyld: Library not loaded: #rpath/SDL2.framework/Versions/A/SDL2
Referenced from: /Users/thomas/Downloads/Chat_Program_Mac v1/Chat_Program 2
Reason: image not found
So this error is not very surprising, as I haven't linked statically (wouldn't know how this works anyways) and obviously the program needs the framework(s) to run.
On Windows you simply put the .dll files in the same folder as the .exe and that works.
Now on mac, putting the frameworks in the same folder as the executable won't change anything.
From my research I know, that in XCode under BuildSettings->"Framework Search Paths" there is the option to tell the compiler where to look for the frameworks.
Someone on this forum answered to a similar question to put ./ as search path and set it to recursive to let the compiler look for the frameworks in the same folder, where the executable is.
This somehow got me closer to the solution. During the build process XCode now looks for the frameworks inside the debug folder and creates the executable without error, while there are no SDL frameworks in /Library/Frameworks/.
EDIT: this does not work for Project->Archive. Even though I put the frameworks into the release folder. (/Users/Tim/Library/Developer/Xcode/DerivedData/Chat_Program-gapnuzuivnylrgbubtywdbzshous/Build/Products/Release)
When I try to run the executable though, the same error appears saying the library couldn't be loaded.
The executable does run though, if I put the frameworks back into /Library/Frameworks/, which tells me there must be an option to tell XCode where the executable has to search for frameworks, that is not the BuildSettings->"Framework Search Paths" of the project.
So how do I tell my executable to look for the framework inside it's own folder?
So here's how I solved my problem:
Goto BuildSettings->All->Linking->Runpath Search Paths
Change to "#loader_path/"
Apparently this changes #rpath in the error message above to the path where the executable is, so the framework(s) can now be put into the same folder as the executable.
Pretty simple actually, maybe I'm an idiot that I had to research a whole day to find this. Maybe it's just very well hidden and kept as secret as possible even on the internet...
Whatever - happy it works now :)

Linking libjpeg to an xCode project for iOS dev

Good evening,
I have been working on a C++ project from someone of my University which I had to improve for my Bachelor thesis. It basically uses the library libjpeg to do some computation resulting in a steganographic process in order to embed a message into a given image.
Now that the C++ code works smoothly, I'd like to create a little iOS app allowing the user to encrypt whatever message he'd like into an image of his choice. So I created an xCode project following this procedure: using c++ in an iOS app
I also found the following file: libjpeg for iOS which allowed me to compile libjpeg for iOS. Since I'm not so sure how to use the framework freshly created and couldn't find anything sufficiently convincing on the internet, I put all the files (.c and .h) of the libjpeg library into my "include" folder where I have my own .hpp.
xCode only throws me the following error:
xCode error
From what I could gather on several posts, I have to modify the build options of my xCode project to link manually the library, so I tried the following:
Other linking flags
Library search path
This wasn't enough to do the trick and I'm still struggling with the same error xCode throws at me. Any help would be very appreciated on how to proceed!
Thanks a lot,
Theo.
Do not add the .c files to your project, add the libjpeg.a file produced by your build to your project. Add the .h files as you are already doing, or edit the project settings to include their containing folder in the search path.
HTH

Dependency library points to device build

I've got an XCode 4 project that has an additional dependency project in it. The dependency project creates a static library I need for the major project.
I'm trying to add the library from the Target->Build Phases->Link Binary With Libraries, choosing the static library in my workspace.
Problem is every time I do that, the build settings "Library Search Paths" is appended a path to the build of the iphoneos build. When I try to compile for simulator, that file is ignored as it not meant for i386 architecture and the build fails.
I've been searching like mad, not understanding what I'm doing differently. Everywhere I look, it seems like XCode should be doing some magic to link simulator with simulator and device with device - But for me it always adds the specific path to either the device or simulator.
(I've tried using two targets to differ them, and that worked, but it's not an ideal solution at all. I have to change 2 targets everytime instead of 1.)
Hope I was understood,
pleeeaaaaase help :)
Oded.
My colleague found the answer eventually -
In XCode 4 the default is to build all projects to a shared building folder. Me being fixated with XCode 3, switched it to the old method in which the build folder is in your project folder.
Turns out switching XCode to build in a single unique place, allowed the magic to happen to and to the corresponding builds be built together. I've been told it's exactly what it's meant for, but have no link to the reference.
XCode Menu -> Preferences -> Locations -> Build Location:
- Place build in derived data location (recommended)
- Unique subfolder
Cheers,
Oded.

installing opencv on windows(W32) to be used with code blocks

i am trying to use opencv library with code blocks(8.02).i have installed opencv2.1.
when i include the headers and link the library its all fine.i have gone through http://opencv.willowgarage.com/wiki/CodeBlocks tutorial as well.but when i compile the project
it reports no error or warning.it just says exit with status 1.
i want to know if anyone who has used opencv with code blocks and can please help me out of this situation.
thanks!!!
I had this exact same problem a couple of weeks ago and couldn't find an answer anywhere !
After messing around with it, I found out exactly how to do it.
1) Compile the library using Cmake. http://www.cmake.org/
2) After your library is compiled you should have two different OpenCV libraries - a compiled one, and a non-compiled one.
3)In Code Blocks, click on Settings (In the File Menu). Under Settings, select Compiler and Debugger.
4)Select the Search Directories tab.Select the compiler tab under search directories. Click Add. Browse to your NON-COMPILED version of the library. In the non-compiled directory, select the include folder. Under the include folder, select OpenCV. Click OK
5)In codeblocks, select the linker tab, which is under the Search Directories tab.. Click on add and this time browse to your COMPILED version of the library. In the compiled directory, select the lib folder and click OK.
6) Go to the linker settings tab in codeblocks. Click Add. Browse to the COMPILED version of the library. In the compiled directory select lib. In the lib folder select all the libraries. Make sure to only select only the dynamic library files (.dylib extention)
7) Codeblocks is setup!
8) Run your project and it should work fine.
Feel free to ask for more help if you are still having problems.