XCode 4 & OpenCV Libraries - c++

I've been googling and trying for days to solve my problem I had n luck, so I'm asking my first question here.
I have a MacBook with Lion (1.7.4), Xcode 4.
I need to work on a C++ application made with Leopard and Xcode 3.
The application comes with its own OpenCV.framework and is made for 32-bit Architecture (as u can see in Fig. 1)
I've tried to get it working on Xcode 3, and it works just fine, no need to install OpenCV or stuff (that is because the OpenCV.framework is included in the project, right?).
On Xcode 4 it's not working. That's what I've tried:
Run it "as is": even thought the OpenCV.framework is in the application directory, i get the following error:
dyld: Library not loaded:
#executable_path/../Frameworks/OpenCV.framework/Versions/A/OpenCV
Referenced from:
/Users/fabrizioborgia/Library/Developer/Xcode/DerivedData/suiviGUI-awhilvjpoqatfdansnpqcexpnxaw/Build/Products/Debug/suiviGUI.app/Contents/MacOS/suiviGUI
Reason: image not found
Remove the OpenCV.framework, install OpenCV via MacPorts and link the libraries. Nope, the libraries are 64-bit, and my program is 32. Removed OpenCV AND MacPorts.
Remove the OpenCV.framework, install 32-bit OpenCV via Homebrew (brew install opencv --build32) and link the libraries. Nope, i get the following error, so I assume that the libraries are STILL 64-bit. Right? Removed OpenCV AND Homebrew.
ld: warning: ignoring file
/usr/local/Cellar/opencv/2.4.1/lib/libopencv_calib3d.2.4.1.dylib, file
was built for unsupported file format which is not the architecture
being linked (i386)
Remove the OpenCV.framework, install OpenCV 2.4.1 by myself (with make and stuff) and link the libraries in the project. Nope, if i run the program on 32-bit arch it tells me that the libraries are not for 32-bit arch.
In any case, if I try to run it on 64-bit the compilation is successful but the program doesn't work properly.
Guys, really, I'm out of ideas, maybe I'm on the wrong direction, maybe I just have to find another OpenCV.framework or there is some linking setting that I'm missing, and the program doesn't see the framwork.
Anyone can help?

Solved the problem.
I applied some sort fo "divide et impera approach" and I asked a new question here on SO, you can find it here: 32-bit OpenCV on OS X Lion? Possible? and I found out that MacPorts AND Homebrew AND the Cmake Approach install by default the native architecture (64-bit in my case) OpenCV libraries, I needed the 32-bit, so i followed those steps:
Step 1: Download OpenCV 2.4.0
Step 2: Download and install CMake.
Step 3: Untar the OpenCV package.
Step 4: Make a separate directory inside the OpenCV package for building
mkdir build
cd build
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
(this will force the 32-bit compile)
make -j8
sudo make install
Step 5: Link the brand-new libraries in the Xcode project using the "Link Binary to Libraries" build phase.
Step 6: Hit "Run" :)

I would suggest that you get OpenCV working (if not already) in Lion with XCode 4 (tutorial). Test it with the example in the linked tutorial. Once that works, then copy over the classes you need from the project that you can't get working.
In other words, abandon the older project and rebuild it from a working project base.

Related

Installing C++ Libraries on OS X

I am trying to get my head around some basic concepts, but I can't seem to figure them out.
I am really confused over what it means to install (I think they are called libraries) for C++. I am trying to install OpenCV, but I don't know what needs to happen for it to be installed, how to check, or what really OpenCV is (Is it a library, framework, something else?).
My understanding is that OpenCV (and other libraries/frameworks) is distributed as only the source code so that is is able to work cross-platform. Then, after you download it, you have to build it (I don't know what build means though), and then link your compiler against it so that it can access the files? I don't know how any of this would be done, or really what this means. I think a lot of this is done by CMake, but I don't know what CMake really does, how you would use it, or how you would then utilize the library/framework in your code. Also, where would the libraries like OpenCV be installed, how would clang (or any other compiler/linker) know where to find them, and what kind of files would they be (.a, .dylib, .cpp, .hpp, executables, or a collection of everything)? Is this structure specific to C++ and OS X or is it more widespread?
I am not looking for a tutorial on how to install OpenCV or other libraries, but I am instead trying to learn how that actually works so I won't need tutorials in the future.
Before you can do any C/C++ development work on a Mac, you need to go to the App Store and download Xcode for free - it is Apple's IDE - Integrated Development Environment. Without Xcode, you will have no compiler (i.e. clang or gcc or g++) and no build tools, (i.e. make).
Install Xcode
If you are totally new to Mac, App Store looks like this:
and Xcode looks like this:
Install Command Line Tools
Next you must install Xcode's command-line tools, so start a Terminal - by pressing ⌘+SPACE and starting to type Terminal and when it guesses correctly, just hit Enter/Return. Copy and paste the following into Terminal and hit Enter/Return.
xcode-select --install
The above is called a "Spotlight Search" and is the easiest way to find anything on a Mac.
Install homebrew
Then, if you want to install OpenCV on a Mac, install a package manager such as homebrew which is a matter of copying and pasting a single line from the homebrew website into your Terminal. I will not show the line here in case it ever changes and someone looks at this in a few years, but it is easy to see if you go to the link above.
Find Packages
Then you can find any packages you want with:
brew search opencv # Look for packages called "opencv"
or
brew search boost # Look for "boost" libraries
Install OpenCV
So, for a vanilla (no special options) installation and build of OpenCV do this:
brew install opencv
Remove Packages
You can later remove any packages you no longer want with:
brew rm opencv
Update Packages
You can also update all installed packages with:
brew update && brew upgrade && brew cleanup
Build a Project
Once you have got it installed, you can start compiling and building your own project. It helps if you use the pkg-config package to pick up all the necessary compiler/linker settings you need, so I would suggest:
brew install pkg-config
Now you can compile and link with a really simple command like:
g++ $(pkg-config --cflags --libs opencv) process.cpp -o process
Then you can go on to use Xcode IDE later if you want to once you get started.
Build with Xcode
Once you have got started with basic compilation, you may want to start using Xcode to edit your programs, to do that, you must tell Xcode where the header files are and also where the libraries are and which libraries to link. This will vary with your OpenCV version, but you will need to alter the places marked in the two diagrams below. You will find these easily if you click them in order - green area first, then the yellow, then the blue, then the red.
The actual information that will need to go in the Xcode settings areas I have marked above can be found by running the same pkg-config command I suggested in the previous section. So run:
pkg-config --cflags opencv
to get the location of the header (include) files, and then run
pkg-config --libs opencv
to get the information you need to fill in for the linker in Xcode.

install wx-widgets is driving me insane on Yosemite

I'm on Mac OS X Yosemite 10.10.2. As far as I know, wx-widgets were preinstalled on older versions on OS X (probably that's why google search doesn't help), but that's not the case anymore. I need to get started on a C++ project using wx-widgets, using any IDE (Eclipse, Codelite, or whatever is best). However, I simply cannot get wx-widgets to work. After a workaround I was able to compile on my machine wxWidgets-3.0.2. I called from terminal make and make install, but the libraries seem to not be correctly installed. Indeed, if I create a project on Codelite I get many "wx-config: Command not found" errors. Can someone help me to get me started on installing the libraries and creating a simple project that includes wx-widgets?
I use homebrew which is installed by copying and pasting one line from the homebrew website.
Then, the installation of wxWidgets is simplicity itself with:
brew install wxmac
Any problems, you just call the doctor with
brew doctor
Now you have a proper package manager you can install ImageMagick, GNU Parallel, GNU awk, Oxygen, webkit2html, zeromq, tree, SDL, Redis, sqlitebrowser, pandoc, exiftool, ffmpeg, 7zip, awscli, etc...
You can then compile your wxWidgets programs with
g++ `wx-config --cxxflags` -o sample sample.cpp `wx-config --libs`
I can successfully compile and install wxWidgets on Yosemite with these commands:
- Get the latest sources of wxWidgets 3 from wxwidgets.org and unpack them.
- Move the unpacked directory someplace where you want to keep it.
- Open a terminal and change into the wxwidgets directory.
- Create two directories: build-release and build-debug (don't rename those!)
- Change into wxwidgets/build-release
- Run
../configure --with-osx_cocoa --disable-shared --with-opengl --enable-universal-binary=i386,x86_64 --with-macosx-sdk=/Developer/SDKs/MacOSX10.6.sdk --with-macosx-version-min=10.6
- Run make, then sudo make install
- Change into wxwidgets/build-debug
- Run
../configure --enable-debug --with-osx_cocoa --with-opengl --enable-universal-binary=i386,x86_64 --with-macosx-sdk=/Developer/SDKs/MacOSX10.6.sdk --with-macosx-version-min=10.6
- Run make, then sudo make install
Be aware that these instructions are for compiling against the Mac OS X 10.6 SDK, which I have at /Developer/SDKs/MacOSX10.6.sdk. You can try to omit the --with-macosx-sdk parameter altogether, which will compile using the latest SDK. Also ensure that you have Xcode and the command line developer tools installed.
These commands will install static libraries for the release build and shared libraries for the debug build. You can change this by supplying or omitting the --disable-shared parameter.
The instructions for building and installing wxWidgets are included in the distribution and can also be viewed online.
If your IDE doesn't find wx-config, you must not have the location where you installed it (/usr/local/bin) by default in your PATH. Add it there to fix this.
Like suggested by VZ, you must change your PATH.
But not the variable PATH in your environment Windows but the variable PATH in your C++ project. It's strange but maybe it's different.
Go into (for eclipse) :
C/C++Build->Environment->PATH (add the path of wx-config in the beginning).
Press : Apply, OK and build the project.
I think is strange that Eclipse don't update the PATH after rebooting the OS. Maybe we must add an option to Eclipse for building WxWidget and force Eclipse to update the PATH, but I don't know it.
This change work for me.
Eclipse / MinGW-MSYS / WxWidget 2.8

OpenCV can not find library on launch. Backwards compatibility?

I am trying to build and use a piece of C++ code that uses OpenCV. I am working on Linux, working in Code::Blocks (and the code was originally also developed on a Linux platform using C::B).
I followed this to install OpenCV (Ubuntu 12.04 & OpenCV 2.4.3). The project compiles fine, but when I try to execute it, it crashes on launch, with the following message about how it can not find the library:
(file_address): error while loading shared libraries: libopencv_core.so.2.3:
cannot open shared object file: No such file or directory
Process returned 127 (0x7F) execution time : 0.017 s Press ENTER to continue.
I set all the parameters for the linker according to several Code::Blocks install tutorials.
I also checked in /usr/local/lib/ for my libraries (it is the folder I gave to Code::Blocks' compiler); and while I do have a libopencv_core.so, a libopencv_core.so.2.4 and a libopencv_core.2.4.3, I do not have a libopencv_core.so.2.3.
So I'm wondering what the issue is. Is it about backwards compatibility, i.e. do I have to install the exact same version of OpenCV used to develop the original code? (This would be a bit concerning, since I am trying to make a widely-usable library).
Could I force it to use libopencv_core.so.2.4 instead?
EDIT: I managed to make it work by removing everything and reinstalling with a simple apt-get. Sometimes it's the simplest method that works the best! From now on I'll try to apt-get before following installation tutorials. ;)
Have a nice day!

instructions on building CGAL libraries from source code

I have installed Computational Geometry Algorithms Library 4.3 and followed instructions on CGAL4.3 manual page(http://doc.cgal.org/latest/Manual/installation.html).
After I cmaked CGAL-4.3 folder , it says ,"make # build the CGAL libraries".However I cant find any cmake command or .exe file to execute "make".What am I missing here?
below I copied the instructions on the manual page in case anyone cant access it.
1 Introduction
This document describes how to install CGAL on Windows, Unix-like systems, and MacOS X.
Ideally, setting up CGAL amounts to:
cd CGAL-x.y # go to CGAL directory
cmake . # configure CGAL
make # build the CGAL libraries
You are on windows so you may not have make.
You can either install make or tell Cmake to generate something else than a makefile (like a Visual Studio project for instance).
If you are using Cygwin, it should be pretty easy to install make or maybe you already have it. Try typing make at the Cygwin prompt.
From my limited experience building code on windows, I recommend installing MinGW and Code::Blocks. Then ask Cmake to generate a Code::Blocks project using MinGW. Open the project and build it. Clean and easy.
Note that the CGAL Project provides Installation Instructions for Windows

32-bit OpenCV on OS X Lion? Possible?

I've been googling and trying for days now, trying to figure out how to get 32-bit OpenCV working on OS X Lion, but can just find 64-bit version.
So i have the following questions:
OpenCV libraries come in 32-bit or 64-bit arch, is that correct?
How do I get 32-bit OpenCV working on Lion? I've trying the following ways:
- Install OpenCV via MacPorts: nope, MacPorts installs a 64-bit version.BI removed OpenCV and MacPorts.
Install OpenCV 2.4.1 via Homebrew, using the following command:
brew install opencv --build32
but looks like they are 64-bit too. Removed OpenCV and Homebrew.
Install OpenCV 2.4.1 by myself using standard unix makefiles. Nope, they still look like 64-bit.
I've written "they look like 64-bit" because i have to replace OpenC in a Xcode project made under OS X Snow Leopard, targeted for 32-bit Mac, and I always get tons of errors like:
ld: warning: ignoring file /usr/local/Cellar/opencv/2.4.1/lib/libopencv_calib3d.2.4.1.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
so i suppose that the OpenCV stuff is 64-bit. If i force the project to run in 64-bit, it rubs but doesn't work properly and gets stuck.
Is there a standard way to check if my OpenCV libraries are 64-bit or 32-bit?
Where can i get 32-bit OpenCV?
Solved the problem.
Recap: it is possible to have 32-bit OpenCV libraries on 64-bit Mac OSX Lion.
How?
Step 1: Download OpenCV 2.4.0
Step 2: Download and install CMake.
Step 3: Untar the OpenCV package.
Step 4: Make a separate directory inside the OpenCV package for building
mkdir build
cd build
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
(this will force the 32-bit compile)
make -j8
sudo make install
Step 5: Enjoy!
For forther reference please visit Mac OS X OpenCV Port Page
Thanks all for putting me on the right track:
#karlphilip: I tried to do as you suggested, but without the make options the compile phase fails, because the architectures are incoherent.
#hamstergene: MacPorts got stuck after the new installation, maybe I have some remains of the older install :( (strange, i followed the official instrusctions to remove it).
#Adrien: That's what I've done, but i had to merge 2 approaches :)
I ve had a hard time configuring OpenCv libraries on a number od different OSs. Turns out that the thing is auto-generating a sample project and then bulding business logic inside it.
See the installation instructions here
The web site of the OpenCV project has been significantly upgraded in the last year.
A new tutorial section is avaiable, i was able to install OpenCV on my 32-bit core Mac OS Lion.
A very cool tutorial is also available at Sadeep's Tech Blog, covering an interesting range of details.
Hope this helps!
Here's something you can try: download OpenCV 2.4 sources and edit the CMakeLists.txt in the root directory. Around line 242 you will see:
# ----------------------------------------------------------------------------
# Path for build/platform -specific headers
# ----------------------------------------------------------------------------
set(OPENCV_CONFIG_FILE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/" CACHE PATH "Where to create the platform-dependant cvconfig.h")
add_definitions(-DHAVE_CVCONFIG_H)
ocv_include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR})
below the add_definitions() call, add this one:
add_definitions(-m32)