Reputation: 251
Good morning,
I'm having some issue during the compilation of my project on mac. I'm using a Makefile
for the compilation and when I execute the make
command, I have errors that come up. The problem is that under a docker, the compilation works perfectly fine but for this project I need to compile it under my mac because I'm using a library which is not installed under my docker and I don't have time for that for the moment. I think it's probably because the shell is using clang
for the compilation and I'm used to use GCC
. I'm totally new under mac so I don't know what I should do to avoid that.
MY_INFO$ make
c++ -c -o *.o Input.cpp
In file included from Input.cpp:8:
In file included from ./Input.hpp:11:
./Error.hpp:19:9: error: exception specification of overriding function is more lax than base version
~Error() = default;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/exception:101:13: note: overridden virtual function is here
virtual ~exception() _NOEXCEPT;
^
In file included from Input.cpp:8:
In file included from ./Input.hpp:11:
./Error.hpp:19:20: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions]
~Error() = default;
^
./Error.hpp:21:17: error: exception specification of overriding function is more lax than base version
const char *what() const noexcept {return _msg;}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/exception:102:25: note: overridden virtual function is here
virtual const char* what() const _NOEXCEPT;
^
In file included from Input.cpp:8:
In file included from ./Input.hpp:11:
./Error.hpp:21:29: error: expected ';' at end of declaration list
const char *what() const noexcept {return _msg;}
^
;
./Error.hpp:18:15: error: member initializer '_msg' does not name a non-static data member or base class
: _msg(msg), _file(file), _line(line) {}
^~~~~~~~~
In file included from Input.cpp:8:
./Input.hpp:18:9: error: exception specification of overriding function is more lax than base version
~InputSoundError() = default;
^
./Error.hpp:19:9: note: overridden virtual function is here
~Error() = default;
^
In file included from Input.cpp:8:
./Input.hpp:18:30: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions]
~InputSoundError() = default;
^
2 warnings and 5 errors generated.
make: *** [*.o] Error 1
MY_INFO$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
As follow, my makefile.
SRC = *.cpp
OBJ = $(foreach source, $(SRC), $(source:.cpp=.o))
NAME = SoundTest
CFLAGS = -g -Wall -Wextra -std=c++11
LDFLAGS = -lportaudio
CC = g++
LD = g++
all: $(NAME)
$(NAME): $(OBJ)
$(LD) -o $@ $^ $(LDFLAGS)
obj/%.o: %.cpp
$(CC) -o $@ -c $^ $(CFLAGS)
clean:
rm -rf $(OBJ)
fclean: clean
rm -rf $(NAME)
re: fclean all
Upvotes: 0
Views: 379
Reputation: 12929
Your makefile has a few issues. Firstly, you can't glob filenames using *.cpp
-- make
has its own function for that so you should use...
SRC = $(wildcard *.cpp)
You can also check the value of the SRC
variable with something like...
$(info SRC=[$(SRC)])
Next, your rule to build object files is...
obj/%.o: %.cpp
$(CC) -o $@ -c $^ $(CFLAGS)
So for any given source file foo.cpp
this rule tells make how to build obj/foo.o
from that source file. But you specify the list of object files based on the source file names using...
OBJ = $(foreach source, $(SRC), $(source:.cpp=.o))
So if SRC
is, e.g. a.cpp b.cpp
then OBJ
is a.o b.o
not obj/a.o obj/b.o
as would be required to make use of the obj/%.o: %.cpp
rule. What you really want is for OBJ
to be obj/a.o obj/b.o
(by way of example) so the variable definition should be...
OBJ = $(patsubst %.cpp,obj/%.o,$(SRC))
Putting the bits together gives...
SRC = $(wildcard *.cpp)
OBJ = $(patsubst %.cpp,obj/%.o,$(SRC))
NAME = SoundTest
CFLAGS = -g -Wall -Wextra -std=c++11
LDFLAGS = -lportaudio
CC = g++
LD = g++
all: $(NAME)
$(NAME): $(OBJ)
$(LD) -o $@ $^ $(LDFLAGS)
obj/%.o: %.cpp
$(CC) -o $@ -c $^ $(CFLAGS)
clean:
rm -rf $(OBJ)
fclean: clean
rm -rf $(NAME)
re: fclean all
Upvotes: 2
Reputation: 25663
Without knowing the content of your Makefile, we can see that you simply call
c++ -c -o *.o Input.cpp
from it. I have no idea what your compiler is and also not it`s version, maybe it is an older clang.
As we see a lot of warnings containing "are a C++11 extension" you should try to add --std=c++11
somewhere in the Makefile. Typically you find a line like CXXFLAGS+=...
. Here you can add the --std=c++11
flags to use c++11.
Maybe your compiler is to old and did not have full c++11 support. In this case, you have to update.
For a more detailed answer, we need your Makefile and the given compiler including the version.
Upvotes: 0