1

I am trying to build a simple example using aws sdk cpp. But I am stumbled on a building step. I am linking libaws-cpp-sdk-s3.so library, which is supposed to have all symbols from the source file. But the linker cannot even find a couple of them. The source file is:

#include <aws/core/Aws.h>
int main( int argc, char ** argv)
{
    Aws::SDKOptions options;
    Aws::InitAPI(options);

    {
        // make your SDK calls here.
    }

    Aws::ShutdownAPI(options);
    return 0;
}

by using this Makefile:

CC = g++
CFLAGS = -g -c -Wall -std=c++11
LDFLAGS = -g
EXECUTABLE = ex1
RM = rm -f

SOURCES = main.cpp
OBJS = $(SOURCES:.cpp=.o)

all: $(EXECUTABLE)

$(EXECUTABLE): main.o -laws-cpp-sdk-s3
    $(CC) $(LDFLAGS) main.o -o $@

main.o: main.cpp
    $(CC) $(CFLAGS) $^ -o $@

.PHONY: clean
clean:
    $(RM) $(EXECUTABLE) $(OBJS) $(SOURCES:.cpp=.d)

When I run make, I got this error. But why? I built

g++ -g main.o -o ex1 main.o: In function main': /home/username/workspace/ex1/src/main.cpp:6: undefined reference toAws::InitAPI(Aws::SDKOptions const&)' /home/username/workspace/ex1/src/main.cpp:12: undefined reference to `Aws::ShutdownAPI(Aws::SDKOptions const&)' collect2: error: ld returned 1 exit status Makefile:13: recipe for target 'ex1' failed make: *** [ex1] Error 1

1 Answers1

4

I don't see where you are linking libaws-cpp-sdk-core

You probably need:

$(EXECUTABLE): main.o -laws-cpp-sdk-s3 -laws-cpp-sdk-core
    $(CC) $(LDFLAGS) main.o -o $@
Jonathan Henson
  • 8,076
  • 3
  • 28
  • 52
  • @paratrooper sorry for the delay, for some reason this didn't shoe up in my daily digest. The latest version has better pkg-config support which will resolve all of this for you. example pkg-config aws-cpp-sdk-s3 --libs – Jonathan Henson Apr 28 '17 at 21:57
  • Including -laws-cpp-sdk-s3 -laws-cpp-sdk-core as one of the LIB worked for me. – roosevelt Dec 18 '19 at 22:02