cmakefileldflags

How to add my lib to LDFLAGS?


I have next structure of a project:

cruceGame/
    src/
        libCruceGame/...
        cruceGameCurses/...
        multiplayerCurses/...
        networking/...
        parser/...
    docs/...this doesn't matter...

The project has a Makefile.am in src/ folder:

AM_CPPFLAGS = -I$(top_srcdir)/src/libCruceGame -I$(top_srcdir)/src/networking -I$(top_srcdir)/src/cruceGameCurses -I$(top_srcdir)/src/multiplayerCurses
LDFLAGS = -no-undefined
CFLAGS += -std=c99

if DEBUG
CFLAGS += -g -Wall -DDEBUG
endif

lib_LTLIBRARIES = libCruceGame.la libNetworking.la libCruceGameCurses.la libMultiplayerCurses.la
bin_PROGRAMS = cruceGame

cruceGame_SOURCES = cruceGame.c

cruceGame_LDADD = libCruceGame.la libNetworking.la libCruceGameCurses.la libMultiplayerCurses.la
cruceGame_LDFLAGS = -lncursesw -lpthread

libCruceGame_la_SOURCES = libCruceGame/deck.c \
              libCruceGame/team.c \
              libCruceGame/round.c \
                          libCruceGame/game.c

libNetworking_la_SOURCES = networking/network.c

libCruceGameCurses_la_SOURCES = cruceGameCurses/main.c \
                                cruceGameCurses/cli.c

libMultiplayerCurses_la_SOURCES = multiplayerCurses/main.c \
                                  multiplayerCurses/cli.c \
                                  multiplayerCurses/ircHandlers.c

You can find project here(look in develop branch): https://github.com/danij/CruceGame I am trying to pack cruceGameCurses and multiplayerCurses into libraries, but it uses the libCruceGame. When I use this makefile, i receive errors about unreconized reference to libCruceGame functions. So, my question: How I can add libCruceGame to LDFLAGS? PS The project isn't wrote by mine, I only contribue and I am beginner in librariies.


Solution

  • Try changing this line:

    cruceGame_LDFLAGS = -lncursesw -lpthread
    

    to this:

    cruceGame_LDFLAGS = -lncursesw -lpthread -L/directory/your/lib/is/in -lname
    

    where name is the middle part of the library filename. That is, if the file is libfoo.a or libfoo.so, the name used with the -l option is just foo.