Pergunta

I have project using Snappy library and makefile for it:

CXX=g++
CXXFLAGS=-c -Wall
LFLAGS=
OBJS=main.o Utilities.o FramingFormat.o Crc32.o

snappy.out: $(OBJS)
        $(CXX) $(LFLAGS) $^ -o $@

$(OBJS): %.o:%.cpp
        $(CXX) $(CXXFLAGS) $< -o $@
clean:
    -rm -rf *.o
.PHONY: clean

Snappy library has been built earlier.

Now I run my makefile I have errors:

g++  main.o Utilities.o FramingFormat.o Crc32.o -o snappy.out
FramingFormat.o: In function `compressToFrame(char*, unsigned long, char*, unsigned long*)':
FramingFormat.cpp:(.text+0x5b): undefined reference to `snappy_compress'
FramingFormat.o: In function `uncompressFromFrameData(char*, unsigned long, char*, unsigned long*)':
FramingFormat.cpp:(.text+0x14a): undefined reference to `snappy_uncompress'
FramingFormat.o: In function `maxFrameLength(unsigned long)':
FramingFormat.cpp:(.text+0x2bf): undefined reference to `snappy_max_compressed_length'
FramingFormat.o: In function `uncompressedDataLength(char*, unsigned long, unsigned long*)':
FramingFormat.cpp:(.text+0x2f8): undefined reference to `snappy_uncompressed_length'
collect2: error: ld returned 1 exit status
make: *** [snappy.out] Error 1

It is because makefile don't know that I'm using snappy libs how to solve this problem? It's my directories:

  • snappy/catalog-with-snappy
  • snappy/catalog-with-project-using-snappy

[EDIT] My makefile looks like this:

CXX=g++
CXXFLAGS=-c -Wall
LFLAGS=
OBJS=main.o Utilities.o FramingFormat.o Crc32.o

snappy.out: $(OBJS)
        $(CXX) $(LFLAGS) $^ -L"../../SnappyLib1.1.2/SnappyLib1.1.2" -o $@

$(OBJS): %.o:%.cpp
        $(CXX) $(CXXFLAGS) $< -L"../../SnappyLib1.1.2/SnappyLib1.1.2" -o $@
clean:
    -rm -rf *.o
.PHONY: clean
Foi útil?

Solução

use -lsnappy in the linker option, presuming you have snappy.so or snappy.a in the accessible directory. or you may have to use the directory explicitly

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top