Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when Cross-compiling library for ARMv7l #176

Closed
locnnil opened this issue Jan 12, 2023 · 11 comments
Closed

Error when Cross-compiling library for ARMv7l #176

locnnil opened this issue Jan 12, 2023 · 11 comments

Comments

@locnnil
Copy link

locnnil commented Jan 12, 2023

I'm trying to cross compile the log4cxx lib for an armv7l arch.

Steps to reproduce:

Install the cross tolchain arm-linux-gnueabi

sudo apt install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi binutils-arm-linux-gnueabi

Start some env variables to hold directores

export DIR_TARGET=/data/marthe/usr
export DIR_HOST=$HOME/project/lib/expat

Expat dependency library

wget https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-2.5.0.tar.gz
## Extract the source code
tar -xvf expat-2.5.0.tar.gz
cd expat-2.5.0

Configuring

./configure \
--build=i686-pc-linux-gnu \
--host=arm-linux-gnueabi \
--prefix=$DIR_HOST \
--exec-prefix=$DIR_HOST \
STRIP="/usr/bin/arm-linux-gnueabi-strip" \
AR="/usr/bin/arm-linux-gnueabi-ar" \
CC="/usr/bin/arm-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
CXX="/usr/bin/arm-linux-gnueabi-g++ -march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
CFLAGS="-O3 -fexpensive-optimizations -frename-registers -fomit-frame-pointer" \
CXXFLAGS="-O3 -fexpensive-optimizations -frename-registers -fomit-frame-pointer" \
LDFLAGS="-Wl,--strip-all -Wl,--rpath=$DIR_TARGET/lib -Wl,--dynamic-linker=$DIR_TARGET/lib/ld-linux.so.3 -Wl,-O3 -Wl,--hash-style=gnu -Wl,--as-needed" \
CPP="/usr/bin/arm-linux-gnueabi-gcc -E -march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
CXXCPP="/usr/bin/arm-linux-gnueabi-g++ -E -march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
STRIP="/usr/bin/arm-linux-gnueabi-strip" \
OBJDUMP="/usr/bin/arm-linux-gnueabi-objdump"

make -j4 

make install

Log4cxx instalation

Downloading and extracting source code

wget https://dlcdn.apache.org/logging/log4cxx/1.0.0/apache-log4cxx-1.0.0.tar.gz
tar -xvf apache-log4cxx-1.0.0.tar.gz
cd  apache-log4cxx-1.0.0

Configuring

cmake -Bbuild -H. \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=$HOME/project/lib/log4cxx \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/project/cmake/toolchain-arm-linux-gnueabi.cmake \
  -DBUILD_TESTING=off \
  -DBUILD_SHARED_LIBS=off \
  -DEXPAT_LIBRARY=$HOME/project/lib/expat/lib \
  -DEXPAT_INCLUDE_DIR=$HOME/project/lib/expat/include \
  -G "Unix Makefiles"

Error from configuration step

-- Available appenders:
--   Async Appender .................. : ON
--   ODBC Appender ................... : OFF
--   SMTP Appender ................... : OFF
--   XMLSocketAppender ............... : ON
--   SocketHubAppender ............... : ON
--   SyslogAppender .................. : ON
--   TelnetAppender .................. : ON
--   NTEventLogAppender .............. : OFF
--   OutputDebugStringAppender ....... : ON
--   ConsoleAppender ................. : ON
--   FileAppender .................... : ON
--   RollingFileAppender ............. : ON
--   MultiprocessRollingFileAppender . : OFF
-- Available layouts:
--   HTMLLayout ...................... : ON
--   JSONLayout ...................... : ON
--   PatternLayout ................... : ON
--   SimpleLayout .................... : ON
--   XMLLayout ....................... : ON
--   FMTLayout ....................... : OFF
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:
/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/APR_INCLUDE_DIR
   used as include directory in directory /home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/main/cpp
/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/APR_UTIL_INCLUDE_DIR
   used as include directory in directory /home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/main/cpp

-- Configuring incomplete, errors occurred!
See also "/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/build/CMakeFiles/CMakeOutput.log".
See also "/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/build/CMakeFiles/CMakeError.log".

these are the log files of the errors:

CMakeError.log
CMakeOutput.log

@locnnil locnnil changed the title Error Cross-compiling library Error when Cross-compiling library for ARMv7l Jan 12, 2023
@rm5248
Copy link
Contributor

rm5248 commented Jan 12, 2023

Are you using pkgconfig to compile other code and find the libraries? If I remember correctly you need to set the PKG_CONFIG_PATH and/or PKG_CONFIG_SYSROOT_DIR variables(see also this stackoverflow post).

@locnnil
Copy link
Author

locnnil commented Jan 13, 2023

Currenty to find the libraries and compile the code I'm using the Cmake file toolchain-arm-linux-gnueabi.cmake that points to my toolchain.

This is my toolchain file:

set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)

set(cpu_flags "-march=armv7-a -mfloat-abi=softfp -mfpu=neon")
set(c_cxx_flags " -O2 -fexpensive-optimizations -frename-registers -fomit-frame-pointer -pthread")

set(CMAKE_C_COMPILER   /usr/bin/arm-linux-gnueabi-gcc ${cpu_flags})
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabi-g++ ${cpu_flags})

set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-start-group -lpthread -lm -Wl,-end-group -Wl,--rpath=${target_dir}/lib -Wl,--dynamic-linker=${target_dir}/lib/ld-linux.so.3 -Wl,-O3 -Wl,--hash-style=gnu -Wl,--as-needed")

set(CMAKE_C_FLAGS ${c_cxx_flags})
set(CMAKE_CXX_FLAGS ${c_cxx_flags})
set(CMAKE_STRIP /usr/bin/arm-linux-gnueabi-strip)
set(CMAKE_FIND_ROOT_PATH  /usr/arm-linux-gnueabi)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

I realized that my toolchain file was missing the specification -pthread to tell the compiler that I'm going to use the thread library. Also the linker flag -lpthread but this last is only for the linker and don't map the macros inside the library so I had to use both.

But now I'm with a different error. It's a linking error too saying that:

cannot find -lesmtp

So now I'm going to cross compile libESMTP. But first, is this library realy necessary or just used for some feature? If so, is there an Cmake option where I can disable it?

@rm5248
Copy link
Contributor

rm5248 commented Jan 13, 2023

libESMTP is completely optional.

If it's complaining about that, you likely have it installed on your build system - it is only used if it is found.

The check happens here, perhaps this is not working correctly when cross-compiling.

@swebb2066
Copy link
Contributor

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:
/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/APR_INCLUDE_DIR
used as include directory in directory /home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/main/cpp
/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/APR_UTIL_INCLUDE_DIR

You need to build APR and APR-UTIL with your cross-compiler.

To cross-compile APR you will need a triplet file that locates the tool chain and sets --host and --cache parameters of "./configure".
The .cache file must have been generated on the targeted host using "./configure -C".

@swebb2066
Copy link
Contributor

On reflection, I am not sure I ever successfully build APR and APR-UTIL with a cross-compiler.

What I found works is to use the conan package manager (and a Artifactory server from JFrog). This allows APR and APR-UTIL to be built on the native system and uploaded to the server for use in cross-compilation builds.

The conan package manager can be used to install APR and APR-UTIL from the remote Artifactory server.

@locnnil
Copy link
Author

locnnil commented Jan 15, 2023

libESMTP is completely optional.

If it's complaining about that, you likely have it installed on your build system - it is only used if it is found.

The check happens here, perhaps this is not working correctly when cross-compiling.

So if I just comment this part I will be able to cross-compile successfully? If yes, I'll gonna try it and post here the results.

@rm5248
Copy link
Contributor

rm5248 commented Jan 15, 2023

So if I just comment this part I will be able to cross-compile successfully? If yes, I'll gonna try it and post here the results.

That seems like a good thing to try.

Okay, I'm going to try this! But just one question, did the ./configure -C compiles something on my environment or just use some coreutils and other simple things? Because my target (which is algo my host) environment it's pretty limited. It's a embedded armv7l running with BusyBox.

I have no idea - I have found cross-compiling is hard to setup correctly. If the build scripts are not setup correctly it may not work. In theory, cross-compiling only checks things in the rootfs(e.g. include files, libraries). You may also need to worry about the --sysroot option for GCC.

@locnnil
Copy link
Author

locnnil commented Jan 15, 2023

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:
/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/APR_INCLUDE_DIR
used as include directory in directory /home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/main/cpp
/home/lincoln/cross_compile/source/apache-log4cxx-1.0.0/src/APR_UTIL_INCLUDE_DIR

You need to build APR and APR-UTIL with your cross-compiler.

To cross-compile APR you will need a triplet file that locates the tool chain and sets --host and --cache parameters of "./configure". The .cache file must have been generated on the targeted host using "./configure -C".

Okay, I'm going to try this! But just one question, did the ./configure -C compiles something on my environment or just use some coreutils and other simple things? Because my target (which is also my host) environment it's pretty limited. It's a embedded armv7l running with BusyBox.

@swebb2066
Copy link
Contributor

swebb2066 commented Jan 15, 2023

The autotools ./configure -C does a lot of stuff, including trying to compile some code.

As BusyBox does not support gcc, you will need to hack a cache file generated on some other armv7 machine (say a raspberrypi).

Perhaps you should also look at this old PR

@Zaoui-Douaa
Copy link

how can i build log4cxx with linux arm cortex A9

@rm5248
Copy link
Contributor

rm5248 commented Apr 28, 2023

If you have a specific issue compiling, please create a new issue. Every system is different, but the process of cross-compiling should be similar for all systems.

@rm5248 rm5248 closed this as completed Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants