I'm using this C package for numerical integration in several implementations. So far, what I do is copy the associated folder (after downloading the cubature-master in Github) into the same directory of my scripts, include the package as
#include "cubature-master/cubature.h"
and add the corresponding flag when compiling my code. I'm doing all of this locally on my Mac arm64. As suggested in the comments, I compiled the package via CMake and I got these results:
Sebastians-Macbook-Pro:cubature-master surrutiaquir$ cd build Sebastians-Macbook-Pro:build surrutiaquir$ cmake ..
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/surrutiaquir/Software/cubature-master/build Sebastians-Macbook-Pro:build surrutiaquir$ make Scanning dependencies of target cubature [ 33%] Building C object CMakeFiles/cubature.dir/hcubature.c.o [ 66%] Building C object CMakeFiles/cubature.dir/pcubature.c.o [100%] Linking C shared library libcubature.dylib ld: warning: ignoring file CMakeFiles/cubature.dir/pcubature.c.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 ld: warning: ignoring file CMakeFiles/cubature.dir/hcubature.c.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64 [100%] Built target cubature Sebastians-Macbook-Pro:build surrutiaquir$ make install [100%] Built target cubature Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libcubature.dylib
-- Installing: /usr/local/include/cubature.h
I would like to have the package in a single location but I'm not skilled enough to reference that path during the compiling process. My goal is to create a Makefile to deal with all of this. Any guidance would be highly appreciated.
Related
Introduction
Currently, I'm working on a C project with CMake and Googletest.
My project is on a GitHub repo.
Why I execute the test on my local machine I use this command: cmake -B ./build -DCMAKE_BUILD_TYPE=Release. It works.
#MathieuSoysal ➜ /workspaces/Piscine-42 (main) $cmake -B ./build -DCMAKE_BUILD_TYPE=Release
-- Configuring done
-- Generating done
-- Build files have been written to: /workspaces/Piscine-42/build
Problem
And I'm trying to execute it on GitHub Actions. But it does not work.
The Log
Run cmake -B /home/runner/work/Piscine-42/Piscine-42/build -DCMAKE_BUILD_TYPE=Release
cmake -B /home/runner/work/Piscine-42/Piscine-42/build -DCMAKE_BUILD_TYPE=Release
shell: /usr/bin/bash -e {0}
env:
BUILD_TYPE: Release
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:9 (add_subdirectory):
The source directory
/home/runner/work/Piscine-42/Piscine-42/googletest
does not contain a CMakeLists.txt file.
-- Configuring incomplete, errors occurred!
See also "/home/runner/work/Piscine-42/Piscine-42/build/CMakeFiles/CMakeOutput.log".
Error: Process completed with exit code 1.
Question
Does someone know how we can execute this command cmake -B /home/runner/work/Piscine-42/Piscine-42/build -DCMAKE_BUILD_TYPE=Release on GitHub Actions with a linked GitHub repo?
I am trying to compile Deepstream 6.0 Python bindings. My guess it that the issue not related to Deepstream, but to general C/C++ compiling issues:
sudo apt install -y git python-dev python3 python3-pip python3.6-dev python3.8-dev cmake g++ build-essential \
libglib2.0-dev libglib2.0-dev-bin python-gi-dev libtool m4 autoconf automake
sudo apt-get -y install pybind11-dev
git clone https://github.com/NVIDIA-AI-IOT/deepstream_python_apps.git
cd deepstream_python_apps
git checkout v1.1.0
cd bindings
mkdir build
cd build
cmake ..
make
I encounter the error:
ubuntu#ip-x-x-x-x:~/pycharm/libs/deepstream_python_apps/bindings/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/pycharm/libs/deepstream_python_apps/bindings/build
ubuntu#ip-x-x-x-x:~/pycharm/libs/deepstream_python_apps/bindings/build$ make
Scanning dependencies of target pyds
[ 6%] Building CXX object CMakeFiles/pyds.dir/src/pyds.cpp.o
In file included from /home/ubuntu/pycharm/libs/deepstream_python_apps/bindings/include/bind/bindanalyticsmeta.hpp:23:0,
from /home/ubuntu/pycharm/libs/deepstream_python_apps/bindings/src/pyds.cpp:19:
/home/ubuntu/pycharm/libs/deepstream_python_apps/bindings/include/pyds.hpp:22:10: fatal error: pybind11.h: No such file or directory
#include <pybind11.h>
^~~~~~~~~~~~
compilation terminated.
CMakeFiles/pyds.dir/build.make:62: recipe for target 'CMakeFiles/pyds.dir/src/pyds.cpp.o' failed
make[2]: *** [CMakeFiles/pyds.dir/src/pyds.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pyds.dir/all' failed
make[1]: *** [CMakeFiles/pyds.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
If I look for pybind11.h I can find it in:
/usr/include/pybind11/pybind11.h
you need to install the gst-python dependency as stated in the README.
make sure to pull all the git submodules beforehand, otherwise the 3rdparty/gst-python folder might be empty for you.
Windows 10, CMake 3.19.1
Im trying to compile test project with XC8 compiler, CMake and custom toolchain (third party).
Link: Toolchain repository
Toolchains quick guide says to only add two strings at top of my CMakeLists.txt.
So ive got the next CMakeLists.txt:
project(Test)
# set up the Microchip cross toolchain
set(CMAKE_TOOLCHAIN_FILE ./external/cmake-microchip/toolchain.cmake)
# set the default MCU model
set(MICROCHIP_MCU PIC18F97J60)
add_executable(main main.c)
But occasionaly, every time CMake generation output starts with:
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.28.29333.0
-- The CXX compiler identification is MSVC 19.28.29333.0
..... more
And i havent any Makefile in the output folder.
Also im try to run CMake with -G "Unix makefiles". And makefile been generated, with wrong output and any trace of custom toolchain use.
Output been:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
Every CMake generation try, im cleanup the output folder.
Why custom toolchain doesnt starts?
The variable CMAKE_TOOLCHAIN_FILE should be set before the first project() call:
cmake_minimum_required(VERSION <..>)
# set up the Microchip cross toolchain
set(CMAKE_TOOLCHAIN_FILE ./external/cmake-microchip/toolchain.cmake)
project(Test)
# set the default MCU model
set(MICROCHIP_MCU PIC18F97J60)
add_executable(main main.c)
When first project() call is processed, CMake automatically calls the script specified in CMAKE_TOOLCHAIN_FILE.
Note, that preferred way is to not hardcode path to the toolchain in the CMakeLists.txt but pass -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain option to the cmake.
I have tried to build onionlib from sources. I cannot use git on my Debian 8 workstation so I downloaded zip from the github. CMake fails at main CMakeLists.txt:28, 29, 30, etc. with error string sub-command REGEX, mode REPLACE needs at least 6 arguments total to command.
It seems that ONION_VERSION variable is empty. Tried to do git clone on other PC and then copied the whole folder including .git to the target workstation with the same result. Tried to execute .git-version-gen and got output '0.8.123.f6b9d' I also get an empty -- Onion version is during compilation so the version is undefined.
npa#NPA:~/workspace/TMOIP/onion$ sudo sh ./git-version-gen
0.8.123.f6b9d
npa#NPA:~/workspace/TMOIP/onion$ mkdir build
npa#NPA:~/workspace/TMOIP/onion$ cd build
npa#NPA:~/workspace/TMOIP/onion/build$ cmake ..
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:28 (string):
string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
command.
CMake Error at CMakeLists.txt:29 (string):
string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
command.
CMake Error at CMakeLists.txt:30 (string):
string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
command.
-- Onion version is
-- Using epoll as poller
-- Could NOT find GnuTLS (missing: GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR)
-- Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR (missing: GCRYPT_INCLUDE_DIR GCRYPT_LIBRARIES)
Gnutls or gcrypt not found. SSL support is not compiled in.
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
SQLite session support is not compiled in.
-- hiredis client library not found.
Hiredis not found. Redis session support is not compiled in.
-- pthreads found. Threading support is compiled in.
-- Found LibXml2: /usr/lib/i386-linux-gnu/libxml2.so (found version "2.9.1")
-- WebDAV support is compiled in.
No PAM support.
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
libpng not found. No png support.
-- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
libjpeg not found. No jpeg support.
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Found GC library: BOEHM_GC_LIBRARIES-NOTFOUND
-- Could NOT find Boehm_GC (missing: BOEHM_GC_LIBRARIES BOEHM_GC_INCLUDE_DIR)
-- NOT compiling Boehm GC examples
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
curl not found. Some examples wil not be built.
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could NOT find SYSTEMD (missing: SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
Systemd support is not compiled in. Install libsystemd-dev | systemd-devel
md2man-roff NOT found, NOT compiling manpages. Install it via 'gem install md2man'
-- Prepared for packaging
-- Compiling WebDAV support
-- Found include files
CMake Error at src/onion/CMakeLists.txt:107 (SET_TARGET_PROPERTIES):
set_target_properties called with incorrect number of arguments.
-- Found include files onion.hpp;dict.hpp;request.hpp;response.hpp;url.hpp;handler.hpp;extrahandlers.hpp;shortcuts.hpp;exceptions.hpp;listen_point.hpp;http.hpp;https.hpp;mime.hpp
CMake Error at src/bindings/cpp/CMakeLists.txt:10 (SET_TARGET_PROPERTIES):
set_target_properties called with incorrect number of arguments.
CMake Warning at examples/CMakeLists.txt:9 (message):
Oterm without authentication support! May be very unsecure.
CMake Warning at examples/CMakeLists.txt:14 (message):
Some examples are disabled as you dont have PAM: otop, basic, fileserver.
-- jQuery at /usr/share/javascript/jquery/jquery.min.js
-- Using system provided jquery for oterm
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
CMake Warning at examples/CMakeLists.txt:37 (message):
Some examples are disabled as you dont have libpng: mandelbrot
-- Configuring incomplete, errors occurred!
See also "/home/npa/workspace/TMOIP/onion/build/CMakeFiles/CMakeOutput.log".
I figured out that the problem was in CMake call of git-version-gen script. I was able to run it manually but it was not running correctly from the CMake because of some permissions setup of my workstation. The problem gone after it was corrected.
I'm having strange problems with my cmake cross-compiler projects.
My own libraries are found but not the (system) libraries from my toolchain.
Previously I was using KDevelop on debian squeeze machine.
now on my new machine with debian wheezy the configuring fails.
It does not find the system libraries like m or pthread.
On my old machine the following was working perfectly, but I do not remember that I did something special to make this work.
Here is one of my CMakeLists.txt files
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 2.6.36.4)
SET(CMAKE_C_COMPILER arm-angstrom-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER arm-angstrom-linux-gnueabi-g++)
include_directories(../include
../../../sample/include)
project(testmain)
add_executable(testmain
some_c-source-file.c)
set(CMAKE_LIBRARY_PATH ../lib/arm-26/lib
../../../sample/lib/arm-26/lib)
find_library(LIBS_TEST NAMES akku)
find_library(LIBS_M NAMES m)
find_library(LIBS_PTHREAD NAMES pthread )
target_link_libraries(akkumain
${LIBS_TEST}
${LIBS_M}
${LIBS_PTHREAD})
set(CMAKE_C_FLAGS "-Wall -Werror")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O2 -rdynamic")
set(CMAKE_C_FLAGS_RELEASE "-g0 -O0")
set(CMAKE_CXX_FLAGS "-Wall -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O2 -rdynamic")
set(CMAKE_CXX_FLAGS_RELEASE "-g0 -O0")
This is the message displayed when trying to compile using KDevelop: (to repeat myself: this was working on my old machine)
/home/user/testmain/build> /usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug /home/user/testmain/
-- The C compiler identification is GNU 4.3.3
-- The CXX compiler identification is GNU 4.3.3
-- Check for working C compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc
-- Check for working C compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBS_M
linked by target "akkumain" in directory /home/user/testmain
LIBS_PTHREAD
linked by target "akkumain" in directory /home/user/testmain
So LIBS_TEST is found. But not libm or libpthread.
I tried this with different projects: All of my libraries are found, but none of the "system" libraries.
I already tried different things like
set(CMAKE_FIND_LIBRARY_PREFIXES lib )
set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
and some more things I do not remember.
The only thing what IS WORKING is when I specify the directory manually:
find_library(ASTLIBS_M NAMES m PATHS /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib)
After specifying this to my CMakeLists.txt the library is found and I can compile my project without any errors.
BUT: This is not what I want, because I have a LOT of projects and many libraries and I don't want to edit all my CMakeLists.txt... :(
Does anybody know what made my old machine find the system-libs without specifying anything special inside my IDE/CMake files?
Edit:
I just noticed for one of my executables that on Linker stage it throws some errors that it cannot find some symbols from glibc - seems there is something more wrong with my debian wheezy system. - I hope I can figure it out...
Edit:
Maybe I should give a short summary: My code compiles well, but all libraries from my toolchain are not found, but if I add the path to the libs of my toolchain manually it compiles but fails on linker stage.
Have you ever tried using a toolchain file? I also cross-compile to ARM and AVR a LOT and it works very well with no hassle (I also use KDevelop and it works beautifully along with CMake). The main point is specifying the path to your toolchain root filesystem through the CMAKE_FIND_ROOT_PATH variable. Try putting all this in a file, which I usually name after the architecture I'm cross-compiling to (in this case I called it arm-unknown-linux-gnueabi.cmake):
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Linux)
# which C and C++ compiler to use
SET(CMAKE_C_COMPILER arm-unknown-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER arm-unknown-linux-gnueabi-g++)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /home/claudio/TS-7400/rootfs)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
Note the variables CMAKE_FIND_ROOT_PATH_MODE_xxx variables control where CMake will look for binaries, libraries and header files. I usually set PROGRAM to NEVER so it never uses binaries from your cross-architecture root filesystem, since they will not run on your host machine anyway. For libraries and header files BOTH means it will search first your specified ROOT_PATH and then if it doesn't find something it will go through your host machine system dirs.
That way, whenever you want to cross-compile a project all you have to do is to create a build directory (so it doesn't mix your sources with files created during build) and then run cmake from there specifying the toolchain file you want to use (I'm supposing your CMakeLists.txt is together with your toolchain file on the same dir your sources are located - project_sources_dir in my example):
cd project_sources_dir
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../arm-unknown-linux-gnueabi.cmake ..
The whole point of using a toolchain file is that, if you want to compile the exact same project for your host machine, you don't have to change a single line in your CMakeLists.txt. Just run cmake without specifying the toolchain file:
cd project_sources_dir
mkdir build
cd build
cmake ..
and your project is ready for compiling native for your host machine instead. If all that isn't enough, you can look for more details here on CMake Cross Compiling
There are certain default paths where CMake's find_library module searches. If your system libs on your old machine happen to be located in one such place, they will be found without any additional work needing to be done.
However, as your new machine's path to these libs seems to be "/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib", you'll need to tell CMake about this.
One such way, is as you have shown (adding the path explicitly). But in this case, the path is probably specific to just that machine - so you'd be better to only set that path when you invoke CMake on that machine. You can add it to CMAKE_PREFIX_PATH for example:
cmake . -DCMAKE_PREFIX_PATH=/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr
(Note: the path in this case get "lib" appended when find_library is called).
Or if you only want to affect the find_library search paths, and not all find_xxx modules, set CMAKE_LIBRARY_PATH
cmake . -DCMAKE_LIBRARY_PATH=/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/lib