0

I have written an application in the IDE CLion. I am trying to create a Makefile on a Linux machine. I used a template Makefile to create my own Makefile, however, there are issues. Note that there are 3 classes called quote, trade and signal.

CXX = g++
# mandatory build flags
CXXFLAGS = -O2 -Werror -std=c++11

# mandatory link flags
AM_LDFLAGS = -Wl,-as-neeeded

output: main.o quote.o trade.o signal.o
    ${CXX} ${AM_LDFLAGS} ${LDFLAGS} $(filter %.o,$^) -o $@

%: %.cpp
    ${CXX} ${AM_CXXFLAGS} ${CXXFLAGS} $< -c -o $@

quote.o: quote.cpp quote.h
trade.o: trade.cpp trade.h
signal.o: signal.cpp signal.h

When I run the Makefile, I get the errors:

error: #error This file required the -std=c++11 or -std=gnu++11 compiler options.

Then, many errors appear which require C++11 support. For example, there are issues with std::string, std::chrono. How do I fix this? I am requesting that someone fix the code. Since I just started learning MakeFile today, I most likely won't understand your technical suggestion. Please help. Very appreciative!

EDIT: After following the suggestions below, I fixed the above error. I am now getting the following errors:

g++ -02 -Werror -std=c++11 -c -o main.o main.cpp

g++ -02 -Werror -std=c++11 -c -o quote.o quote.cpp

g++ -02 -Werror -std=c++11 -c -o trade.o trade.cpp

g++ -Wl, -as-needed main.o quote.o trade.o signal.o -o output

/usr/bin/ld: unrecognixed -a option 's-needed'

collect2: error: ld returned 1 exit status

9
  • 1
    Add -std=c++11 to the CXXFLAGS... Commented Mar 22, 2016 at 1:56
  • @DanMašek Could you explicitly write exactly how this is done? Commented Mar 22, 2016 at 1:57
  • 1
    something like CXXFLAGS = -O2 -Werror -std=c++11 instead of the existing line you have there. Commented Mar 22, 2016 at 2:00
  • 2
    Show us the full output from running make not just the error message. Commented Mar 22, 2016 at 2:20
  • 2
    That's an entirely different error then the one you said you were getting. Do you still get the other error? Or did you fix that and just not report the new error? Commented Mar 22, 2016 at 2:44

1 Answer 1

2

AM_CXXFLAGS is used by automake. You are not using automake, so this accomplishes nothing.

Put all your compiler flags into CXXFLAGS only.

Sign up to request clarification or add additional context in comments.

3 Comments

Works for me just fine.
thanks! I still receive other messages. Could you please see my edits above?
You made a typo in the option's name. Reread ld's manual page, and fix your typo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.