OpenCV debug install through Homebrew - opencv

I would like to to build and install OpenCV in debug mode on my Mac. I prefer do do this in Homebrew since Homebrew manages everything else in my /usr/local and is able to properly uninstall.
I have edited the Homebrew formula to add -DCMAKE_BUILD_TYPE=DEBUG to the cmake command-line.
But the main challenge now is to keep the source around after the build, or perhaps, copy the source first to a permanent location and do the build from there. I believe this is necessary to be able step into OpenCV in Xcode debugger.
Is there a simple way to do this in Homebrew? If not, are there any examples of custom formulas that do this sort of thing? I'm not very familiar with Ruby so any sample code would be helpful.

Related

Fixing pkg-config using Apple silicon and homebrew

I am working with C++ on an M1 Mac, and I used Time Machine to get my old laptop's data on the new one once I got it. The old laptop was not an Apple silicon MacBook. The problem is that I think this screwed up my homebrew installation, since it changed the default location from /usr/local/Cellar/ to /opt/homebrew/Cellar/ and so now I have two homebrew versions since I installed it again on my new laptop after I got it (since nothing was working with homebrew at first and thought it didn't carry over using Time Machine, oops)
I didn't use homebrew much until recently so I didn't notice, but it has made compiling C++ programs with external libraries very difficult since everything I need is on my new homebrew installation in /opt/homebrew/Cellar/ except pkg-config, which when I call it in a bash script or on the command line points to my old homebrew installation.
For example, I have pugixml in my new installation of homebrew and when I enter pkg-config --libs --cflags pugixml
Package pugixml was not found in the pkg-config search path.
Perhaps you should add the directory containing `pugixml.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pugixml' found
pkg-config finds the libraries in the older homebrew installation just fine
My only alternative is to manually inspect the .pc files in the new homebrew installation and enter the flags in my Makefile. I would prefer not to do this. What's the best way to make sure that pkg-config works correctly? If someone knows how to get the new installation of pkg-config to be used at the command line that would solve all my problems I have right now
edit: I forgot to mention this - when I use the which command and ask which pkg-config it outputs /opt/homebrew/bin/pkg-config. This is sort of confusing since this is the new location
Remove the old (Intel) installation with the official uninstall script.
You have to make it executable with:
chmod +x uninstall.sh
And run it with
./uninstall.sh --path=/usr/local
Then reinstall everything you need on the new M1 version under /opt/homebrew.

Problems when building Drake from source with cmake

I am trying to build and install Drake from source in order to get support for Mosek. I keep running into trouble, however. For the record, I am running macOS Catalina.
Right now my approach has been this:
Clone drake from github to a location on my computer (from https://github.com/RobotLocomotion/drake.git)
Install prereqs
with ./setup/mac/install_prereqs.sh
Run bazel build //... Make a
directory called build and cd build cmake .. and then make
and make install
And in my C++ project, which I build using cmake, I add this to CMakeLists.txt:
link_directories(drakelocation/build/install/lib)
include_directories(drakelocation/build/install/include)
However, when I try to build my project, I get an error that Drake is unable to locate Eigen: 'Eigen/Core' file not found. I was able to work around this by adding:
target_link_libraries(my_lib Eigen3::Eigen) to my CMakeLists.txt
I found this a bit strange, as I expect that Drake includes Eigen when it is built, but at least this made me able to get a bit further.
After this I get a bunch of messages of the type:
no member named 'signbit' in the global namespace
i.e. it seems like Drake suddenly is missing all the standard C++ libraries. I have not yet been able to fix this issue, so this is where I am currently stuck.
Do you have any suggestions, or have you encountered any similar problems before?
Other information:
Using find_package(drake) does not work with my current approach at all (cmake is not able to locate drake-config.cmake). Am I missing something here that is required to make this work? Where does cmake expect libraries to be installed, and how do I install them in that place?
I have also tried skipping the entire bazel build //... step, going directly to the cmake .. step, which did not seem to make any difference.
In between every different build approach I have run bazel clean --expunge to make sure that nothing sticks around from the previous run.
Thanks!
You need to tell CMake where your Drake installation is located:
list(APPEND CMAKE_PREFIX_PATH /absolute/path/to/drakelocation/build/install)
find_package(drake REQUIRED)
add_library(my_lib ...)
target_link_libraries(my_lib drake::drake)
This ensures you have all the necessary compiler and linker flags. Setting the include directory to simply /absolute/path/to/drakelocation/build/install/include is insufficient since it does not contain the include directories of the various dependencies of Drake.
Note that you do not need to call bazel yourself before calling cmake. When you run make install, it will call bazel internally.
Thanks #Jamie that solved the find_package() problem I had.
I still had some trouble with the build. Turns out that there was something wrong with my default SDK path, and that setting "CMAKE_OSX_SYSROOT" according to this: Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace after an update to XCode did the trick.
After this, I got a lot of strange error messages from Eigen, complaining that i.e. MatrixXd was not defined in the namespace 'Eigen'. For some reason, uninstalling it with brew uninstall eigen and then downloading and building eigen from source solved those problems.
It now works!

Installing Wine on Mac OS Catalina. Error: No available formula with the name "wine"

I'm trying to install Wine on my Mac via Brew. I'm using Catalina and just updated brew, installed XQuartz and have Xcode installed. When I type the command "Brew install wine" it returns the following:
Error: No available formula with the name "wine"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
wine was deleted from homebrew/core in commit 82bd38bc:
wine: delete
To show the formula before removal run:
git -C "$(brew --repo homebrew/core)" show 82bd38bc^:Formula/wine.rb
If you still use this formula consider creating your own tap:
https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap
I'm following this tutorial: https://www.davidbaumgold.com/tutorials/wine-mac/
When I run Brew doctor I get the following:
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libtcl8.6.dylib
/usr/local/lib/libtk8.6.dylib
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected header files:
/usr/local/include/fakemysql.h
/usr/local/include/fakepq.h
/usr/local/include/fakesql.h
/usr/local/include/itcl.h
/usr/local/include/itcl2TclOO.h
/usr/local/include/itclDecls.h
/usr/local/include/itclInt.h
/usr/local/include/itclIntDecls.h
/usr/local/include/itclMigrate2TclCore.h
/usr/local/include/itclTclIntStubsFcn.h
/usr/local/include/mysqlStubs.h
/usr/local/include/odbcStubs.h
/usr/local/include/pqStubs.h
/usr/local/include/tcl.h
/usr/local/include/tclDecls.h
/usr/local/include/tclOO.h
/usr/local/include/tclOODecls.h
/usr/local/include/tclPlatDecls.h
/usr/local/include/tclThread.h
/usr/local/include/tclTomMath.h
/usr/local/include/tclTomMathDecls.h
/usr/local/include/tdbc.h
/usr/local/include/tdbcDecls.h
/usr/local/include/tdbcInt.h
/usr/local/include/tk.h
/usr/local/include/tkDecls.h
/usr/local/include/tkPlatDecls.h
Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .pc files:
/usr/local/lib/pkgconfig/tcl.pc
/usr/local/lib/pkgconfig/tk.pc
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected static libraries:
/usr/local/lib/libtclstub8.6.a
/usr/local/lib/libtkstub8.6.a
I'm not sure these warnings has something to do with it.
Thanks in advance!
I was able to build Wine 64 bit from source on macOS Catalina and successfully run Notepad++ 64 bit on it.
My steps were more or less something like that:
Download Wine 4.20 from https://dl.winehq.org/wine/source/4.x/wine-4.20.tar.xz
Extract it
In terminal go to extracted directory
Run: ./configure --enable-win64
It showed that it cannot find some library (I do not remember what exactly) so I installed it with macports (sudo port install name_of_missing_package reported by ./configure)
After I was able to run ./configure --enable-win64 succesfully without errors in terminal run: make
It compiled after more than 30 minutes.
I run it with: ./wine start
It opened windows console and here I was able to cd to Notepad++ 64 bit directory (downloaded from https://notepad-plus-plus.org/repository/7.x/7.0/npp.7.bin.x64.zip note that newest version did not work and throwed some errors about some dll's)
I typed notepad++ to run exe file
It showed some errors about freetype fonts so I installed them with macports and I had to copy them from /opt/X11/lib to /usr/local/lib before wine detected them
After fixing freetype fonts problem I was able to run notepad++
Also you might want to run: sudo spctl --master-disable to disable gatekeeper if you will see some system alerts about loading app from unknown developer.
Also note that instead of ./wine start you can run ./wine explorer for graphical file manager instead of console
Those steps might not be exactly precise, as I'm not sure if I did not miss something but hope it will help someone.
Also note that obviously wine on macOS Catalina will be able to run only some 64 bit windows apps and all 32 bit windows app will not work. I also tested it with IrfanView 64 bit (https://www.fosshub.com/IrfanView.html?dwl=iview453_x64_setup.exe) and it also works fine.
In case you wanted to get wine working for purpose of running 32 bit games then unfortunately it will not work with wine but you can try with virtualbox. You can check https://www.youtube.com/watch?v=3AO8dF0vviQ for some performance improvements tips.
Wine hast been removed from homebrew due to the incompatibility to Macos Catalina
https://discourse.brew.sh/t/issue-with-wine/6188/3
Try using wine64 to run your .exe files after installing wine. The manuals and references don't seem to mention this explicitly.
More Info
I followed the guidance in the wine manual to install using home-brew. After install, I got an error when trying to test the installation like it says in the quickstart.
Install wine-stable using homebrew
brew tap homebrew/cask-versions
brew install --cask --no-quarantine wine-stable
After install, test by opening notepad
wine notepad
zsh: bad CPU type in executable: wine
While uninstalling wine, I noticed one of the linked libraries was called wine64. I immediately reinstalled and tried again using wine64 as the call, as I am using wine on an M1 Mac. This was successful!
You can also use winehelp to get access to more commands that will work with 64bit processor.
Based on https://github.com/Homebrew/homebrew-core/pull/46556#issuecomment-559938873 you can do brew cask install wine-stable on newer version of OS X. And works with recent versions of homebrew since the source version was moved :(
How to install wine on Mac OS Catalina with brew
install homebrew with
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
install xquartz to install wine using brew
brew cask install xquartz
install wine using brew
brew install homebrew/cask-versions/wine-devel
run wine and check the version
wine64 --version
As of Wine 5.0 there is no 32bit support on mac in the official version, but you are able to achieve it via the
Unofficial Wineskin Winery
You can download it from github releases here. And then create a Wineskin with WS11WineCX[64/32]bit19.0.[0/1]. All WS11 versions support Catalina. To use it you also need to turn off the no32exec boot argument. You theoretically can do it by typing:
sudo nvram boot-args="no32exec=0"
into the Terminal while you're logged in but it didn't work out for me, so if you'll have the same problem, reboot into the Recovery mode, in the menubar pick Utilities -> Terminal and type just:
nvram boot-args="no32exec=0"
(without sudo).
Example
To be more exact, to install eg. Steam 32bit, you would:
Install the Unofficiall Wineskin Winery from the provided link
Turn on the 32bit execution boot argument by going into Recovery Mode and entering nvram boot-args="no32exec=0" into the terminal
Open Wineskin, click the '+' sign and scroll down to find the WS11WineCX64bit19.0.1 (the newest version with 64 and 32 bit support, at the time of writing)
Click update/install under the Wrapper Version.
Click Create New Blank Wrapper, name it and click through installation of mono and gecko.
Launch the Wrapper App from Finder. Click Install Software, choose setup executable, and proceed through installation. Then pick the executable from a menu. (In case of steam, Steam.exe)
Note: If you get the "No windows app to open the file"(Like I did) error, click advanced -> configuration and set the Windows EXE to the path to the installer. Then find the place that it has installed in and set that as Windows EXE. Then you can run by clicking Test Run.
Enjoy your windows app, as an .app file!
Hope I helped!

ghostview no longer works after homebrew upgrade of ghostscript

I recently did an update/upgrade with homebrew, and now gv no longer opens any of my .ps files. The Ghostscript error window that comes up says "Unknown device: x11 Error: PostScript interpreter failed in main window".
If I try gs --help, it doesn't list x11 under available devices, and the Default output device is "bbox". I tried uninstalling and reinstalling through homebrew. I tried to reinstall adding "--with-x11" but that throws the error "invalid option: --with-x11" - apparently that's no longer allowed. I've upgraded my command line code through the app store, and tried all of this again - nothing changed. I'm on High Sierra 10.13.3, using Homebrew 2.0.6, ghostscript 9.26_1, and gv 3.7.4.
I'm not a Mac developer so I'm not completely familiar with Homebrew, but it does sound like the package has been built wiithout X11 support. The fact that --help doesn't list the device is pretty clear.
I do notice from the website that in the last 30 days there have been 2 downloads of --with-x11. So possibly they've removed X11 support recently.
The only other thing I can suggest (assuming you are comfortable with compiling yourself) is to get the sources from www.ghostscript.com, untar the source tarball, then in a terminal window, from the 'ghostpdl' directory, execute ./autogen.sh, then when that is complete, execute 'make'.
Assuming you have autotools, gcc and the X11 development package, that should build a version of Ghostscript which includes X support. Looking at the Homebrew forumla, and assuming this has worked for you in the past, I think you should be able to build Ghostscript that way.
You might want to add --disable-cups --disable-compile-inits --disable-gtk --disablefontconfig --without-libidn to the ./autogen.sh command line to mimic the Homebrew formula. I'm not sure why they disable CUPS, but whatever.
Other than that, this isn't really a Ghostscript question as such, you would need to contact whoever handles the Homebrew Ghostscript distribution, which isn't any of the Ghostscript development team.
For those searching for a solution, I've put together a custom Homebrew tap that allows you to easily install GV (commonly called Ghostview, but really a derivative of it):
brew install johnhcc/gs-x11/gv
This will automatically install a version of Ghostscript with X11 enabled in the process (it is a dependency). You can optionally install the dependency by itself, it you want:
brew install johnhcc/gs-x11/ghostscript-x11
The main page is here:
https://github.com/johnhcc/homebrew-gs-x11

How can I make Homebrew and CocoAspell coexist?

After much searching on the Internet, I have never seen a satisfactory answer or explanation to the following problem. I would like to use CocoAspell for system-wide spell-checking on OS X 10.9 (plugs into TexShop, TextMate, etc.), but every time I install it, brew doctor starts throwing the following warnings:
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libaspell.15.1.4.dylib
/usr/local/lib/libpspell.15.1.4.dylib
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .la files:
/usr/local/lib/libaspell.la
/usr/local/lib/libpspell.la
Internet searches have shown that these warnings never seem to lead to any errors, but it seems to me that there must be some way to suppress them. Partly, I like to see the Your system is ready to brew notification, but I'd also like to avoid some sort of "boy crying wolf" situation, where I become accustomed to brew doctor throwing errors.
Is there a way to either:
Install CocoAspell in another location, such that brew doesn't see it
Hide the offending dylib and .la files from brew doctor
Or enable the CocoAspell preference pane/program to access libraries installed by a brewed version of aspell
Uninstalling CocoAspell and trashing the offending files results in a clean bill of health, and performing brew install aspell results in a working version of aspell, but this doesn't help me with any of the GUI applications I prefer for LaTeX editing.
Uninstall cocoAspell completely if you installed it before.
Install aspell with homebrew or any other package manager. Don't forget the dictionaries you need. I wanted English and Czech, so I used
brew install aspell --with-lang-cs --with-lang-en
Install only the preference pane of cocoAspell. Click on "Customize" before installing and only select the "Spelling" option.
Create the directory /Library/Application Support/cocoAspell/
Make a symlink in the directory to make the preference pane aware of the available dictionaries (as the administrator):
cd /Library/Application\ Support/cocoAspell/
ln -s /usr/local/lib/aspell-0.60 Dictionaries
Make sure that /usr/local/lib/aspell-0.60 is the correct path.
The cocoAspell pref pane now shows the installed dictionaries.
Add the offending files to the white_list in doctor.rb. Mine was in /usr/local/Library/Homebrew/cmd/doctor.rb
If your's isn't there, find it with
locate doctor.rb
Look for white_list in side of def check_for_stray_dylibs, mine was on line 105. It should probably look like this.
white_list = {
"libfuse.2.dylib" => "MacFuse",
"libfuse_ino64.2.dylib" => "MacFuse",
"/usr/local/lib/libTrAPI.dylib" => "TrAPI"
}
An alternative is to install Homebrew somewhere other than /usr/local (that is, create ~/.homebrew, or /Tools/homebrew; then sudo chmod $USER /Tools/homebrew, untar Homebrew there, and add /Tools/homebrew/bin to your $PATH). That way, /usr/local is reserved for things you're installed there by some other means, rather than using Homebrew; for example the situation you describe here. Homebrew still occasionally whines about it, but you can usually ignore it.
I use Homebrew as my principal OS X package manager; I don't let it anywhere near /usr/local.
Note that this advice is the direct opposite of Homebrew's insistent dogma, which I myself find unpersuasive.

Resources