$ make
clang++ -o build/blist.exe src/driver.cpp src/BList.h -O0 -g -Wall -Wno-unused-parameter -Wextra -Wconversion -Wold-style-cast -std=c++14 -pedantic -Wold-style-cast
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: cannot specify -o when generating multiple output files
My template implementation is in BList.cpp, but BList.h includes BList.cpp. That's why I pass the header in as an object. I don't know how to set clang to compile!
My header must be named "BList.h" according to my professor.
These parameters compiles with GCC, but not with Clang.
The error has nothing to do with including BList.cpp in BList.h (though that's a dubious practice by itself).
The problem is that you pass src/BList.h to Clang as if it was a source file. The build instruction should be:
clang++ -o build/blist.exe src/driver.cpp -O0 -g -Wall -Wno-unused-parameter -Wextra -Wconversion -Wold-style-cast -std=c++14 -pedantic -Wold-style-cast
You should update your makefile accordingly.
Related
I am attempting to compile a program that uses ranged based for loops, and a couple other features available only in c++11 and above. When I attempt to compile the program using a makefile in the terminal, I get this error:
error: range-based ‘for’ loops are not allowed in C++98 mode
and some warnings:
warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
What's annoying is that this has happened before, but it just resolved itself. However, this time it has not resolved itself.
Here's my makefile:
main: main.o
g++5 -std=c++11 -Wall -Werror -g *.cpp -o lab4
Here are some examples of things I have tried to change in the makefile, but did not work.
g++-5 -std=c++11 -Wall -Werror -g *.cpp -o lab4
g++5 -std=gnu++11 -Wall -Werror -g *.cpp -o lab4
g++5 -std=c++0x -Wall -Werror -g *.cpp -o lab4
g++ -std=c++11 -Wall -Werror -g *.cpp -o lab4
g++ -std=gnu++11 -Wall -Werror -g *.cpp -o lab4
All of the previous examples result in similar warnings and errors. What can I do to fix the problem?
I am facing the weirdest thing ever. I am having a deprecation warning although I am using -Wno-deprecated flag with g++.
What am I doing wrong? Should I reorder the flags I am passing to g++?
g++ -fno-strict-aliasing -Wall -D__LINUX__ -DOS_USE_STD_IOSTREAMS -DOS_LINUX_2_2 -D__CPP -D__USE_BSD -DLINUX -Wno-sign-compare -Wno-deprecated -Wno-unused-variable -Wno-write-strings -Wno-unused -DOS_USE_STD_IOSTREAM -m64 -m64 -O3 -Werror
The deprecation warning is specifically about sys_errlist and that I should use stderror or stderror_r.
I have checked the specific header file declraing the function that uses sys_errlist and it doesn't have a diagnostic pragma.
I am using GCC 3.3.1 on a 64 bit RHE4 machine
I am just curious if the position of the standard selection switch (-std=c++11 for my case) is relevant in g++ command line or not. The reason is that the following:
g++ -ftest-coverage -fprofile-arcs -std=c++11
-ansi -fpermissive -finline-functions -Wno-long-long
-fvisibility-inlines-hidden -m64 -Wall -Wextra
-g -o CMakeFiles/common.dir/cryptoclass.cpp.o
-c /home/work/common/cryptoclass.cpp
does not compile, while the following:
g++ -ftest-coverage -fprofile-arcs
-ansi -fpermissive -finline-functions -Wno-long-long
-fvisibility-inlines-hidden -m64 -Wall -Wextra
-g -o CMakeFiles/common.dir/cryptoclass.cpp.o
-std=c++11 -c /home/work/common/cryptoclass.cpp
does compile. The only change is that the -std=c++11 was moved to the end of the switches.
g++ gives the following warning:
error: #error This file requires compiler and
library support for the ISO C++ 2011 standard.
This support is currently experimental, and must
be enabled with the -std=c++11 or -std=gnu++11 compiler options.
Version:
g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
As per documentation, -ansi option enables the c++-98/c++-03 standard.
If you set multiple standard options, the latter option overrides the former. Same applies to other mutually exclusive options such as optimization levels.
I'm trying to set windows programming enviroment for c++. I use the Visual Studio to write the code but my University wants me to use g++ compiler. So far I managed to link g++ with the PATH using cmd but that's not all. I have to use an alias which in linux is:
p1++="g++ -ansi -Wall -O2 -DNDEBUG -Wextra -Werror -Wno-uninitialized -Wno-sign-compare -Wshadow
I tried the same using the command doskey:
doskey p1=g++ -ansi -Wall -O2 -DNDEBUG -Wextra -Werror -Wno-uninitialized -Wno-sign-compare -Wshadow
and it works but whenever I use for example:
p1++ hello.cpp
it says
g++: fatal error: no input files
compilation terminated.
but if i use:
g++ hello.cc
It does compile, so my question is what does all that code mean and how can I get rid of that error?
Thanks
test.cpp (assumed to exist at C:\test.cpp):
#include <iostream>
int main(void) { std::cout << "hello" << std::endl; return 0; }
Here's what it looks like in my Windows CMD prompt:
NOTE: No quotes in alias, and it is assumed that g++ is already in your PATH.
C:\>set p1++=g++ -ansi -Wall -O2 -DNDEBUG -Wextra -Werror -Wno-uninitialized -Wno-sign-compare -Wshadow
C:\>%p1++%
g++: fatal error: no input files
compilation terminated.
C:\>%p1++% test.cpp
C:\>a.exe
hello
C:\>doskey p1++=%p1++% $*
C:\>p1++ test.cpp
C:\>a.exe
hello
If you wanted to have the %p1++% environment variable persist across CMD prompts then you'd need to add an environment variable to your Windows User Profile.
On Windows 7:
Control Panel => System => Advanced System Settings => Environment Variables.
Create a new User Variable with name = p1++ and value = g++ -ansi -Wall -O2 -DNDEBUG -Wextra -Werror -Wno-uninitialized -Wno-sign-compare -Wshadow.
The following code fragment does nothing, but illustrates the problem. It was extracted from some Boost Python code, which uses the Numpy C API. This was tested with the backport of a gcc 4.7 snapshot from Debian unstable to squeeze.
#include <boost/python/object.hpp>
#include <numpy/arrayobject.h>
int main(void)
{
PyObject* obj=0;
npy_int64 val;
PyArray_ScalarAsCtype(obj, &val);
return 0;
}
I'm compiling like this.
g++-4.7 -o warn.o -c -isystem /usr/include/python2.6 -fdiagnostics-show-option -ftemplate-depth-100 -fno-strict-aliasing -ansi -pedantic -Wextra -Wall -Werror -Wno-unused-function -Wc++0x-compat -g -O3 -std=c++11 -I/usr/include/python2.6 warn.cc
warn.cc: In function 'int main()':
warn.cc:8:3: error: ISO C++ forbids casting between pointer-to-function and pointer-to-object [-Werror]
cc1plus: all warnings being treated as errors
The problem is the -pedantic and the PyArray_ScalarAsCtype line of code. Without -pedantic the following compiles without error
g++-4.7 -o warn.o -c -isystem /usr/include/python2.6 -fdiagnostics-show-option -ftemplate-depth-100 -fno-strict-aliasing -ansi -Wextra -Wall -Werror -Wno-unused-function -Wc++0x-compat -g -O3 -std=c++11 -I/usr/include/python2.6 warn.cc
g++-4.7 -o warn warn.o -L/usr/lib/python2.6/config -lpython2.6 -lboost_python
Note: I added the =0 to suppress an uninitialized warning. Like I said, the code doesn't do anything.
I'd like to either suppress or remove the warning and keep the -pedantic flag. From what I've read, there is no error as such here, but this falls within some disputed section of the standard. I don't really understand the issue, or how it pertains to this line of code. The new gcc diagnostics allow one to selectively suppress warnings in a section of code, but they require you to know what specific flag is triggering the warning, and I don't know. Without the -Werror flag I get
warn.cc:8:3: warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object [enabled by default]
In Standard C++, you cannot convert between, say, an int* and int(*)(). Likely, this is what's happening under the hood in your implementation. Most platforms allow it, but not all.
Of course, there is nothing illegal about any library only executing on platforms where it is legal.