Tanner Quigley
Tanner Quigley

Reputation: 246

Error: no such file or directory: '–std=c++11' after compiling makefile

When I compile using make in the terminal it prints:

g++ -Wall –std=c++11 -c File.cpp
clang: error: no such file or directory: '–std=c++11'
make: *** [Book.o] Error 1

makefile:

PROG = studs
CC = g++
OBJS = File.o FileTestDriver.o
CPPFLAGS = -Wall –std=c++11

$(PROG) : $(OBJS)
    $(CC) -o $(PROG) $(OBJS)
File.o : File.h
    $(CC) $(CPPFLAGS) -c File.cpp
FileTestDriver.o :
    $(CC) $(CPPFLAGS) -c FileTestDriver.cpp
clean:
    $(RM) $(PROG) $(OBJS)

FileTestDriver has the main function and File.cpp is just a simple class with some constructors, instance variables and functions. I'm not sure where the problem is but I assume it's in the Makefile as I just started using them today.

When I simply compile g++ -std=c++11 File.cpp I get the error:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But I assume the error is because it has a .h and needs the makefile to be compiled. Anyway, not sure what I'm doing wrong but I appreciate any help. Let me know if more info is needed.

Also (maybe this should be a separate question/I need to look harder), but after using the makefile, ./a.out will only ever run the makefile, regardless of the last thing I compiled. Not sure how to change that.

Upvotes: 3

Views: 11053

Answers (2)

paxdiablo
paxdiablo

Reputation: 881283

If you take a look at your compile line closely, you'll see a very subtle difference between the - before Wall and the before std=c++11:

g++ -Wall –std=c++11 -c File.cpp
    ^     ^

Here are those two options, one under the other, captured with Windows Snipping Tool and blown up with Paint.net. You can clearly see that the second "hyphen" is wider:

enter image description here

And it's wider because it's not a hyphen - the character is actually an en dash (Unicode code point U+2013).

This problem is often caused by cutting and pasting directly from places like word processors(a) or web pages. Because it's not considered a valid lead-in character (hyphen-minus, or Unicode code point U+002D), it's simply being treated as a file name, hence the error.

I suggest you just retype the line (or only the -std=c++11 bit) to ensure it's using the correct character.


(a) Word processors, with their smart text replacement features, will often turn hyphens into en- or em- dashes, or modify your strings or character literals from "pax" into “pax”. You can disable this behaviour (smart quotes in MS Word, for example) but it's sometimes quite handy.

I just tend to avoid using word processors as text editors, or become aware to the possibility that cut'n'pasted code may contain "suspicious" character. If a piece of text I've gotten from the web or a word processor causes my build system to complain, I examine (and retype manually) the offending section.

Upvotes: 13

Kevin Chou
Kevin Chou

Reputation: 577

I made a mistake as follows:

# CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std = c++11")

Notice there is NO whitespace between -std and c++11

Upvotes: 0

Related Questions