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/
ESP-IDF GNU Scientific Library (GSL)
-
- Posts: 3
- Joined: Thu Sep 15, 2022 6:33 pm
Re: ESP-IDF GNU Scientific Library (GSL)
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:
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
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:
- # Compiling and Linking the Library
- # We have to make the component know where its .h files are
- # and where to find its .a file.
- # the GSL documentation says that for some functions both lgslcblas and lgsl must be linked in order to work properly
- # (https://www.gnu.org/software/gsl/doc/html/usage.html#linking-programs-with-the-library)
- idf_component_register( INCLUDE_DIRS ${COMPONENT_DIR}/include/gsl )
- target_link_libraries( ${COMPONENT_LIB} INTERFACE ${COMPONENT_DIR}/lib/libgsl.a ${COMPONENT_DIR}/lib/libgslcblas.a)
- #
- # Declare our external project.
- # I believe the BUILD_BYPRODUCTS interacts with the (not sure)
- # 'target_link_libraries' above to force this to build.
- #
- ExternalProject_Add( gsl_build
- PREFIX ${COMPONENT_DIR}
- SOURCE_DIR ${COMPONENT_DIR}
- DOWNLOAD_COMMAND ""
- CONFIGURE_COMMAND ""
- BUILD_IN_SOURCE 1
- BUILD_COMMAND make CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} AR=${CMAKE_AR}
- INSTALL_COMMAND make CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} AR=${CMAKE_AR} install libdir=${COMPONENT_DIR}/lib includedir=${COMPONENT_DIR}/include
- BUILD_BYPRODUCTS ${COMPONENT_DIR}/lib/libgslcblas.a ${COMPONENT_DIR}/include
- BUILD_ALWAYS 1
- )
- #
- # Get that SOURCE_DIR variable hauled out so I can use it
- #
- ExternalProject_Get_Property( gsl_build SOURCE_DIR )
- #
- # Make our local 'build' directory get wiped on a Cmake 'clean'
- #
- 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
Re: ESP-IDF GNU Scientific Library (GSL)
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
How should I build esp_gsl to get libgslcblas.a under ESP32-IDF environment?
<esp_gsl>
https://components.espressif.com/compon ... anguage=en
thanks
-
- Posts: 3
- Joined: Thu Sep 15, 2022 6:33 pm
Re: ESP-IDF GNU Scientific Library (GSL)
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:
1)Check your cmake version installed, must be > 3.4!
Building the lib without AMPL bindings
2)Inside the cloned repo, create a build directory and move there:
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"
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"
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!
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
2)Inside the cloned repo, create a build directory and move there:
Code: Select all
mkdir build
cd build
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
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: No registered users and 335 guests