Skip to content

Instantly share code, notes, and snippets.

@wongsyrone
Created January 2, 2020 11:07
Show Gist options
  • Save wongsyrone/64d4b8e09f36c343c2522cd15bd06950 to your computer and use it in GitHub Desktop.
Save wongsyrone/64d4b8e09f36c343c2522cd15bd06950 to your computer and use it in GitHub Desktop.
build musl-libc trojan for linux x86 ubuntu 16.04 vps
In Alpine linux, use bash shell
boost
bash bootstrap.sh
./b2 --stagedir=/home/wong/boost-stage architecture=x86 address-model=64 toolset=gcc variant=release link=static threading=multi --with-system --with-date_time --with-program_options stage
openssl use static lib
Change OpenSSL perl Configure:
diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf
index df1cc00529..bc68affc57 100644
--- a/Configurations/10-main.conf
+++ b/Configurations/10-main.conf
@@ -638,10 +638,10 @@ my %targets = (
CXX => "g++",
CFLAGS => picker(default => "-Wall",
debug => "-O0 -g",
- release => "-O3"),
+ release => "-O2 -g"),
CXXFLAGS => picker(default => "-Wall",
debug => "-O0 -g",
- release => "-O3"),
+ release => "-O2 -g"),
cflags => threads("-pthread"),
cxxflags => combine("-std=c++11", threads("-pthread")),
lib_cppflags => "-DOPENSSL_USE_NODELETE",
./config no-shared --prefix=/home/wong/openssl-install --openssldir=/home/wong/openssl-install && make install_sw
make test
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96934cb..7a7e4b8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,9 @@ if(MSVC)
else()
add_definitions(-Wall -Wextra)
endif()
+SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+SET(BUILD_SHARED_LIBS OFF)
+SET(CMAKE_EXE_LINKER_FLAGS "-static -no-pie")
add_executable(trojan
src/core/authenticator.cpp
@@ -127,3 +130,5 @@ else()
add_test(NAME LinuxSmokeTest-fake-client
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/LinuxSmokeTest/fake-client.sh ${CMAKE_BINARY_DIR}/trojan)
endif()
+target_link_libraries(trojan dl)
+target_link_libraries(trojan -static-libgcc -static-libstdc++)
pushd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_MYSQL=OFF -DSYSTEMD_SERVICE=OFF -DOPENSSL_ROOT_DIR=/home/wong/openssl-install -DBoost_NO_BOOST_CMAKE=ON -DBOOST_INCLUDEDIR=/home/wong/boost_1_72_0 -DBOOST_LIBRARYDIR=/home/wong/boost-stage/lib -DBoost_NO_SYSTEM_PATHS=ON -DBoost_USE_DEBUG_LIBS=OFF -DBoost_USE_RELEASE_LIBS=ON -DBoost_USE_STATIC_LIBS=ON ..
make
file trojan
ldd trojan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment