Error installing llvm and clang from source in Linux - clang

I am trying to install clang from source following the instructions as given in http://clang.llvm.org/get_started.html ( Steps 1-4 and 7) in Ubuntu 14.04
Inside the build directory , I ran make which succeeded. I wasn't sure what to do after that , so I ran make install inside the build directory, following which I got this cmake error:
There is no executable named clang in /build/bin folder anyway, but I can find others like clang-check, clang-query, etc. What's going wrong?
PS: My main requirment is to experiment with alpha security checkers of clang analyzer and also write my own checker later.

Related

Using ZMQ on iOS

I am trying to build an iOS app that is exposed to a fairly extensive Rust project, but I am having issues with one of the dependencies in the project. The Rust project has a ZMQ dependency, and while I am able to build the project on my Mac, when I try to incorporate the Rust project I get the following error:
error: failed to run custom build command for `zmq-sys v0.8.3`
Caused by:
process didn't exit successfully: `/Users/lisa/company/project/project_detail/target/debug/build/zmq-sys-16dfc88dff84d855/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=LIBZMQ_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-apple-ios
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_apple_ios
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-ios
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_ios
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-ios
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_ios
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'Unable to locate libzmq:
pkg-config has not been configured to support cross-compilation.
Install a sysroot for the target platform and configure it via
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
cross-compiling wrapper for pkg-config and set it via
PKG_CONFIG environment variable.', /Users/lisa/.cargo/registry/src/github.com-1ecc6299db9ec823/zmq-sys-0.8.3/build.rs:31:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
I am trying to build the appropriate library for the iOS and iOS simulator architectures without relying on pkg-config, but if someone can provide useful instructions for configuring pkg-config for cross-compilation, I am not opposed to it, I just don't know how and can't find any up to date resources.
I have cloned the libzmq project from this github: https://github.com/zeromq/libzmq.git, then navigate into libzmq.
Inside libzmq, I run ./autogen.sh followed by ./configure --prefix [directory location] --target "aarch64-apple-ios", then make and make install.
The above procedure without the --target flag is how I got the project to compile on my Mac in the first place, and with the target flag in place make and make install both complete successfully, but when I try to build the project using PROJECT_DIR="${PWD}/ProjectName" ./ProjectName/build-rust.sh,
I get the previously posted error.
I am following the Swift-Bridge Book (https://chinedufn.github.io/swift-bridge/building/xcode-and-cargo/index.html) to try to load the Rust libraries into Xcode.
One thing to note: In the libzmq git hub, there is a folder called builds/ios/ and inside this folder is what looks to be a build file for all of the iOS archs, but I haven't been able to get the repo to build with that file. I think figuring out how to use the build_ios.sh build file as opposed to the standard build.sh provided might be the answer, but I've tried dropping build_ios.sh where build.sh is, and ./autogen.sh doesn't work, because it complains that it can't find configure.ac, even though this file does exist.

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!

Docker's clang can not update

I tried to compile code to ledger Nano S like there https://ledger.readthedocs.io/en/0/nanos/setup.html and I have a problem. When I run the "make .." command, it says "fno-jump-tables unknown argument". I see that it compiles by clang 3.9 but I download clang's latest version and link env variable to it like in the example. I have tried to download clang 6.0, 7.0, 4.0 and latest.
My question: how to update clang in docker to compile my code without error?
If you follow the guide you mentioned and trying to compile blue-app-helloworld app you should take a look at its Makefile at first. At the 48th and the 60th lines you'll see the path it looks for clang binaries. So, if you want to use different version of clang for the build process you could do the following:
Install clang-4.0 as it's described here. Before that you'll need to pre-install some default packages
Edit the Makefile:
The 48th line should be set to: CLANGPATH := /usr/bin/
The 60th line should be set to: CC := $(CLANGPATH)clang-4.0
Run the build as it's described in the guide by executing:
make BOLOS_ENV=/opt/ledger-blue/ BOLOS_SDK=/home/nanos-secure-sdk
You'll see app.elf and app.hex files in the bin folder.

fatal error: opencv2/xfeatures2d.hpp: No such file or directory

I am trying to build this code:
https://docs.opencv.org/3.2.0/d5/d6f/tutorial_feature_flann_matcher.html
I am using Ubuntu 16.04 with CLion 2017.3 and have OpenCV 3.4 installed.
xfeatures2d.hpp can't be found on the system.
I have looked at many different problems on the internet, but couldn't find a solution.
Any help?
You have to include cmake comiplation flag to opencv OPENCV_EXTRA_MODULES_PATH and set it to the opencv_contrib/modules.
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
Here's what I had to do to compile OpenCV with xfeatures2d:
Download opencv_contrib (I took a release from the releases page). This step is what gives us xfeatures2d.
Unpack the tarball somewhere, e.g., ~/src/opencv_contrib-4.5.5
When configuring OpenCV (the main OpenCV source like opencv-4.5.2) with CMake, add the following option to cmake command line (adjusting the value to be your actual path to the modules subdirectory of the opencv_contrib tarball):
-DOPENCV_EXTRA_MODULES_PATH=$HOME/src/opencv_contrib-4.5.5/modules/
Now just build as you normally would and install.
The above actions gave me the expected file (among others): /usr/include/opencv4/opencv2/xfeatures2d.hpp.

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

Resources