I'm working on Mac OS and using CLion/Xcode IDEs. I've already read a lot of information about dynamic libraries. Is it possible to link my dylib to the project without writing "include "name_file.h"" on my Macbook? I know if it is possible in Visual Studio on Windows. VS on Mac OS doesn't support C++.
To link a library in XCode, left click the project name in the source panel to the left. At the top click the "Build Phase" tab. You will see a drop down "Link Binary with Library" click the drop down then hit the "+" symbol and locate the dylib. Then compile your code.
Related
Trying to port an example project for a product that uses a static library for iOS 13.2. The library is an "SDK" with the headers and .a and built singularly for "ARM64 Release" for the iPad. The original project, written for iOS 8.1 with VS2017, simply used -llibSomething.a in the "Additional Options" field and that worked. When doing the same in VS2019, the mac reports back that the linker option is ignored and fails to include it in the command that actually builds the application resulting in missing symbols. For the C++ application settings, there are no express linker options in the property page for the project unless I'm missing something--I'm not a big visual studio or iOS person. I know the path to the SDK is correct, the project finds the headers and compiles the sources without any undefined symbols, it just won't seem to link in the library. The biggest issue is that this all has to be done with whatever Visual Studio has to offer. Am I missing a dialog where this reference is supposed to go or is there something in the project.pbxproj that I'm supposed to be modifying?
Wound up answering my own question:
Unload the project
Edit the project.pbxproj
In the XCBuildConfiguration area for your configuration, add an entry for OTHER_LDFLAGS = "-lSomething ";
The list is just space separated, same as on the command line
I'm using a library (Astro.lib) which i've built without problems (i guess this is a release build).
I've also built a project which references the library (it runs as a release exe fine) but i can't debug the project because i get the message 'unable to start program 'Astro.lib'.
If i try to debug the lib then i get the same error, so I guess its something to do with not building for debug my lib but not sure how to modify.
I've tried changing the properties pages using MSDN info but not sure i'm addressing the correct problem. What changes should i make to the properties pages of the library of linking project?
Thanks in advance
I've also built a project which references the library
That's the project you want to debug. You probably just have the wrong project selected as the startup project of your solution. It is marked in bold type in the Solution Explorer window.
Right-click the project that uses the library and select "Set as StartUp Project"
your debug settings are wrong - you're trying to debug the lib, not the exe.
Chances are you've set the library project as the one that is started by the debugger (eg the "startup project" that shows in bold in Visual studio). Change your solution explorer so the main executable project is bold and try again, or right click on it and selecty the appropriate "run in the debugger" option.
Another solution is:
Make sure you have the Solution Explorer view (VIEW->SOLUTION EXPLORER).
Then, right click on SOLUTION at the top, and click EXPLORER.
Under COMMON PROPERTIES->STARTUP PROJECT -> SINGLE STARTUP PROJECT, choose the project that you want VS to execute. Note that this project has the property CONFIGURATION TYPE set as APPLICATION(.EXE). This can b found under the project's properties->CONFIGURATION PROPERTIES->GENERAL.
Hope that helps.
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.
I have been trying to find a guide how to link a static library to my Eclipse CDT project but I was not able to find one. I have tried both with Visual Studio 2010 compiler and MiNGW.
I use Windows and Eclipse Juno 8.1.1 , under Project Settings -> C/C++ Build -> Settings I have something like this :
Lib manager :
Path and symbols:
You have to add the library name without lib and .a in Libraries (-l) and adding the path in Libraries search path (-L).
However, this question is resolved also in this stack.
Also in this site you can find a lot of usefull information and the explanation on how include linking library.
edit
As reported in the documentation:
Q. How do I add a static library file to a project? (Files such as libmtm.a)
A. First you will need to copy the file into your Eclipse project. You can do that by simply dragging it into the project folder in the "Project Explorer" tree in Eclipse.
To link the library (A static library is used similarly to an object file):
Open Project, Properties.
In that dialog select "C++ Build, Settings".
Under the Tool Settings tab choose "Linker" or "MinGW C Linker" or equivalent and under that select "Libraries".
Under "Libraries" press the "Add..." button (the green cross) and write the name of the library without the "lib" prefix and ".a" suffix. e.g. in order to link the library file libmtm.a write "mtm".
Under "Library search path" press the "Add..." button, select workspace and select the project.
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.