liudf0716 / xfrpc

The xfrpc project is a lightweight implementation of the FRP client written in C language for OpenWRT and IoT systems. It is designed to provide an efficient solution for resource-constrained devices such as OpenWRT routers and IoT devices, which often have limited ROM and RAM space.
GNU General Public License v3.0
712 stars 89 forks source link

Support to compile it static #17

Closed lars18th closed 1 year ago

lars18th commented 1 year ago

Hi,

This project targets OpenWRT devices. However, it could be useful to run it in other devices. In this case, the only one requirement is that the binary will be static. Therefore, the question is: how to compile the target static?

Regards.

liudf0716 commented 1 year ago

does the following content answer your question ?


Quickstart for Ubuntu 20.04.3 LTS
xfrp need [libevent](https://github.com/libevent/libevent) [openssl-dev](https://github.com/openssl/openssl) and [json-c](https://github.com/json-c/json-c) support

Before compile xfrp, please install libevent and json-c in your system.

Install json-c libevent in ubuntu 20.04 LTS

sudo apt-get install -y libjson-c-dev
sudo apt-get install -y libevent-dev
Fork xfrpc on GitHub

git clone https://github.com/${YOUR_GITHUB_ACCOUNT_NAME}/xfrpc.git
cd xfrp
mkdir build
cmake ..
make
lars18th commented 1 year ago

Hi @liudf0716 ,

Thank you for the response. However, this is only a simple guide to compile the content of this repo. My concern is about How to compile the binaries statically. Are you sure that the default compilation mode using the cmake tool is an static target?

lars18th commented 1 year ago

Hi @liudf0716 ,

To compile the package inside one Ubuntu docker image:

$ docker run -v $(pwd):/root -it ubuntu:22.04 /bin/bash

apt update
apt install build-essential
apt-get install -y git cmake libssl-dev zlib1g-dev
apt-get install -y libjson-c-dev
apt-get install -y libevent-dev

cd /root
git clone https://github.com/liudf0716/xfrpc.git
cd xfrp
mkdir build
cd build
cmake ..
make

root@914d09f63f63:~/xfrpc/build# ldd xfrpc
        linux-vdso.so.1 (0x00007ffd7cfc1000)
        libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007f5ad31e0000)
        libevent-2.1.so.7 => /lib/x86_64-linux-gnu/libevent-2.1.so.7 (0x00007f5ad318c000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f5ad3170000)
        libjson-c.so.5 => /lib/x86_64-linux-gnu/libjson-c.so.5 (0x00007f5ad315d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5ad2f35000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f5ad3655000)

And as you can see the output binary is NOT static. The question is how to compile it without any library dependency. Do you know it?

liudf0716 commented 1 year ago

@lars18th thanks for your detailed explanation, I understand what u mean now. In fact I didn't think that in deep, therefore I need time to verify how to link depended library in static mode.

lars18th commented 1 year ago

Hi @liudf0716 ,

Thank you. I hope you will found a solution to compile the binaries statically. The objective is to use this tool in different devices not running OpenWRT.

Regards.

lars18th commented 1 year ago

Hi to @helintongh abd @liudf0716 for adding this very useful option. Congratulations! 👍