Karthikeyan Raju
Karthikeyan Raju

Reputation: 81

How to add CFLAGS in makefile.am

I m using Makefile.am in yocto source.

My code is working with normal Makefile.

But, while integrating with the Makefile.am in yocto, It's getting segmentation faults.

I m using -lpthread while compilation. I want to know how to use cflags in Makefile.am. Can anyone tell me if my Makefile.am is correct? Because I'm doubting about my compilation.

Below is my Makefile.am

AUTOMAKE_OPTIONS = foreign

CFLAGS = -Wall -Wextra -static -lpthread -lrt
#include_HEADERS = .Iinclude/*
nobase_include_HEADERS = include/fmsHeader.h include/c_typedef.h include/console_comm.h

bin_PROGRAMS = bbmain
bbexample_SOURCES = bbmain.c

Upvotes: 2

Views: 6849

Answers (2)

Shachar Shemesh
Shachar Shemesh

Reputation: 8573

Several problems with your suggested makefile (in the question):

  1. Don't use = in Makefile.am, as that makes it more difficult to control the base flags from outside. Use += instead.
  2. As you've correctly noticed, CFLAGS is for compilation flags. Unfortunately, LDFLAGS is also wrong, as that's used for linker flags. You should add the flags to LIBS.
  3. Don't use -lpthread, ever. Use -pthread instead. Also, note that -pthread is a compilation flag, as well as a link time flag.
  4. Personally, I like to add flags such as -Wall and -Wextra through the configure script, and not as part of the makefile itself. It makes it easier to control its use.

End result should look something like this:

CFLAGS += -pthread
LIBS += -lrt

Upvotes: 2

Karthikeyan Raju
Karthikeyan Raju

Reputation: 81

I re-modified the contents into below format. It works

Hope it may helpful for someone.

AUTOMAKE_OPTIONS = foreign

CC=arm-linux-gnueabihf-gcc

CFLAGS +=-Wall -Wextra
LDFLAGS=-lpthread -lrt

nobase_include_HEADERS = Headers/console_comm.h Headers/c_typedef.h Headers/fmsHeader.h

bin_PROGRAMS=fmsTestApp
test_SOURCES=fmsTestApp.c

bin_PROGRAMS: 
        ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${test_SOURCES}

Upvotes: 2

Related Questions