Zaid Amir
Zaid Amir

Reputation: 4775

Running CMake on Amazon Linux

I am trying to build OpenJpeg on an AWS Amazon Linux EC2 instance. I installed cmake and gcc and had no issues during installation. When I try to cmake openjpeg I get the following error:

-- Check if the system is big endian
-- Searching 16 bit integer
CMake Error at /usr/share/cmake/Modules/TestBigEndian.cmake:44 (message):
  no suitable type found
Call Stack (most recent call first):
  CMakeLists.txt:164 (TEST_BIG_ENDIAN)


-- Configuring incomplete, errors occurred!

Checking the error logs it seems CMake is unable to determine the size of integers, shorts and longs. The full error log can be found in this gist

How can I work this out and make CMake work?

Upvotes: 5

Views: 14602

Answers (5)

Wesley Cheek
Wesley Cheek

Reputation: 1696

For Amazon Linux 2023 you can install cMake with dnf: dnf install cmake.

Here's an example of building a Docker image with Amazon Linux 2023 and cMake, for use as an AWS Lambda Function:

FROM public.ecr.aws/lambda/python:3.12
ENV PYTHONDONTWRITEBYTECODE=1

# Install cMake
RUN dnf install -y cmake

# Copy requirements.txt
COPY requirements.txt ${LAMBDA_TASK_ROOT}

# Install the specified packages
RUN pip install --no-cache-dir -r requirements.txt 

# Copy function code
COPY main.py ${LAMBDA_TASK_ROOT}

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "main.lambda_handler" ]

Upvotes: 0

Leandro Barone
Leandro Barone

Reputation: 159

This works in the most recent Amazon Linux image (Nov 2021):

# Install sudo, wget and openssl, which is required for building CMake
yum install sudo wget openssl-devel -y

# Install development tools
sudo yum groupinstall "Development Tools" -y

# Download, build and install cmake
wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
tar -xvzf cmake-3.18.0.tar.gz
cd cmake-3.18.0
./bootstrap
make
sudo make install

Upvotes: 14

bvdb
bvdb

Reputation: 24710

Amazon has a guide: Preparing to Compile Software, which proposes the following command to install a C compiler.

sudo yum groupinstall "Development Tools"

Next, you can download and build Cmake yourself: Install Cmake 3.

wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
tar -xvzf cmake-3.18.0.tar.gz
cd cmake-3.18.0
./bootstrap
make
sudo make install

Note: the last make actually needs sudo.

Upvotes: 23

Zaid Amir
Zaid Amir

Reputation: 4775

Though this does not actually answer why the error was happening but I was able to build OpenJpeg by building CMake from source. So I just removed Cmake which was installed via yum and I believe was 2.8.12. Downloaded the latest CMake3 sources (v 3.10) built Cmake and openjpeg and all my other packages with no issues.

Upvotes: 1

ivanmoskalev
ivanmoskalev

Reputation: 2044

You could try to set up a Docker container to replicate correct environment. This way, you could form a container on your local machine, make sure it all builds on the container environment, and later use this environment on the EC2.

There is a project on Github that provides a Docker image which can be used to compile for Lambda and test stuff locally. Have a look: https://github.com/lambci/docker-lambda

Upvotes: 1

Related Questions