ESP-IDF GNU Scientific Library (GSL)

nicolasgou
Posts: 3
Joined: Thu Sep 15, 2022 6:33 pm

ESP-IDF GNU Scientific Library (GSL)

Postby nicolasgou » Fri Sep 16, 2022 3:46 pm

Hello everyone,

Has anyone tried to compiling/use the C/C++ GNU Scientific Library (GSL) as an external library or component in an ESP-IDF project?

Link GNU Scientific Library (GSL): https://www.gnu.org/software/gsl/

nicolasgou
Posts: 3
Joined: Thu Sep 15, 2022 6:33 pm

Re: ESP-IDF GNU Scientific Library (GSL)

Postby nicolasgou » Mon Sep 26, 2022 2:10 pm

For other folks trying to do the same, I could solve this by adding the entire library as a Prebuilt Component

For reference follow my Project File Structure:
import_prebuilt_ project
-- components
----- gsl
-------- include
----------- <all .h files generated by default GSL build >
-------- lib
----------- libgsl.a
----------- libgslcblas.a
-------- CMakeList.txt
-- main
----- main.c
----- CMakeList.txt
-- CMakeList.txt

creating a custom component with the prebuilt library (code adapted from Jim's Depository [https://jim.studt.net/depository/?timePrefix=2022-04]

gsl/CMakeLists.txt:
  1. # Compiling and Linking the Library
  2. # We have to make the component know where its .h files are
  3. # and where to find its .a file.
  4. # the GSL documentation says that for some functions both lgslcblas and lgsl must be linked in order to work properly
  5. # (https://www.gnu.org/software/gsl/doc/html/usage.html#linking-programs-with-the-library)
  6.  
  7. idf_component_register( INCLUDE_DIRS ${COMPONENT_DIR}/include/gsl )
  8. target_link_libraries( ${COMPONENT_LIB} INTERFACE ${COMPONENT_DIR}/lib/libgsl.a ${COMPONENT_DIR}/lib/libgslcblas.a)
  9.  
  10.  
  11. #
  12. # Declare our external project.
  13. # I believe the BUILD_BYPRODUCTS interacts with the (not sure)
  14. # 'target_link_libraries' above to force this to build.
  15. #
  16. ExternalProject_Add( gsl_build
  17.                      PREFIX ${COMPONENT_DIR}
  18.                      SOURCE_DIR ${COMPONENT_DIR}
  19.                      DOWNLOAD_COMMAND ""
  20.                      CONFIGURE_COMMAND ""
  21.                      BUILD_IN_SOURCE 1
  22.                      BUILD_COMMAND make CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} AR=${CMAKE_AR}
  23.                      INSTALL_COMMAND make CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} AR=${CMAKE_AR} install libdir=${COMPONENT_DIR}/lib includedir=${COMPONENT_DIR}/include
  24.                      BUILD_BYPRODUCTS ${COMPONENT_DIR}/lib/libgslcblas.a ${COMPONENT_DIR}/include
  25.                      BUILD_ALWAYS 1
  26.                      )
  27.  
  28. #
  29. # Get that SOURCE_DIR variable hauled out so I can use it
  30. #
  31. ExternalProject_Get_Property( gsl_build SOURCE_DIR )
  32.  
  33. #
  34. # Make our local 'build' directory get wiped on a Cmake 'clean'
  35. #
  36. set_directory_properties( PROPERTIES ADDITIONAL_CLEAN_FILES "${SOURCE_DIR}")


notes: As there are no source files (SRCS) the library must be linked with INTERFACE attribute. See [https://esp32.com/viewtopic.php?t=15251]

other Links that helped me:
https://esp32.com/viewtopic.php?t=15251
https://github.com/espressif/esp-idf/tr ... t_prebuilt

dallim30
Posts: 22
Joined: Thu Apr 29, 2021 1:35 am

Re: ESP-IDF GNU Scientific Library (GSL)

Postby dallim30 » Tue Nov 14, 2023 2:47 am

Hello.

How should I build esp_gsl to get libgslcblas.a under ESP32-IDF environment?
<esp_gsl>
https://components.espressif.com/compon ... anguage=en

thanks

nicolasgou
Posts: 3
Joined: Thu Sep 15, 2022 6:33 pm

Re: ESP-IDF GNU Scientific Library (GSL)

Postby nicolasgou » Wed Nov 15, 2023 10:58 am

Hi dallim30,

I did not use this "esp_gsl" project to build the GSL lib.

in my case, I used the following repository that contains a copy of the latest stable version of GSL but with a cmake build system:

https://github.com/ampl/gsl


here are some steps that worked for me and my project:
conditions: Linux Environment; cmake, git and the ESP-IDF env already installed in your system.
... -> needs to meet your specific path

0) From a terminal command Clone the above repo:
make sure using the cmake in the context of ESP-IDF tools by:

Code: Select all

. /home/.../esp-idf/export

Code: Select all

git clone https://github.com/ampl/gsl.git --recurse-submodules

1)Check your cmake version installed, must be > 3.4!

Code: Select all

cmake --version
Building the lib without AMPL bindings

2)Inside the cloned repo, create a build directory and move there:

Code: Select all

mkdir build
cd build
3)Initialize the build files with your desired generator: -G"Unix Makefiles" , "Ninja" etc.. defining the variables NO_AMPL_BINDINGS, GSL_DISABLE_TESTS, DOCUMENTATION Forcing the use of ESP32 Toolchain to compiling it to ESP32 architecture.

In my project, I was using the ESP32-s3 so my "DCMAKE_TOOLCHAIN_FILE" parameter was "toolchain-esp32s3.cmake"

Code: Select all

cmake .. -DCMAKE_TOOLCHAIN_FILE=.../esp/esp-idf/tools/cmake/toolchain-esp32s3.cmake -DNO_AMPL_BINDINGS=1 -DGSL_DISABLE_TESTS=1 -DDOCUMENTATION=OFF
NOTE: run the same command above twice , not sure what happens but the first time it fails!!

4)Build the resulting build files accordingly, just run "make"

Code: Select all

make

5)Copy the resulted archives libgslcblas.a ..etc files and include/.h header files to the proper location in order to be used in the your ESP-IDF Project

6) follow the steps in the previous post to add the files library as a Prebuilt Component in your project.

hope it helps!

Who is online

Users browsing this forum: VinayDand and 456 guests