Can not make opencv3 run on Xcode with c++ macOs big sur - c++

I am trying to set up an Xcode c++ project with opencv3, and I set up:
header search paths: /usr/local/Cellar/opencv#3/3.4.12_3/include
library search paths: /usr/local/Cellar/opencv#3/3.4.12_3/lib
other linker flags: the result from pkg-config --cflags --libs /usr/local/Cellar/opencv#3/3.4.12_3/lib/pkgconfig/opencv.pc
But when I import opencv in c++ code, it just doesn't find the opencv.hpp file. I imported it like this:
#include <opencv2/opencv.hpp>
And i can see it in the /usr/local/Cellar/opencv#3/3.4.12_3/include/opencv2 folder. I would appreciate any help..

If this is a not a library provided by the system (it's not I think), you should bundle it with your project by adding it to the Embedded Binaries section of your target's Build Phase. This way, your application, once compiled, will contain that library in its Frameworks folder.
If you don't do that, your compiled application won't run correctly because it will try to use a library that is not present on the computer of your user (so it will probably crash at runtime).
Finally the header search path will change accordingly and you should also ensure that this setting is correctly set :
LD_RUNPATH_SEARCH_PATHS = $(inherited) #executable_path/../Frameworks.

Related

Xcode "ld: library not found" for C++ makefile project

OS: Mac 10.14.6 -- Xcode ver: 11.3.1
I have an external C++ project (that uses an existing makefile to build) that I imported into Xcode, and when I try to build it I get the following error message: ld: library not found for -ljpeg.
Strangely, when I run the same build command ($make all-recursive) from the command line, it builds successfully. I've double-checked and the relevant .dylib files DO exist in /usr/local/lib. From reading around the web it seemed like Xcode build-settings needed library search paths to include the directory where the .dylib files are, so I added LIBRARY_SEARCH_PATHS under target "Build Settings", but that did not solve the problem.
Is there any reason that comes to mind why Xcode's build command would fail but mine wouldn't?
Link should also receive a flag of the form -L<path> which has the path to the jpeg library's parent folder, before the -ljpeg flag.
So add -L/usr/local/lib to the other linker flags build setting and try again.
Easy way to find the correct flags is running pkg-config:
pkg-config --libs libjpeg
-L/usr/local/Cellar/jpeg/9d/lib -ljpeg
If that fails, you can:
Copy the dylib from its original location.
Paste it in a folder #executable_path/../Resources/lib. Create those folders if needed.
Then rebuild.
Most robust way is to pass the full path in -l option, and not break it in two components.

Netbeans library manager

not sure if this is an appropriate question...
Im using netbeans, and have started to play about with gtk-3.0.
In Netbeans library manager I have added the path /usr/include/gtk-3.0. I have tried to compile a simple project which uses one of the gtk header files. It will not compile, states header file not found. I have checked the class path is correct and that the header file is in the specified location. But had no joy. (the headerfile I am using is gtkmm.h)
I then tried putting the same path into the include directories list in project properties, and the program compiles fine.
My question therefore is, does adding the path in netbeans library manager not automatically include it for my program? I thought this was the whole point? I am stuck with having to add my paths to each new project I create? I thought putting them into the library manager would make this unnecessary? I thought this was the whole point of library manager?
The simplest way is to create a NetBeans "project with existing sources". In order to begin you'll need a directory with only two files - a Makefile and one simple C++ program (with empty main function). However, the Makefile must know about the gtkmm. The pkg-config tool is your friend (in Unix/Linux environment). I have following gtkmm-related lines in my Makefile:
GTKMM_VERSION := gtkmm-3.0
CFLAGS += ${shell pkg-config --cflags ${GTKMM_VERSION}}
LDLIBS += ${shell pkg-config --libs ${GTKMM_VERSION}}
Then you'll need to create a new project in NetBeans - choose "C/C++ Project with existing sources" and tell the NetBeans where your directory is located. The NetBeans will find the Makefile automatically and will try to run it.
A good idea is to run the make in this directory even before creation a new NetBeans project - to make sure the Makefile does what you want.

flandmark library in dev c++ for feature point detection

How to include flandmark library in dev c++? I need to find landmark points for eye.
There are no proper example for using flanmark in dev c++. When i included the header files in the project directory i still get linkage error.
it seems that there is still no official support for generating project for dev c++ in CMake. However, you can of course still use it. From your question it is not clear whether you have compiled flandmark library already and now want to create an external project in dev c++ using the library or if you want to compile flandmark library itself using dev c++.
If you have already successfully compiled flandmark and want to use it in external project, then besides setting the include directory and include the header files, you also need to specify linking directory and link flandmark libary to your project. See e.g. the CMakeLists.txt line 65 file for getting the idea what to include and what to link.
In case you want to use dev c++ for compiling the flandmark library, you need to link the OpenCV libraries and includes and specify the include directory with flandmark headers. For the OpenCV on linux works the command:
pkg-config --cflags --libs opencv
at the end of the g++ line.

Using MySQL in XCODE for C++ project

Currently, I have a project in C++ where i have to get a mysql database and ask for tablevalues. I understand that now I have to import the mysql library.
So I do so by going to this site:
MySQL Mac OSX 10.7 (64bit)
Now that I have successfully downloaded the files and imported the include folder and libraries that the folder contains, I get this error in the mysql.driver.h file I imported with the rest of the mysql files in the folder I just recently downloaded ...
#include <boost/scoped_ptr.hpp> // 'boost/scoped_ptr.hpp' file not found
So this is telling me that this templated header file was not found...
Do I need to download the boost library now? I did and imported BOOST into my project but it just gave me more errors...
Anyone ran into this same issue before or can help? :) I'd greatly appreciate it!
EDIT
I also read up on a forum in the mySQL webpage and saw that I would need to add linker flags and header/library search paths? I did this but nothing helped :(
Header Search Paths - /usr/local/mysql/include
Library Search Paths - /usr/local/mysql/lib
Other Linker Flags -lz -lm -lmysqlclient
I am a newbie and had a hard time on getting the C++ connector for mysql to work under Xcode. These are the steps necessary for it to work:
Download the MySQL C connector dmg package and install it. This package installs in /usr/local/mysql-connector.... Rename that folder to mysql. (in order to view the /usr folder in finder click on the GO menu and then on GO TO FOLDER once there type in /usr.)
Download the MySQL C++ connector binary. Uncompress it by double clicking the file. Once the file uncompresses, create a folder named mysqlCPP in /usr/local/ (you will now have a folder named mysql and mysqlCPP). Now copy the folders /include and /lib from the uncompressed C++ connector folder to the mysqlCPP folder you just created.
Download the BOOST library from boost.org. Uncompress the downloaded file and copy the boost directory to /usr/local/. (now you should have /mysql /mysqlCPP /boost directories here. There may be additional system folders DONT DELETE THEM.
Now on XCODE open your project and in Build Settings do the following:
Look for OTHER LINKER FLAGS, double click and add the following: -lz -lm -lmysqlcppconn-static (this builds a static reference and a bigger executable, if you wish to link dynamically you need type -lz -lm -lmysqlcppconn but you MUST COPY THE dynamic library into the EXECUTION directory of the file. Add to all options under OTHER LINKER FLAGS.
Look for HEADER SEARCH PATHS, double click and add the following /usr/local/mysqlCPP/include, /usr/local/mysql/include and /usr/local/ all should be added non-recursive. Don't forget to type in for all inputs Debug, Release, Any Architecture, etc.
Look for LIBRARY SEARCH PATHS, double click and add the following: /usr/local/mysql/lib and /usr/local/mysqlCPP/lib. Don't forget to type in for all inputs Debug, Release, Any Architecture, etc. Now you have both installed Connector-C and Connector-C++.
Look for C++ Standard Library and choose the libstdc++ (GNU C++ standard library)
Now you should be set and ready to compile C++ programs. If you wish to use the C connector instead then you should change the OTHER LINKER FLAGS to: -lm -lz -lmysqlclient. Just try with any of the samples on mysql.com and both connectors should work.
The documentation clearly states boost is required for building the MySQL connector from source
As of MySQL Connector/C++ 1.1.0, the Boost C++ libraries 1.34.0 or
newer must be installed. Boost is required only to build the
connector,
Once you have boost installed, just point to its installation location
Once Boost is installed, tell the build system where the Boost files
are by defining the BOOST_ROOT:STRING option. This can be done when
you invoke CMake. For example:
shell> cmake . -DBOOST_ROOT:STRING=/usr/local/boost_1_40_0

How can I use boost::test with xcode 4 for testing some ios c++ code?

I would like it to operate similarly to how the normal test framework works - if you the tests from the Product->Run tests menu item, the output should appear in the left sidebar window.
I found a guide for using xcode 3 with boost test, but couldn't figure out how to translate those instructions for xcode 4 (if it is even possible).
Finally, I'm building an iPhone application. I could get boost running using the #include <boost/test/included/unit_test.hpp>, however it is pretty slow. Using the standard #include <boost/test/unit_test.hpp> results in link errors due to the library being built for the wrong architecture.
You should build the boost library to a static library ".a" using .configure and make.
According to this:
No special build options or macro definitions are required to build
the static library. Using the Boost.Build system you can build the
static library with the following command from libs/test/build
directory:
bjam [-sTOOLS=] {-sBUILD=boost_unit_test_framework}
This library or libraries and their respective headers need to be added to the project. (Two built versions are needed, one i386 for the simulator and one ARM for devices).
The static library is imported from Link Binary with Libraries in
Build Phases.
Also you need to tell XCode which of these to use, you
can do this by setting contidional build settings in `Build settings-
Library search paths. Above this line is where you add the Header
Search Path to the boost header files.
After this you should be able to include the headers (Added above) in C++ or objective-C++ code of yours. (To make Obj-C files Obj-C++ files you need to change all deppendent .m files to .mm)
If there is a some problems after this, switching Compiler or standard library for C++ in Build Settings might help.