Comments (12)
See: https://wiki.wxwidgets.org/Reducing_Executable_Size
"Pass -ffunction-sections -fdata-sections to the compiler while building and -Wl,--gc-sections to the linker"
Create a toolchain file that compiles the library and all Hunter dependencies with:
-ffunction-sections -fdata-sections
And be sure to link with
CHECK_C_COMPILER_FLAG("-Wl,-dead_strip" FLAG_dead_strip)
IF(NOT FLAG_dead_strip)
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--gc-sections")
ELSE()
SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,-dead_strip")
ENDIF()
http://stackoverflow.com/a/18115676
from drishti.
Also -flto
might help
http://stackoverflow.com/a/31355020
GCC: https://gcc.gnu.org/wiki/LinkTimeOptimization
Clang: https://llvm.org/docs/LinkTimeOptimization.html
from drishti.
Another options:
- Try
-O2
instead of-O3
- Try
-Os
(MinSizeRel) - Single Compilation Unit. This is something that is not implemented in CMake so just for the record.
from drishti.
DELETE
from drishti.
DELETE
from drishti.
http://stackoverflow.com/a/18949281
XCODE_ATTRIBUTE_GENERATE_MASTER_OBJECT_FILE "YES" # "Perform Single-Object Prelink"
from drishti.
I've added a lightweight c interface (remove rtti, etc) and strip everything except the explicitly defined symbols table (details below) and can get the sdk down to 2.2 MB from the previous 8.0 MB. This is also using a new xcode-sections
toolchain for all hunter dependencies.
6.9M _install/xcode-sections/lib/libdrishti.0.7.1.dylib
4.0K _install/xcode-sections/lib/libdrishti.0.dylib
4.0K _install/xcode-sections/lib/libdrishti.dylib
2.2M _install/xcode-sections/lib/libdrishti_c.dylib
792K _install/xcode-sections/lib/libdrishti_c.dylib.gz
function(drishti_hide_and_strip drishti_library)
set_target_properties(${drishti_library}
PROPERTIES
CXX_VISIBILITY_PRESET hidden ### HIDE
VISIBILITY_INLINES_HIDDEN "ON"
XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN "YES"
XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES"
XCODE_ATTRIBUTE_COPY_PHASE_STRIP "YES"
XCODE_ATTRIBUTE_STRIP_INSTALLED_PRODUCT "YES"
XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
XCODE_ATTRIBUTE_STRIPFLAGS "-x -u -r"
XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING "YES"
XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
XCODE_ATTRIBUTE_GENERATE_MASTER_OBJECT_FILE "YES" # "Perform Single-Object Prelink"
PUBLIC_HEADER "${DRISHTI_DRISHTI_HDRS_PUBLIC}"
)
endfunction(drishti_hide_and_strip)
drishti_hide_and_strip(drishti_c)
set_target_properties(drishti_c
PROPERTIES
XCODE_ATTRIBUTE_EXPORTED_SYMBOLS_FILE "${CMAKE_CURRENT_LIST_DIR}/drishti/drishti_symbols.txt"
)
drishti_symbols.txt:
_drishti_create_from_file
_drishti_create_from_stream
_drishti_destroy
_drishti_segment
from drishti.
Switching to MinSizeRel
and dropping the unnecessary text archive support on OS X saves a bit more:
5.9M libdrishti.0.7.1.dylib
4.0K libdrishti.0.dylib
4.0K libdrishti.dylib
1.9M libdrishti_c.dylib
716K libdrishti_c.dylib.gz
from drishti.
This stripped _c.dylib.gz
size is suitable. The issue can be closed once the post build install() libraries are actually tested. See #75
from drishti.
See #138
This is really an ongoing effort. The eye sdk size is significantly reduced using the above C interface, and initial comparisons were done in #138, so I'm removing this from the current milestone in favor of more focused follow up efforts.
from drishti.
Some Apple notes on size reduction "How to best..."
https://developer.apple.com/library/content/technotes/tn2185/_index.html
from drishti.
This was on the right path but was missing: -flto -Os
and related per platform linker flags (as needed) to get the full savings. Satisfied with current approach after boost -> cereal updates + extern "C" api + strip + -flto -Os -fdata-sections -ffunction-sections
from drishti.
Related Issues (20)
- mac os/android studio build error HOT 11
- Hide drawn curves and draw other effects/ android demo HOT 11
- Build problems because of broken glm verions + gcc 7.3 HOT 2
- Black screen for DrishtiFaceFilter on Android HOT 1
- make model file into lib HOT 5
- Drishti with Xcode 10.2 HOT 19
- Drishti does not compile with linux gcc anymore. HOT 1
- How I compile this project in android studio HOT 3
- Hide Camerapreview in android demo HOT 1
- How I compile this project in Xcode HOT 7
- Build failed-macOS HOT 2
- Example not building for android studio
- Could you give me some hints about the algorithm for this cool project?
- ABI configuration problem
- drishti works with 'armeabi-v7a', 'arm64-v8a only???
- iOS build failed. HOT 1
- iOS facefilter example error.
- SIGSEGV on System.loadLibrary HOT 1
- iOS 14.5 compile error
- Build android-studio app fail.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drishti.