makefileautomakesocketcan

Automake LibSocketCan


I am using automake to build my project. My project uses pthread and libsocketcan. I have installed libsocketcan with the command

sudo apt-get install libsocketcan-dev

In eclpise I have added linker flags for pthread and libsocketcan. The code will compile and run. When I run my automake script the build fails with the error.

gcc: error: unrecognized command line option ‘-socketcan’[![enter image description here][1]][1]

My makefile.am is as follows:

AUTOMAKE_OPTIONS = foreign subdir-objects

bin_PROGRAMS = MAIN_Application

LDFLAGS = \
    -pthread \
    -socketcan


AM_CPPFLAGS = \
    -I$(srcdir)/include \
    -I$(srcdir)/include/utilities \
    -I$(srcdir)/include/comms

MAIN_Application_SOURCES = \
    src/main.c \
    src/scheduler.c \
    src/utilities/time_conversions.c \
    src/utilities/ring_buffer.c \
    src/utilities/logger.c \
    src/comms/can.c 

If I remove all code and references here to socketcan, everything works fine. I get a nice application binary that can run threads. Once I add can I can no longer build. I have tried with the LDFLAGS socketcan, libsocketcan and libsocketcan-dev.

What LDFLAG do I need in my makefile to properly include libsocketcan?


Solution

  • You do not need any "LDFLAG" for this. LDFLAGS is for linker flags, not for adding libraries to link to.

    You can have MAIN_Application link against libsocketcan with something like:

    MAIN_Application_LDADD = -lsocketcan