c++ - How to create makefile build Snappy as static library -
i have files required build snappy library:
- snappy.h
- snappy.cc
- snappy-c.h
- snappy-c.cc
- snappy-internal.h
- snappy-sinksource.h
- snappy-sinksource..cc
- snappy-stubs-internal.h
- snappy-stubs-internal.cc
- snappy-stubs-public.h
- snappy-test.h
- snappy-test.cc
- snappy-unittest.cc
how create makefile making snappy static library.
i know have create .o file every .cpp file have variable , important rules.
objs=snappy.o snappy-c.o snappy-sinksource.o snappy-stubs-internal.o\ snappy-test.o snappy_unittest.o cc=gcc ccflags=-wall -static $(objs): %.o:%.cc $(cc) $(ccflags) $< -o $@ clean: -rm -rf *.o .phony: clean
what have next?
[edit]: have now:
objs=snappy.o snappy-c.o snappy-sinksource.o snappy-stubs-internal.o snappy-test.o snappy_unittest.o cc=gcc ccflags=-wall -static libname=libsnappy.a all:$(libname) $(libname): $(objs) ar rcs $@ $^ $(objs): %.o:%.cc $(cc) $(ccflags) $< -o $@ clean: -rm -rf *.o .phony: clean
but still doesn't work:
gcc -wall -static snappy.cc -o snappy.o snappy.cc: in member function ‘bool snappy::snappyiovecwriter::append(const char*, size_t)’: snappy.cc:1013:36: warning: comparison between signed , unsigned integer expressions [-wsign-compare] if (curr_iov_index_ + 1 >= output_iov_count_) { ^ snappy.cc: in member function ‘bool snappy::snappyiovecwriter::appendfromself(size_t, size_t)’: snappy.cc:1095:38: warning: comparison between signed , unsigned integer expressions [-wsign-compare] if (curr_iov_index_ + 1 >= output_iov_count_) { ^ snappy.cc: @ global scope: snappy.cc:567:13: warning: ‘void snappy::computetable()’ defined not used [-wunused-function] static void computetable() { ^ /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2 /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: in function `_start': (.text+0x20): undefined reference `main' /tmp/cctyhfnh.o: in function `snappy::internal::workingmemory::gethashtable(unsigned long, int*)': snappy.cc:(.text+0x5f9): undefined reference `operator new[](unsigned long)' /tmp/cctyhfnh.o: in function `snappy::compress(snappy::source*, snappy::sink*)': snappy.cc:(.text+0x1608): undefined reference `operator new[](unsigned long)' snappy.cc:(.text+0x17ff): undefined reference `operator new[](unsigned long)' snappy.cc:(.text+0x1926): undefined reference `operator delete[](void*)' snappy.cc:(.text+0x193f): undefined reference `operator delete[](void*)' /tmp/cctyhfnh.o: in function `snappy::rawuncompresstoiovec(char const*, unsigned long, snappy::iovec const*, unsigned long)': snappy.cc:(.text+0x19ec): undefined reference `snappy::bytearraysource::~bytearraysource()' snappy.cc:(.text+0x19ff): undefined reference `snappy::bytearraysource::~bytearraysource()' /tmp/cctyhfnh.o: in function `snappy::rawuncompress(char const*, unsigned long, char*)': snappy.cc:(.text+0x1aaa): undefined reference `snappy::bytearraysource::~bytearraysource()' snappy.cc:(.text+0x1abd): undefined reference `snappy::bytearraysource::~bytearraysource()' /tmp/cctyhfnh.o: in function `snappy::uncompress(char const*, unsigned long, std::string*)': snappy.cc:(.text+0x1b58): undefined reference `std::string::max_size() const' /tmp/cctyhfnh.o: in function `snappy::isvalidcompressedbuffer(char const*, unsigned long)': snappy.cc:(.text+0x1c03): undefined reference `snappy::bytearraysource::~bytearraysource()' snappy.cc:(.text+0x1c16): undefined reference `snappy::bytearraysource::~bytearraysource()' /tmp/cctyhfnh.o: in function `snappy::rawcompress(char const*, unsigned long, char*, unsigned long*)': snappy.cc:(.text+0x1caf): undefined reference `snappy::uncheckedbytearraysink::~uncheckedbytearraysink()' snappy.cc:(.text+0x1cbb): undefined reference `snappy::bytearraysource::~bytearraysource()' snappy.cc:(.text+0x1ccc): undefined reference `snappy::uncheckedbytearraysink::~uncheckedbytearraysink()' snappy.cc:(.text+0x1cdd): undefined reference `snappy::bytearraysource::~bytearraysource()' /tmp/cctyhfnh.o: in function `snappy::compress(char const*, unsigned long, std::string*)': snappy.cc:(.text+0x1d23): undefined reference `std::string::resize(unsigned long)' snappy.cc:(.text+0x1d59): undefined reference `std::string::resize(unsigned long)' /tmp/cctyhfnh.o: in function `snappy::stlstringresizeuninitialized(std::string*, unsigned long)': snappy.cc:(.text._zn6snappy28stlstringresizeuninitializedepssm[_zn6snappy28stlstringresizeuninitializedepssm]+0x1f): undefined reference `std::string::resize(unsigned long)' /tmp/cctyhfnh.o: in function `snappy::string_as_array(std::string*)': snappy.cc:(.text._zn6snappy15string_as_arrayepss[_zn6snappy15string_as_arrayepss]+0x15): undefined reference `std::string::empty() const' snappy.cc:(.text._zn6snappy15string_as_arrayepss[_zn6snappy15string_as_arrayepss]+0x31): undefined reference `std::string::begin()' /tmp/cctyhfnh.o: in function `snappy::internal::workingmemory::~workingmemory()': snappy.cc:(.text._zn6snappy8internal13workingmemoryd2ev[_zn6snappy8internal13workingmemoryd5ev]+0x2b): undefined reference `operator delete[](void*)' /tmp/cctyhfnh.o: in function `snappy::sink::sink()': snappy.cc:(.text._zn6snappy4sinkc2ev[_zn6snappy4sinkc5ev]+0xf): undefined reference `vtable snappy::sink' /tmp/cctyhfnh.o: in function `snappy::source::source()': snappy.cc:(.text._zn6snappy6sourcec2ev[_zn6snappy6sourcec5ev]+0xf): undefined reference `vtable snappy::source' /tmp/cctyhfnh.o: in function `snappy::bytearraysource::bytearraysource(char const*, unsigned long)': snappy.cc:(.text._zn6snappy15bytearraysourcec2epkcm[_zn6snappy15bytearraysourcec5epkcm]+0x27): undefined reference `vtable snappy::bytearraysource' /tmp/cctyhfnh.o: in function `snappy::uncheckedbytearraysink::uncheckedbytearraysink(char*)': snappy.cc:(.text._zn6snappy22uncheckedbytearraysinkc2epc[_zn6snappy22uncheckedbytearraysinkc5epc]+0x23): undefined reference `vtable snappy::uncheckedbytearraysink' /tmp/cctyhfnh.o:(.eh_frame+0x1ab): undefined reference `__gxx_personality_v0' collect2: error: ld returned 1 exit status make: *** [snappy.o] error 1
[edit2]: file have following content (and working now):
objs=snappy.o snappy-c.o snappy-sinksource.o snappy-stubs-internal.o cc=gcc ccflags=-wall libname=libsnappy.a all: $(libname) $(libname): $(objs) ar rcs $@ $^ ranlib $@ $(objs): %.o:%.cc $(cc) $(ccflags) $< -c -o $@ clean: -rm -rf *.o .phony: clean
your rule compiling , linking each source file, quite wrong, need compile it.
$(objs): %.o:%.cc $(cc) $(ccflags) $< -o $@
needs -c in it
$(objs): %.o:%.cc $(cc) $(ccflags) $< -c -o $@
the -static
flag should not in ccflags, that's linking stage (and static libraries doesn't linked when create them).
ccflags=-wall
Comments
Post a Comment