How to build libonion? - c

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.

Related

CMake on GitHub Action with Googletest

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?

Making local C package widely available

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.

cmake issue trying to generate configuration for glfw on windows

im trying to generate the configuration for glfw after cloning the source from https://github.com/glfw/glfw.git . I get an error only on windows (on ubuntu linux i have no issue) . I suspect an issue with my CMake but im not sure.
When I run CMake from the root directory of glfw I get the following error using Cmake 2.8
C:\temp\glfw-master>cmake .
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Using Win32 for window creation
-- Using WGL for context creation
CMake Error at examples/CMakeLists.txt:16 (include_directories):
include_directories given empty-string as include directory.
-- Configuring incomplete, errors occurred!
I then tried upgrading to CMake latest 3.0.1 , I still get the error but with a little more info :
$ cmake .
-- Building for: Visual Studio 11 2012
-- The C compiler identification is MSVC 17.0.61030.0
-- Check for working C compiler using: Visual Studio 11 2012
-- Check for working C compiler using: Visual Studio 11 2012 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Found OpenGL: opengl32
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
-- Found Threads: TRUE
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Using Win32 for window creation
-- Using WGL for context creation
CMake Error at examples/CMakeLists.txt:16 (include_directories):
include_directories given empty-string as include directory.
-- Configuring incomplete, errors occurred!
See also "C:/temp/glfw/CMakeFiles/CMakeOutput.log".
See also "C:/temp/glfw/CMakeFiles/CMakeError.log".
If I check the CMakeError.log it seems to mention missing pthreads (which doesnt make sense to me since this is windows and probably pthreads.h should only be used on posix based OSs)
CheckIncludeFiles.c
CheckIncludeFiles.c(2): fatal error C1083: Cannot open include file: 'pthread.h'
: No such file or directory [C:\temp\glfw\CMakeFiles\CMakeTmp\cmTryCompileExec38
59330081.vcxproj]
Done Building Project "C:\temp\glfw\CMakeFiles\CMakeTmp\cmTryCompileExec38593300
81.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\temp\glfw\CMakeFiles\CMakeTmp\cmTryCompileExec3859330081.vcxproj" (default t
arget) (1) ->
(ClCompile target) ->
CheckIncludeFiles.c(2): fatal error C1083: Cannot open include file: 'pthread.
h': No such file or directory [C:\temp\glfw\CMakeFiles\CMakeTmp\cmTryCompileExec
3859330081.vcxproj]
0 Warning(s)
1 Error(s)
Could anyone shed light on what I might have missed? I tried posting this question in glfw irc and discussion forum but i think its not very active and i am under the gun to get this running. It could also be that i am not getting an answer there because its more related to CMake and my configuration than it is glfw per se.
Thanks!

CMAKE cross compile libraries are not found

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

Problem with using Cmake in sub directories after once using cmake on the entire project

I have a head folder called Tutorial and sub folder called MathFunctions each having one code each
I wrote CMakeLists.txt for both the folders and used cmake in cmd promptand it is working fine.
CMakeLists.txt in head folder has the following:
CMAKE_MINIMUM_REQUIRED ( VERSION 2.6)
PROJECT (Tutorial)
SET (Tutorial_VERSION_MAJOR 1)
SET (Tutorial_VERSION_MINOR 0)
CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
"${PROJECT_BINARY_DIR}/TutorialConfig.h "
)
INCLUDE_DIRECTORIES ("${PROJECT_BINARY_DIR}")
OPTION (USE_MYMATH "Use tutorial provided math implementation" ON)
if (USE_MYMATH)
INCLUDE_DIRECTORIES ("${PROJECT_SOURCE_DIR}/MathFunctions")
ADD_SUBDIRECTORY (MathFunctions)
SET (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)
ADD_EXECUTABLE (Tutorial tutorial.c)
TARGET_LINK_LIBRARIES (Tutorial ${EXTRA_LIBS})
CMakeLists.txt in sub folder has the following:
CMAKE_MINIMUM_REQUIRED ( VERSION 2.6)
add_library (MathFunctions mysqrt.c )
and in command prompt :
C:\home\Tutorial\BUILD>cmake ..
-- Building for: Visual Studio 9 2008
-- Check for working C compiler using: Visual Studio 9 2008
-- Check for working C compiler using: Visual Studio 9 2008 --
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 9 2008
-- Check for working CXX compiler using: Visual Studio 9 2008
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/home/Tutorial/BUILD
Later I made some modifications in MathFunctions.c .I made no changes in Tutorial.c. So i want to re generate make files only for MathFunctions folder. But I am not able to do it. I am getting the following error
C:\home\Tutorial\BUILD>cmake ../MathFunctions
CMake Error: The source "C:/home/Tutorial/MathFunctions/CMakeLists.txt" does not match the source "C:/home/Tutorial/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
I cannot figure out why this error is coming.
Please help
Thanks
OK, I know this is ancient but...had a similar problem, same error message.
There is a command under File on the GUI that cleans out the cache. This did not work the first time but eventually it did. I thrashed around a bit, adding cmake to the user path, reboot, don't know if any of that helped.
I got into trouble initially by trying to run cmake on a CMakeLists.txt that was NOT the root. This error popped up when I tried again with the proper source directory. V3.1.3.
If you have made modifications to a source file which is already in the project, there is no need to relaunch CMake. Just recompile.
Just remove
.externalNativeBuild
folder from your project and sync it again. By doing this you will remove build cache.

Resources