Problems when building Drake from source with cmake - drake

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!

Related

How do I install clang-format without root privileges and without installing LLVM?

I have clang-format version 3.8.0 (tags/RELEASE_380/final) in my ~/bin folder on a Fedora machine with no root privileges. It works, but it is very old and I'd like to upgrade. I just want the clang-format tool, so I would like to avoid going through the full installation process for LLVM or clang if I can avoid it. I assume I can avoid it, since my old clang-format works without either of those installed. I don't remember how clang-format got in my ~/bin directory, and I can't figure out how to update it.
The first thing I tried was following this post which said I should be able to download a prebuilt binary from this page (I tried http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-linux-gnu-Fedora27.tar.xz), then just set up a symlink to bin/clang-format. This did not work for me. When I type /path/to/bin/clang-format --help I get the error error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory.
The next thing I tried is downloading the clang source code and compiling that with
mkdir build && cd build && CC=$(which gcc) CXX=$(which g++) cmake ..
but when I did I got the error
CMake Error at CMakeLists.txt:36 (message):
llvm-config not found -- LLVM_CONFIG-NOTFOUND
Which I guess means I'd need to install the LLVM to go this route?
Any help getting an updated clang-format (vesion 5.0 at minimum) without root access would be appreciated. Bonus points for minimal installation (i.e. no clang or llvm).
=== EDIT ===
By downloading a bunch of different versions of prebuilt binaries, I've discovered that older versions (<4.0) have clang-formats that work out of the box, but at 4.0 and up give the same error about libtinfo. I guess that means I'll have to live with older versions unless I want to go through a painful installation process.
When you download llvm 6.0, make sure the directory structure is as follows:
llvm
|-->tools
|----->clang
|----> tools
|----> extra
If you just want to build clang-format, then you can cd into
llvm-build-dir/tools/clang/tools/extra/clang-format and then execute make -j8 all
later you can make a symbolic link in your /bin folder

Error while building opencv_contrib opencv 3.0

I wanted to use the "extra" modules, that come as opencv_contrib from here for other functions of opencv 3.0. I followed the instructions as per the page, for building and compiling the modules, but am stuck with this error
Command:
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
Error:
<Skipping the common Cmake statements and going straight to the error>
CMake Error at opencv_contrib/modules/adas/tools/fcw_train/CMakeLists.txt:16 (ocv_include_modules_recurse):
Unknown CMake command "ocv_include_modules_recurse".
-- Configuring incomplete, errors occurred!
I checked the CMakeLists.txt as mentioned in the path and there were other lines of code that had ocv_xxx , thus it was not a rename issue (I thought they misspelt opencv).
This is my folder structure:
Opencv
- build
- opencv_contrib
This is to verify if my CMake command was correct, as I had posted above.
Can you please tell me how to rectify this error?
UPDATE 1
As per a suggestion, I tried,by putting the opencv_contrib folder outside the opencv folder structure. The new structure was like this
-Opencv
- build
-opencv_contrib
and my new command was
cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
the error is still the same.
Fixed it, thanks to this question. From that question, I understood that the value of the argument should be correct, to turn on the build or something like that. So I changed my command from
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
to
cmake -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules .
Plain and simple, without hierarchy information and it worked. Cheers.

OpenCV debug install through Homebrew

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.

Open CV using Cmake

I am working on a harr detecttion project. I want to generate the exe files using the .cpp files that come with Opencv. I am using CMake for it. When I try to do that I am getting an error like this. Don`t know how to solve it.
CMake Error at CMakeLists.txt:7 (ocv_check_dependencies):
Unknown CMake command "ocv_check_dependencies".
Configuring incomplete, errors occurred!
Source link: C:/opencv/apps/haartraining
Destination link: D:/build
Please help me.
I was working on some image processing that involves Haar detection. And i was having a hard time trying to configure with Cmake at first but i finally found manual configuration tutorial with out using Cmake or else. It has helped me a lot and you can get it here. I hope it will work perfect as it worked for me too. Click here -> http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/. The tutorial uses open CV 2.3.1 but it will work perfect for recent versions too with the need for Cmake ore else.If you more questions, hit me up and i will explain.Good luck!
It looks like You need to compile the whole library with build examples option enabled (if You are using windows then I bet You use graphic cmake interface, so it shouldn't be a problem), and then You will find the .exe in bin directory,
or You would need to include OpenCVModule.cmake file found in cmake catalogue to CMake file You are trying to use for the build.
I didn't test the second option myself, but it looks like CMake file You are trying to use does not load all macros needed for it to run, but macros are loaded when the root library CMake file is used.

Are there multiple branches of Glib?

I'm trying to build Firefox from source and I'm getting hung up on some of the requirements.
I'm trying to build libIDL, which requires glib. I got glib built and installed to /usr/local, but when I try and configure libIDL, I get a failure at:
checking for LIBIDL... configure: error: Package requirements (glib-2.0 >= 2.4.0) were not met:
No package 'glib-2.0' found
I used the very latest version of glib that I can find, ftp://ftp.gtk.org/pub/glib/2.20/glib-2.20.3.tar.gz
However, I've also been searching around and am seeing references to libglib-2.0 such as at http://packages.debian.org/search?keywords=libglib2.0-dev
Are there 2 divergent branches of Glib, like a v1 and v2?
You need to install glib-devel in order to have the glib headers exist on your system. Without the headers, autoconf will mark the library as missing.
You installed glib from source which should have worked. The actual problem was most likely with the paths you chose to install into. The autoconf script may not be looking for glib where you installed it, or it may be looking into another directory first and finding an old version.

Resources