Comments (7)
You can recommend users wanting to do static builds to compile with -ffunction-sections -fdata-sections and link with --gc-sections and for testing/debugging you can use --print-gc-sections to see just what gets removed (-flto works just as well but no printout capabilty and its not available in older versions of gcc - many projects, including Apple, still use the last GPL2 version) ... also compiling with -fvisibility=hidden helps when compiling objects for static libraries, but don't do it for shared objects. I have seen this combination cut a static compile size by almost 50%.
FWIW I do like the 1 file per function method but it can be tedious at times and compilers can eliminate most of the cruft, so I wouldn't change any existing code (except maybe the makefiles)
from cello.
Really? This project has several hundred functions. I don't think statically linked programs will be much smaller. Perhaps a few kb at most. I don't think there is much motivation for this.
from cello.
Static linking uses only those objects that are needed, so file splitting helps.
traditional hello.c:
#include <stdio.h>
int main() { printf("hello\n"); return 0; }
size (gcc hello.c -o hello -static -s): 5.7KB
small size hello.c:
#include <unistd.h>
#define WSTR(s) (s),sizeof(s)-1
int main() { write(1,WSTR("hello\n")); return 0; }
size (gcc hello.c -o hello -static -s): 3.3KB
hello.c (Cello):
#include <Cello.h>
int main() { print("hello\n"); return 0; }
size (gcc hello.c -o hello -static -s -lCello): 114.4KB
edit: c syntax... + libCello vs c++, go
c++:
#include <iostream>
int main() { std::cout << "hello\n"; return 0; }
# g++ hello.cc -o hello -static -s
# ls -lh hello
-rwxr-xr-x 1 root root 525.1k May 8 12:44 hello
go:
package main
import "fmt"
func main() { fmt.Println("hello") }
# go build hello.go
# strip -s hello
# ls -lh hello
-rwxr-xr-x 1 root root 888.3k May 8 12:46 hello
from cello.
I'm aware of that, but how will separating each individual function into a separate file help?
Are there any other projects which do this you can show me?
Functionality is separated into files fairly sensibly, such that if you are likely to use a single function in that file it will probably rely on (or you will use elsewhere) the vast majority of other functions in that file. Yes perhaps there are a few functions you may not use and it may shave off a couple of kb but the difference will be very very small.
Do you have a particular problem where library or executable size is a major concern? Having over 100 source files to shave a few KB off an executable seems pretty weird to me.
from cello.
It's just a suggestion. I have a small distro based on the musl-libc:
http://www.musl-libc.org/
http://git.musl-libc.org/cgit/musl/tree
musl-libc is optimized for static linking - they take care to use only the required code. Test it. I think you will enjoy. Code quality is very high.
btw. libCello is a nice alternative to Go. Many thanks for writing this lib!
from cello.
Cool looks interesting. Thanks for the suggestion and feedback! I still don't know if it is right for this project though.
from cello.
Thanks for the info!
from cello.
Related Issues (20)
- Unexpected GC behavior with Tuple HOT 5
- Make install should use "install --mode=..." instead of "cp" HOT 2
- make install doesn't install the dynamic library
- How do one "extends" a type? HOT 3
- error: cast to pointer from integer of different size HOT 2
- pop semantics? HOT 3
- Append Char HOT 2
- MacOS: __dyld section not supported HOT 1
- Abstracting a scripting language's internal value types using Cello HOT 1
- Feature request : Lua->Cello transpiler
- Missing Git tag for 2.1.0 release HOT 2
- Can I make a wrapper for other languages?
- Add vcpkg installation instructions
- Question about Array
- Doesn't work with Emscripten HOT 2
- is the project alive? can I use it in my product? who develops forks based on Cello? HOT 3
- Moving objects between threads HOT 1
- Failed to compile on GCC 8.1.0
- Can you do a comparison to Nim and Nelua?
- new release? HOT 2
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 cello.