I am trying to install OpenCV on my Macbook and I tried following this link:
http://www.learnopencv.com/install-opencv-3-on-yosemite-osx-10-10-x/
However when I try to run a sample code: I get the following error:
g++ -ggdb pkg-config --cflags --libs opencv
ld: library not found for -lcrt1.10.5.o
I looked up a few things online and I arrived at the conclusion that there was a problem with my xcode.
https://software.intel.com/en-us/articles/installing-intel-compilers-for-os-x-pre-requisite-xcode-command-line-tools
However, When I tried to install the required software I got an error saying >>source /opt/intel/bin/iccvars.sh intel64
-bash: /opt/intel/bin/iccvars.sh: No such file or directory
I would really appreciate any recommendations.
I have OpenCV in my mac with yosemite and compiles on xcode command line tools.
I followed the following step
Download the latest version of OpenCV binaries from the repository.
Please install MacPort (from here) on which the OpenCV will be installed.
Install CMAKE on your mac.
cd to your OpenCV folder and create a new directory (eg. on terminal mkdir build) and cd build, that is move to build folder. (I recommend you to use terminal)
On terminal type cmake .. (with is dots)
Next, type: make -j8
type: make install
Now OpenCV is installed in your system.
Next open Xcode with Command line tool installed.
Create a new C++ project
On your Left side plane, where the list of folder content is shown (I dont know the name) but where you will see the file main.cpp. Here right click and create a new group and name it OpenCV Frameworks. Next Right Click on this Group and select Add files and a new dialogue box will appear. Please navigate to your installation file and add all the opencv libraries to this group. you will find it either on /usr/local/lib/ or /opt/local/lib . The libaries has name like libopencvxxx.dylib.. (I Kind of forgot but something with that name)
Next go and add your header and lib path to the compiler.
Thats it.
Please try and if you still cant compile than I will add photo shoots of each step.
Related
I recently moved from the SGI, Sun workstation environment to a Mac. SGI and Sun came with Fortran compilers so I have maybe 100 small f77 codes I wrote over the years for post-processing and analysis of simulated data. I was hoping to get these codes running on my iMac with gfortran. Most of these are very simple codes but I can't get them to compile and execute. I tried starting with the basics and wrote the Hello World code from a gfortran help page. My code, fortran.f is:
program helloworld
print *, "hello world"
end program helloworld
When I tried compiling this according to the example I typed:
gfortran fortran.f
But I keep getting the error message:
FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
This is the same error message I get on my other codes. Can someone tell me what I'm doing wrong? I can't think of a simpler example but I can't seem to get it to work.
When it comes to macOS, I think that building form sources is the best approach you can have. You can achieve that quite easily by downloading and compiling GFortran as part of GCC directly from: https://gcc.gnu.org/wiki/GFortran
However, there are few things you have to take care of:
make sure you have XCode installed, you can get it here
XCode
XCode is free of charge
Make sure you have command line tools
You can get them either from developer.apple.com
Command Line Tools
or directly from XCode. It might be that XCode will tell you to install Command Line Tools upon first execution
In the past, running command like "svn", when Command Line Tools were not installed, also triggered the installation.
Compile GCC
> ./configure --prefix=$HOME/opt/usr/local
> make all
> make install
Alternatively, you can install using macOS package from GFortran
gfortran-6.3-Sierra.dmg
Fully working sample with Fortran based MPI code:
http://www.owsiak.org/running-open-mpi-on-macos/
If your gfortran was installed a long time ago and you have updated macOS since installing, it may need re-installing to get correctly aligned and linked with the latest macOS tools and libraries.
My advice would be to:
uninstall gfortran,
check that Xcode and its command line tools are up-to-date,
re-install gfortran.
Hints for each of those steps follow:
Note that gfortran is a part of GCC - the "GNU Compiler Collection".
If you installed gfortran via homebrew, you can remove it with:
brew rm gcc
You can update Xcode by by going to AppStore and clicking Updates at top-right.
The Xcode Command Line tools include make and git and command-line versions of the compilers. You can install/update the Xcode command line tools with:
xcode-select --install
You can install gfortran with homebrew using:
brew install gcc
When you are finished, you should make sure that your PATH includes /usr/local/bin near the start and that there are no errors when you run:
brew doctor
which is a brilliant utility that checks your homebrew configuration is correct.
All I had to do was change the path.
Initially, my PATH was something like
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Because of this reason, the default assembler (as) was not called which is in the /usr/bin directory.
To enable the call to the right assembler (as), I had to add /usr/bin to the PATH in front of (before) /opt/local/bin, i.e. on a Mac this can be added by editing ~/.bash_profile such that one's $PATH looks like
/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Once edited, execute at your command prompt:
source /etc/bash_profile
This worked for me.
I'm on a mac 10.7.5 trying to work with the OpenCV library in XCode 4.6.2. I'm following this tutorial http://sadeepj.blogspot.co.uk/2012/03/installing-and-configuring-opencv-to.html
So I've downloaded cmake and OpenCV2.3.1 I have written in terminal :
tar xvf OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1
mkdir build
cd build
cmake -G "Unix Makefiles" ..
It all works except at the Unix Makefiles command, where it says CMake Error: Could not create named generator Unix Makefiles..
Anyone know why this is happening or maybe there is another method of getting OpenCV running smoothly in Xcode?
I encourage you to avoid compiling OpenCV by yourself, whenever possible.
You can download the latest OpenCV compiled framework for iOS here, and here you can find some previous versions. To use the framework, just drag the opencv2.framework directory to your XCode project, and you're done.
I'm on mac 10.7.5, using xcode 4.6.2 and working with the OpenCV 2.4.3 library. I went through the process of making the build directory with the cmake files in terminal and did the download.
I added the .dylib files in Xcode and changed the header path, changed C++ Library to libstdc++, but when I compiled I got this error :
ld: library not found for -lopencv_calib3d.2.4.3
clang: error: linker command failed with exit code 1
I have libopencv_calib3d.2.4.3.dylib added in the project so I have no idea what else it needs.Any ideas?
If your "make back-end" is Cmake you should stick to using it. Local config changes in Xcode can "secretly" be overwritten when the cmake is rerun (which for example happens after you make changes to it) creating weird build errors and forcing you to remember all the manual changes you made.
Your problem seems to be that the generated project doesn't seem to know where to look for opencv.
Assuming you installed opencv using macports you should add a line saying
link_directories(/opt/local/lib)
to your CMakeLists.txt. (if you installed it using brew, or compiled it manually just replace /opt/local/lib for /usr/local/lib or the path to your compiled libraries)
Also make sure to link against opencv_calib3d instead of opencv_calib3d.2.4.3 (unless you have a very particular reason for bypassing this, but that usually means that something else is weird in the setup :) )
Final pointer that you might already know of: As you are already using Cmake you should add the libraries to link against using TARGET_LINK_LIBRARIES(...) in Cmake rather than manually adding them in Xcode (referring to my previous argument).
I am trying to build OpenCASCADE on Mac, but I am not having any luck.
I downloaded it from Github in tar.gz, but I am really new to Mac and I am stuck.
Can anybody explain what should be my next step?
(I found some terminal commands what I should use, but I am not familiar with them. So if it is the right way to build OpenCASCADE on Mac please write down the terminal commands with details. Thank you!)
EDIT:
I understood the command line commands now from the link below. I understood it before too, but I was mistaken, because my main problem was, that I didn't had gcc installed (XCode does not installs gcc automatically...). So anyways, now finally I can run the cmake command. It starts but it ends with this:
CMake Error at /Applications/CMake
2.8-9.app/Contents/share/cmake-2.8/Modules/FindX11.cmake:420 (MESSAGE): Could not find X11 Call Stack (most recent call first):
CMakeLists.txt:313 (FIND_PACKAGE)
Anybody have any idea what to do? I tryed to search this too here, and google...and I found some "solutions" but those didn't work for me.
EDIT EDIT:
The solution for the last edit is that Mountain Lion doesn't install X11. So open up an app that uses X11 or Xquartz and it will install automatically.
Unfortunetly it still doesn't work. My next error message is the following after the make command in terminal:
In file included from
/Users/davidbirkas/Documents/tpaviot-oce-6c9a06a/src/AlienImage/AlienImage_X11XWDAlienData.cxx:14:
/Users/davidbirkas/Documents/tpaviot-oce-6c9a06a/inc/Aspect_XWD.hxx:5:12:
fatal error:
'X11/XWDFile.h' file not found
# include
^ 1 error generated. make[2]: * [adm/cmake/TKService/CMakeFiles/TKService.dir/_/_/__/src/AlienImage/AlienImage_X11XWDAlienData.cxx.o]
Error 1 make1:
[adm/cmake/TKService/CMakeFiles/TKService.dir/all] Error 2 make: **
[all] Error 2
Any ideas how to fix this?
Ensure that, together with XCode, you also install the X11 support from Apple's Devtools. Your error message is indicating that it is missing.
FWIW, I have written a blog post about OCC and PythonOCC on Mac some time ago. Maybe you'll find some detailed info there.
http://cad-3d.blogspot.com/2011/10/pythonocc-open-source-interactive-cad.html
In this post, I still talk about using the binary installer, but recent updates to the OCE edition compile usually without problems out-of-the-box, also on OSX (that is NOT the case with the official OpenCASCADE release).
I spent a little time on this and I think I have it. Here is what I did step by step:
Preparation phase:
Installing Xcode (with command line tools) = Apple developer site
// If Xcode doesn't install gcc, than you can still download it from the developer site as Command Line Tools for Xcode.
Installing Cmake (with command line tools) = Google
// You can download it from the official site with a .dmg/.pkg file extension. Easy install.
X11 under Mountain Lion "changed" to Xquartz. Probably it is not installed by default, but it is easy to check it. Just go to the folder "Application" and start the X11 app. If X11/Xquartz is not installed than it will install automatically!
Installing FTGL = MacPorts = Google
// Download MacPorts from their official site, install it with the installer, than write this to the terminal:
sudo port install ftgl
Download OCE and extract it (.OCE-0.9.0.tar.gz file) = https://github.com/tpaviot/oce/wiki/Download
Installing phase:
I. Open Terminal.
II. Run this command
// This will set the proper PATH.
ln -s /opt/X11/include/X11 /usr/local/include/X11
III. Than from the Terminal go to the directory where you extracted the OCE file (the original extracted file name should be: tpaviot-oce-6c9a06a).
IV. Than write these commands:
// You make a build directory to the extracted OCE folder.
mkdir build
cd build
V. After this you give out the cmake command:
cmake -DOCE_INSTALL_PREFIX:PATH=$HOME/OCE \
-DOCE_WITH_FREEIMAGE:BOOL=ON \
-DOCE_WITH_GL2PS:BOOL=ON \
-DOCE_DRAW:BOOL=ON \
..
VI. And at the end the make commands:
make
make install/strip
If you did everything exactly like this, than it should work!
Give OCE a try. Compiling for osx is a walk in the park
Can anyone provide me some detailed guide how to compile OpenCV 2.3.1 on OS X Lion with Xcode?
I'm getting mad about this … I got the source, used cmake to create the Xcode template and tried to build it, but it fails with about 200 errors.
Thanks in advance,
Dom
SOLUTION in my answer post.
Detailed guide how to get OpenCV 2.3.1 up and running under OS X Lion (10.7.2) with Xcode 4.2.1 using MacPorts
EDIT 08/06/2012: This is also working for OpenCV 2.4.1. Just make sure you got the latest version of Xcode and installed the "Command Line Tools" (Xcode -> Preferences -> Downloads -> Command Line Tools).
EDIT 15/08/2012: Tested everything with Mountain Lion ans the current versions of Xcode & OpenCV … it's working :) And you don't have to use the LLVM compiler.
EDIT 16/10/204: Over the last year I abandoned MacPorts and started using brew, which works better for my purposes.
Brew guide
1.) Get the current Version of Brew here.
2.) Make sure brew is ready to us
brew doctor && brew update
3.) Install OpenCV (as of 17/20/2014 v2.4.9)
brew install opencv
4.) Fire up Xcode (as of 17/20/2014 v6.0.1) and open/create your project
5.) Select your target, go to "General" and hit the "+"-Button in the "Linked Frameworks and Libraries"
5.1.) Click "Add Other", hit "/", go to "/usr/local/lib" and add any libopencv_**.dylib you need
6.) Now add "/usr/local/include" to your "Header Search Paths" under "Build Settings" (target still selected)
7.) Finally make sure include OpenCV in your .mm files.
MacPorts guide (maybe outdated)
1.) Get the current Version of MacPorts here. Don't forget to add "/opt/local/(s)bin" to your environment PATH
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
2.) Keep your MacPorts up-2-date:
sudo port -v selfupdate
3.) Install OpenCV 2.3.1 (building with llvm-gcc)
sudo port install opencv configure.compiler=llvm-gcc-4.2
4.) Fire up Xcode and create your project
5.) Select your target, go to "Summary" and hit the "+"-Button in the "Linked Frameworks and Libraries"
5.1.) Click "Add Other", hit "/" and go to "/opt/local/lib"
5.2.) Add any libopencv_**.dylib you need
6.) Now add "/opt/local/include/" to your "Header Search Paths" under "Build Settings" (target still selected)
7.) Finally make sure to have the following lines at the beginning of your .pch file:
#ifdef __cplusplus
#import "opencv2/opencv.hpp"
#endif
Otherwise you'll get some nasty erros like this:
"Non-const static data member must be initialized out of line"
"Statement expression not allowed at file scope"
That's it! Hope it helps :)
Thanks to Vachidrewer, I was able to get OpenCv running on Mavericks.
I did things in a little different order,so here are my notes.
If it isn't installed, install Macports and add it to path.
(I already had it installed)
Use Macports to update itself from the command line
$ sudo port -v selfupdate
Use Macports to install opencv and its dependencies from the command line.
$ sudo port install opencv
If it isn't installed, install xCode. (I already had it installed)
Use xCode to create a C++ Command line project.
Use xCode to verify that the simple hello world C++ program it created works by running it in the xCode IDE.
Modify the main.cpp file created by xCode from the hello world example to the simple opencv example from Vachidrewer.
Notice that xCode editer reports that it can NOT find the header opencv header file.
Add /opt/local/include/ to the project search path and notice that the editer errors go away.
Try to run the program in the xCode IDE and notice that it reports that it can't find the opencv libraries.
Add a group called opencvfrqmework to the project and add /opt/local/lib/libopencv_core.dylib and /opt/local/lib/livopencv_highgui.dylib to the group.
Use the xCode IDE to run the project and notice that a window pops up with half od it darker then the other half.
Have you tried just building it using standard UNIX Makefiles?
Follow this guide, and see if that helps. If you have already downloaded the source code, you probably don't need to do the svn checkout that is suggested. You can probably start with Use CMake to build in section 2.
Hope that helps.
With small changes to #moosgummi answer below steps worked with Xcode 4.6 on Mac OSX 10.7 TEST code is included below.
Installation of OpenCV :
Get the current Version of MacPorts here.
Don't forget to add "/opt/local/(s)bin" to your environment PATH
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Keep your MacPorts up-2-date:
sudo port -v selfupdate
Install OpenCV with mac ports
sudo port install opencv
Configuring Xcode for using OpenCV
Create a new XCode project using the Command Line Utility/Standard Tool template. Name it and select C++
Select Project -> Edit Project Settings. Select the Build tab. Set Configuration to All Configurations
In the Architectures section, double-click Valid Architectures and remove all the PPC architectures if any.
Compiler for C/C++/Objective-C > Apple LLVM compiler 4.2
Language" > "C++ Standard Library", and select "libstdc++ (GNU C++ standard library)"
In the Search Paths section set Header Search Paths to /opt/local/include/
Please choose non-recursive as an option while adding that search path
Close the Project Info window
Select Project -> New Group and create a group called OpenCV Frameworks
With the new group selected, select Project -> Add files to 'Your Project Name'
Press the "/" key to get the Go to the folder prompt. Enter /opt/local/lib
Select libopencv_core.dylib, libopencv_highgui.dylib (you may need to add other library files from this folder to run other code.)
Uncheck Copy Items… and click Add
TEST CODE
Copy this code into your main.cpp file. It should open up a small window that is half shaded.
#include <iostream>
#include <opencv2/opencv.hpp>
int main(int argc, char *argv[])
{
// Open the file.
IplImage *img = cvCreateImage( cvSize(100,200), IPL_DEPTH_8U, 3); //if (!img) {
// printf("Error: Couldn't open the image file.\n");
// return 1;
//}
// Display the image.
cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
cvShowImage("Image:", img);
// Wait for the user to press a key in the GUI window.
cvWaitKey(0);
// Free the resources.
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
After get a lot of errors (segmentation fault etc) I finally get it working. Here is the tutorial:
http://www.guidefreitas.com/installing-opencv-2-4-2-on-mac-osx-mountain-lion-with-python-support