c++sqlitearmv7conan-2

How build library under armv7 with conan2?


I have simple project with SqlLite:

#include <iostream>
#include <sqlite3.h>

int main()
{
    sqlite3 *db;
    int rc = sqlite3_open("test.db", &db);
    if (SQLITE_OK == rc)
    {
        std::cout << "Opened SQLite database successfully! \n";
        std::string sql = "insert into person values(3, 'Bob', 2);";
        int exit = 0; 

        char* messaggeError; 
        exit = sqlite3_exec(db, sql.c_str(), NULL, 0, &messaggeError); 
        if (exit != SQLITE_OK) { 
            std::cerr << "Error insert Table" << std::endl; 
            sqlite3_free(messaggeError); 
        } 
        else
        {
            std::cout << "Table inserted Successfully" << std::endl; 
        }
        sqlite3_close(db);
    }
    else
    {
        std::cout << "Can't open the SQLite database: " << sqlite3_errmsg(db) << "\n";
    }
    return 0;
}

I try to build it under armv7 architecture with conan2 [10 ver.] and sqlite as remote dependency. My conanfile.txt:

[requires]
sqlite3/3.47.1

[generators]
CMakeDeps
CMakeToolchain

CMakeLists.txt:

cmake_minimum_required (VERSION 3.8)

project(TestConan CXX)
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)

find_package(SQLite3 REQUIRED)

add_executable(testConan test_conan.cpp)
target_link_libraries(testConan SQLite::SQLite3)

Output of conan install . --output-folder=build --build="*" --options="*:shared=True":

======== Input profiles ========
Profile host:
[settings]
arch=armv7
build_type=Release
compiler=gcc
compiler.cppstd=14
compiler.libcxx=libstdc++
compiler.version=9
os=Linux
[options]
*:shared=True

Profile build:
[settings]
arch=armv7
build_type=Release
compiler=gcc
compiler.cppstd=14
compiler.libcxx=libstdc++
compiler.version=9
os=Linux


======== Computing dependency graph ========
Graph root
    conanfile.txt: /home/castiel/projects/Conan/conanfile.txt
Requirements
    sqlite3/3.47.1#64c6f07e86823080ce20dea6e61c1a01 - Cache

======== Computing necessary packages ========
sqlite3/3.47.1: Forced build from source
Requirements
    sqlite3/3.47.1#64c6f07e86823080ce20dea6e61c1a01:5f818215bb63e416640abf926f212f7ddda88c8a - Build

======== Installing packages ========

-------- Installing package sqlite3/3.47.1 (1 of 1) --------
sqlite3/3.47.1: Building from source
sqlite3/3.47.1: Package sqlite3/3.47.1:5f818215bb63e416640abf926f212f7ddda88c8a
sqlite3/3.47.1: Copying sources to build folder
sqlite3/3.47.1: Building your package in /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b
sqlite3/3.47.1: Calling generate()
sqlite3/3.47.1: Generators folder: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release/generators
sqlite3/3.47.1: CMakeToolchain generated: conan_toolchain.cmake
sqlite3/3.47.1: CMakeToolchain generated: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release/generators/CMakePresets.json
sqlite3/3.47.1: Generating aggregated env files
sqlite3/3.47.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
sqlite3/3.47.1: Calling build()
sqlite3/3.47.1: Running CMake.configure()
sqlite3/3.47.1: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/src/.."
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- Using Conan toolchain: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: Setting BUILD_SHARED_LIBS = ON
-- The C compiler identification is GNU 9.4.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
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Looking for log in m
-- Looking for log in m - found
-- Looking for system
-- Looking for system - found
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release

sqlite3/3.47.1: Running CMake.build()
sqlite3/3.47.1: RUN: cmake --build "/home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release" -- -j7
[ 25%] Building C object CMakeFiles/sqlite3.dir/src/sqlite3.c.o
[ 50%] Linking C shared library libsqlite3.so
[ 50%] Built target sqlite3
[ 75%] Building C object CMakeFiles/sqlite3-bin.dir/src/shell.c.o
[100%] Linking C executable sqlite3
[100%] Built target sqlite3-bin

sqlite3/3.47.1: Package '5f818215bb63e416640abf926f212f7ddda88c8a' built
sqlite3/3.47.1: Build folder /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release
sqlite3/3.47.1: Generating the package
sqlite3/3.47.1: Packaging in folder /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p
sqlite3/3.47.1: Calling package()
sqlite3/3.47.1: Running CMake.install()
sqlite3/3.47.1: RUN: cmake --install "/home/castiel/.conan2/p/b/sqlit1d7e869180ce4/b/build/Release" --prefix "/home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p"
-- Install configuration: "Release"
-- Installing: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p/lib/libsqlite3.so
-- Installing: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p/include
-- Installing: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p/include/sqlite3.h
-- Installing: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p/include/sqlite3ext.h
-- Installing: /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p/bin/sqlite3
-- Set non-toolchain portion of runtime path of "/home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p/bin/sqlite3" to ""

sqlite3/3.47.1: package(): Packaged 2 '.h' files: sqlite3.h, sqlite3ext.h
sqlite3/3.47.1: package(): Packaged 2 files: sqlite3, LICENSE
sqlite3/3.47.1: package(): Packaged 1 '.so' file: libsqlite3.so
sqlite3/3.47.1: package(): Packaged 1 '.cmake' file: conan-official-sqlite3-variables.cmake
sqlite3/3.47.1: Created package revision ca712d007a1a2224d1bcd4b32cc09fd8
sqlite3/3.47.1: Package '5f818215bb63e416640abf926f212f7ddda88c8a' created
sqlite3/3.47.1: Full package reference: sqlite3/3.47.1#64c6f07e86823080ce20dea6e61c1a01:5f818215bb63e416640abf926f212f7ddda88c8a#ca712d007a1a2224d1bcd4b32cc09fd8
sqlite3/3.47.1: Package folder /home/castiel/.conan2/p/b/sqlit1d7e869180ce4/p
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.filenames' used in: sqlite3/3.47.1
WARN: deprecated:     'cpp_info.names' used in: sqlite3/3.47.1
WARN: deprecated:     'cpp_info.build_modules' used in: sqlite3/3.47.1
WARN: deprecated:     'env_info' used in: sqlite3/3.47.1

======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to /home/castiel/projects/Conan/build
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(SQLite3)
    target_link_libraries(... SQLite::SQLite3)
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: CMakeToolchain: Preset 'conan-release' added to CMakePresets.json.
    (cmake>=3.23) cmake --preset conan-release
    (cmake<3.23) cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake  -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release
conanfile.txt: CMakeToolchain generated: /home/castiel/projects/Conan/build/CMakePresets.json
conanfile.txt: CMakeToolchain generated: /home/castiel/projects/Conan/CMakeUserPresets.json
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
Install finished successfully

From this output I guess that conan try to build sqlite with my system compiler under x86-64:

  -- The C compiler identification is GNU 9.4.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped

Because when I run file to my .so, I got this:

./p/b/sqlit1d7e869180ce4/b/build/Release/libsqlite3.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=ecceb2e5756e9e3bf285262dc3ffb2a15b910576, not stripped

What should I do so that conan can build the library with a right compiler [arm-linux-gnueabihf-gcc]?


Solution

  • I haven't read the documentation very carefully for building under ARMv7. Thanks to @AlanBirtles I read again documentation and found out that forget specify buildenv for building my dependencies:

    [buildenv]
    CC=arm-linux-gnueabihf-gcc-9
    CXX=arm-linux-gnueabihf-g++-9
    LD=arm-linux-gnueabihf-ld