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

can't execute cross-compile and static link together, ubuntu to arm7 #1264

Open
Aricsa opened this issue Jan 9, 2025 · 0 comments
Open

can't execute cross-compile and static link together, ubuntu to arm7 #1264

Aricsa opened this issue Jan 9, 2025 · 0 comments

Comments

@Aricsa
Copy link

Aricsa commented Jan 9, 2025

Description

Hi. Im trying to set environment for application which runs at arm7.
It builds well when only cross-complie using .so
But if I put the option -DBUILD_SHARED_LIBS=OFF for static link when I install opencv, there are lots of error swarm almost undefined errror.

error.txt

I just wonder about the gocv latest release version supports cross compile(ubuntu to arm7) and static link at the same time.

Im confused Im doing right way..
Any advice may rescue me, welcome any easier way for cross-compile, static link for arm7.

Steps to Reproduce

1.install all dependency

sudo apt-get install -y unzip wget build-essential cmake curl git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libharfbuzz-dev libfreetype6-dev
sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf

2.install opencv

curl -Lo opencv.zip https://github.com/opencv/opencv/archive/refs/tags/4.10.0.zip
unzip -q opencv.zip
curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.10.0.zip
unzip -q opencv_contrib.zip
rm opencv.zip opencv_contrib.zip

3.build opencv for arm architecture

cd opencv-4.10.0

mkdir -p build && cd build

cmake -DCMAKE_BUILD_TYPE=RELEASE\
 -DCMAKE_SYSTEM_PROCESSOR=arm\
 -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.10.0/modules\
 -DBUILD_SHARED_LIBS=OFF\
 -DCMAKE_INSTALL_PREFIX=/usr/local\
 -DOPENCV_GENERATE_PKGCONFIG=ON\
 -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc\
 -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++\
 -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake\
 ../

sudo make -j$(nproc)
sudo make install
  1. make go project (use cmd/version/main.go)
cd ../../
mkdir project && cd project
go mod init project
go get gocv.io/x/gocv

and paste cmd/version/main.go

  1. build go application for arm7 binary
GOARCH=arm GOOS=linux GOARM=7 CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CGO_ENABLED=1 go build -o version -ldflags="-extldflags=-static"

Your Environment

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

1 participant