Running libdatachannel over esp32 board - c

I am using esp idf to develop my project. I downloaded libdatachannel in esp folder so now I have 2 directories in esp folder:
esp-idf
libdatachannel
I then updated CMakeLists.txt in the root of my project and added line
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/examples/common_components/protocol_examples_common $ENV{IDF_PATH}/../libdatachannel")
now when I try to build the project I get following callstack
Executing task: ninja
[0/1] Re-running CMake...
-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32 CMake Error at /Users/ayaz/esp/esp-idf/tools/cmake/component.cmake:219 (message):
CMake Warning (dev) at build_properties.temp.cmake:7:
Syntax Warning in cmake code at column 51
Argument not separated from preceding token by whitespace.
Call Stack (most recent call first):
/Users/ayaz/esp/esp-idf/tools/cmake/scripts/component_get_requirements.cmake:3
(include)
This warning is for project developers. Use -Wno-dev to suppress
it.
fatal: not a git repository (or any parent up to mount point
/Volumes)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
set).
CMake Error at /Users/ayaz/esp/libdatachannel/CMakeLists.txt:2
(project):
project command is not scriptable
Call Stack (most recent call first):
/Users/ayaz/esp/esp-idf/tools/cmake/scripts/component_get_requirements.cmake:106
(include)
/Users/ayaz/esp/esp-idf/tools/cmake/scripts/component_get_requirements.cmake:124
(__component_get_requirements)
Call Stack (most recent call first):
/Users/ayaz/esp/esp-idf/tools/cmake/build.cmake:491
(__component_get_requirements)
/Users/ayaz/esp/esp-idf/tools/cmake/project.cmake:378
(idf_build_process) CMakeLists.txt:10 (project)
-- Configuring incomplete, errors occurred! See also "/Volumes/Projects/ESP-Projects/websocket/build/CMakeFiles/CMakeOutput.log".
FAILED: build.ninja
/Users/ayaz/.espressif/tools/cmake/3.20.3/CMake.app/Contents/bin/cmake
--regenerate-during-build -S/Volumes/Projects/ESP-Projects/websocket -B/Volumes/Projects/ESP-Projects/websocket/build ninja: error: rebuilding 'build.ninja': subcommand failed
The terminal process "/bin/zsh '-c', 'ninja '" terminated with
exit code: 1.
PROGRESS SO FAR:
I am having following error while building toolchain
Compiling the CXX compiler identification source file
"CMakeCXXCompilerId.cpp" failed. Compiler:
/Volumes/Extra/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
Build flags: Id flags:
The output was: 1 ld: library not found for -lc++ clang: error: linker
command failed with exit code 1 (use -v to see invocation)
Compiling the C compiler identification source file
"CMakeCCompilerId.c" failed. Compiler:
/Volumes/Extra/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
Build flags: Id flags:
The output was: 1 ld: library not found for -lSystem clang: error:
linker command failed with exit code 1 (use -v to see invocation)
another problem is that esp32 uses xtensa-esp32-elf- compiler where as libdatachannel is getting compiled using Apple Clang. I need to modify sdkconfig so that all includes gets compiled using xtensa-esp32-elf-
# The following four lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
# (Not part of the boilerplate)
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
include($ENV{IDF_PATH}/../libdatachannel/CMakeLists.txt)
include($ENV{ADF_PATH}/CMakeLists.txt)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(websocket_example)

Related

Error with CLion (The C compiler identification is unknown) MacOS Ventura

Today I updated my laptop to Mac OS Ventura and CLion with it. When I opened the project I saw this :
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/ninja -G Ninja -S /Users/nikita/Documents/CLion/untitled -B /Users/nikita/Documents/CLion/untitled/cmake-build-debug
-- The C compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - broken
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"/usr/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/nikita/Documents/CLion/untitled/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/Applications/CLion.app/Contents/bin/ninja/mac/ninja cmTC_6cb20 && [1/2] Building C object CMakeFiles/cmTC_6cb20.dir/testCCompiler.c.o
FAILED: CMakeFiles/cmTC_6cb20.dir/testCCompiler.c.o
/usr/bin/cc -arch arm64 -o CMakeFiles/cmTC_6cb20.dir/testCCompiler.c.o -c /Users/nikita/Documents/CLion/untitled/cmake-build-debug/CMakeFiles/CMakeTmp/testCCompiler.c
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/nikita/Documents/CLion/untitled/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/Users/nikita/Documents/CLion/untitled/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
**Guys, how can I fix it ? **
I don't know how to do this.
I am a beginner in programming with C (
I faced the same issue and it was solved by installing xcode-select and reinstalling cmake with the following commands in the terminal:
xcode-select --install
brew reinstall cmake

Installing Tensorflow Lite with CMake

I am trying to install Tensorflow Lite on Raspberry Pi Zero W. I followed the steps from the official website (https://www.tensorflow.org/lite/guide/build_cmake_arm). But I get the following error message:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc
-- Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_ed1a3/fast && /usr/bin/make -f CMakeFiles/cmTC_ed1a3.dir/build.make CMakeFiles/cmTC_ed1a3.dir/build
make[1]: Entering directory '/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o
/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc -march=armv6 -mfpu=vfp -funsafe-math-optimizations -o CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o -c /home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp/testCCompiler.c
/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc: 1: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc: Syntax error: ")" unexpected
make[1]: *** [CMakeFiles/cmTC_ed1a3.dir/build.make:66: CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o] Error 2
make[1]: Leaving directory '/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_ed1a3/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:44 (project)
Configuring incomplete, errors occurred!
See also "/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeOutput.log".
See also "/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeError.log".
Does anyone know how to fix the problem?
I ran into the same problem like you!
The instructions given at https://www.tensorflow.org/lite/guide/build_cmake_arm?hl=en are not intended to be executed on the Raspberry Pi (at least the last ones).
Let me share, what I'll figured out.
Short answer:
you're trying to run a cross-compile of TensorFlow Lite for an ARM made for x86 platform on an ARM system (your Raspberry Pi). What you're trying to do actually needs to be done on an x86 platform.
(on the top of the tutorial page is a hint: "following instructions have been tested on Ubuntu 16.04.3 64-bit PC (AMD64)" which reveals that the commands have been run on x86)
Some details:
The message ‘Syntax error: "(" unexpected’ probably comes from a shell. Why is a shell trying to execute your binary? Because the kernel tried and gave up. Why did the kernel fail to run the program? Because the executable is not in a supported format -> meant to be run on x86 but was executed on ARM.
https://unix.stackexchange.com/questions/336436/syntax-error-unexpected-when-execute-a-compiled-c-program
With older TensorFlow versions it was possible to compile TF lite on the Raspberry Pi itself via the
./tensorflow-2.4.1/tensorflow/lite/tools/make/download_dependencies.sh /and build_aarch64_lib.sh scripts.
However, this scripts got removed in version 2.8 (or even with an earlier version before). See note in the Readme of the Git: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/make/README.md
Using Python for inference
Unfortunately I have no real solution how to compile / built TensorFlow Lite on the Raspberry itself. I personally ended up using Python (only needed inference) and followed this Tutorial:
https://qengineering.eu/install-tensorflow-2.7-on-raspberry-64-os.html

Flutter C Interop with omp.h on iOS

I'm trying to make a C interop in Flutter in iOS.
The code uses omp.h and when compilling it in Xcode says omp.h not found.
What I've tried:
Install OpenMP library.
Change compiler to GCC in Xcode but didnt find any ways to do that.
Included omp.h manually in code folder.
When included omp.h manually it goes, but now I'm getting this error:
Undefined symbols for architecture x86_64:
"_omp_init_nest_lock", referenced from:
_count_3_initialize in count_3_initialize.o
"_omp_destroy_nest_lock", referenced from:
_count_3_terminate in count_3_terminate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've tried using a dylib but this error appears:
Unhandled Exception: Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, increment): symbol not found)
Anyone have experiencied a problem like that before?
Need more information to know what happened exactly. But what I guess is:
check your library via file command, does it contains x86_64 arch or not.
use __attribute__((used)) to decorate your C function, like:
__attribute__((used)) void increment(){
//...
}
in your case.
Your installed library could be linked against macOS (e.g. installed by brew install libomp), you cannot use the macOS library for iOS or iPhone Simulator to link.
So we need to compile it ourselves:
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/openmp-14.0.6.src.tar.xz
tar -xf openmp-14.0.6.src.tar.xz
cd openmp-14.0.6.src
mkdir -p build
cmake -B build \
-DCMAKE_TOOLCHAIN_FILE=ios.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./build/install \
-DIOS_PLATFORM=OS -DENABLE_BITCODE=1 -DENABLE_ARC=0 -DENABLE_VISIBILITY=0 -DIOS_ARCH="arm64;arm64e" \
-DPERL_EXECUTABLE=$(which perl) \
-DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_OMPT_SUPPORT=OFF -DLIBOMP_USE_HWLOC=OFF
cmake --build build -j 3
cmake --build build --target install
The above would create a static library libomp.a for iOS, if you want a library for Simulator also, you need to set -DIOS_PLATFORM=SIMULATOR and -DIOS_ARCH="x86_64;arm64"
Here's my implementation on creating a OpenMP.xcframework which can support both iOS and iPhone Simulator: https://github.com/flyinghead/flycast/pull/805/

CMake compilation failing on MSYS2

I'm trying to set up CMake for a project I'm working on, and I'm first trying to compile a simple Hello World program in C. I'm using Windows 10 with MSYS2. If I invoke the compiler (GCC) directly in Bash, it compiles fine without warnings or errors and gives an executable as output which prints "Hello, world!" exactly as expected. My problem comes in when I try to use CMake to compile my project. When I run cmake -G Ninja .. to compile my project, it throws this error:
CMake Error at C:/msys64/mingw64/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/msys64/mingw64/bin/cc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/dylanweber/Documents/C-Projects/webapp/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_45340 && [1/2] Building C object CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
C:\msys64\mingw64\bin\cc.exe -o CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj -c testCCompiler.c
/bin/sh: C:msys64mingw64bincc.exe: command not found
ninja: build stopped: subcommand failed.
Notice how it mentions C:msys64mingw64bingcc.exe... there must be some kind of path delineation problem but I've tried setting the CC environmental variable to C:\\msys64\\mingw64\\bin\\gcc.exe and C:/msys64/mingw64/bin/gcc.exe. I have been clearing the CMake caches between runs.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(webapp)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
file(GLOB SOURCES "main/*.c")
add_executable(webapp ${SOURCES})
My code is in a "main" folder which is currently just one "main.c" file, in addition to a build directory used to keep all the temporary files in. The most frustrating part is that CMake was just working an hour ago, and I didn't change anything. What can I do to fix this problem?
The solution was not only installing the MinGW64 version of CMake, but also the MinGW64 version of Ninja as well. Since they have different pathing schemes compared to MSYS, they didn't play well together until they were both on the same POSIX-like platform.

Cross Compile on maxOS fails linking System library (CMake), but other libraries succeed

tl;dr - CMake fails at linker not finding System library with precompiled RaspberryPi toolchain when other libraries work
So I've been fighting this for a few days, asked on the RaspberryPi SO without help, and I believe I'm nearing the end of my journey to get an ARM executable for the RaspberryPi compiled through CMake on macOS Sierra.
Currently, I'm using the pre-compiled RaspberryPi toolchain from this blog, and getting the following results:
macbook:gpsexample alex$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/linuxdev/gpsexample
macbook:gpsexample alex$ make
[ 20%] Linking C executable gpsexample
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [gpsexample] Error 1
make[1]: *** [CMakeFiles/gpsexample.dir/all] Error 2
make: *** [all] Error 2
I've previously had problems linking the m library with the same error, however adding the proper system root fixed that issue. I have a feeling I'm missing another library or directory - however I'm not too sure where.
Below is my CMakeLists.txt (single file only):
cmake_minimum_required(VERSION 3.6.2)
project (gpsexample)
set(CMAKE_SYSROOT "/Volumes/xtools/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/sysroot")
#Enable POSIX Threading
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
#Bring the headers in
include_directories(include)
#Wildcard add all source files in dir
file(GLOB SOURCES "src/*.c")
#Create the target
add_executable(gpsexample ${SOURCES})
#Link the standard math lib to the exec
target_link_libraries(gpsexample m)
Is there somewhere else I should add for a library to get System found? Will I need to download the raw files from the Pi directly and include them in the custom tools directory?
Thanks for all the help.

Resources