I'm trying to compile an open source project on OSX that has only been tested on Linux.
$: g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-da
I'm trying to compile with the following command line options
g++ -MMD -Wall -std=c++0x -stdlib=libc++ -Wno-sign-compare -Wno-unused-variable -ftemplate-depth=1024 -I /usr/local/Cellar/boost/1.55.0/include/boost/ -g -O3 -c level.cpp -o obj-opt/level.o
I am seeing several errors that look like this:
./square.h:39:70: error: chosen constructor is explicit in copy-initialization
int strength = 0, double flamability = 0, map<SquareType, int> constructions = {}, bool ticking = false);
The project states the following are requirements for the Linux setup. How can I confirm I'm making that?
gcc-4.8.2
git
libboost 1.5+ with libboost-serialize
libsfml-dev 2+ (Ubuntu ppa that contains libsfml 2: )
freeglut-dev
libglew-dev
The project requires you to compile with gcc-4.8.2 , but your g++ is using clang, which is a different compiler.
Install gcc-4.8.2 or above, and use it to compile your project
$ sudo port install gcc49
Related
I need to use C++98 for university programs, however even when passing the -std=c++98 flag to clang++ or to g++ it still seems to compile with c++11 and does not give errors if I use c++11 features. Here is a simple example:
#include <string>
#include <sstream>
using namespace std;
int main()
{
int i;
string number = "12";
i = stoi(number);
}
My makefile:
all:
clang++ -std=c++98 -c *.cpp
clang++ -o main *.o
clean:
rm -f *.o main
run: clean all
./main
Then I run the command make from Terminal (I tried using clang++ instead of g++ but it yields the same result) and receive the following output:
➜ cppversion make
g++ -std=c++98 -c *.cpp
g++ -o main *.o
➜ cppversion make
clang++ -std=c++98 -c *.cpp
clang++ -o main *.o
➜ cppversion
I believe this code should not have compiled if the -std=c++98 flag was working. How do I force code to compile with c++98?
Here is the version of clang:
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin\
Here is the version of g++:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I have also tried adding the flag -pedantic but it does not fix the problem.
Using the flag -stdlib=libc++ yields the following:
➜ cppversion make
clang++ -stdlib=libstdc++ -std=c++98 -c *.cpp
clang: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
main.cpp:1:10: fatal error: 'string' file not found
#include <string>
^~~~~~~~
1 error generated.
make: *** [all] Error 1
If I change it to just -stdlib=libc++ then it still compiles:
➜ cppversion make
clang++ -stdlib=libc++ -std=c++98 -c *.cpp
clang++ -o main *.o
➜ cppversion
I found an easy solution: Use homebrew to install gcc and use g++-11 to compile.
Try using -std=c++98 -pedantic.
This should strictly enforce the specific standard.
Disclaimer: This is partly guesswork since I don't have a Mac
From my understanding, clang++ is the default compiler on Mac and I would therefore not be surprised if even g++ uses LLVM:s libc++ and headers by default. std::stoi is unconditionaly declared in the libc++ headers.
If you instead useg++:s libstdc++ toolchain, you will probably get the error you want:
clang++ -stdlib=libstdc++ -std=c++98 -o main main.cpp
I found an easy solution: Use homebrew to install gcc and use g++-11 to compile.
I can build c++ projects without c++ modules with build2, but when i try to configure and use build2 with c++ modules, I have "compiler does not support modules" error.
I'm sure my compiler is capable of building modules, because I can manually build using these commands:
clang++ --std=c++17 -fmodules-ts --precompile foo.cppm -o foo.pcm
clang++ --std=c++17 -fmodules-ts --precompile foo2.cppm -o foo2.pcm
clang++ --std=c++17 -fmodules-ts -c foo.pcm -o foo.o
clang++ --std=c++17 -fmodules-ts -c foo2.pcm -o foo2.o
clang++ --std=c++17 -fmodules-ts -fprebuilt-module-path=. foo.o foo2.o bar.cpp
Version of my clang is 7.0.0:
$ clang++ --version
clang version 7.0.0- (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
To enable modules support in build2 I added following lines to root buildfile:
cxx.std = experimental
using cxx
assert $cxx.features.modules 'compiler does not support modules'
mxx{*}: extension = mxx
cxx{*}: extension = cxx
What can be wrong? It's my first time with build2, so I can be missing something very simple.
Managed it to work.
As I understand the problem was that I changed buildfile, but should use build/root.build instead.
I'm trying to configure eclipise kepler to use c++ 11.
I appended -std=c++11 to:
Properties > c/c++ build > settings > GCC c++ complier > Miscellaneous>other flags
But when I compile the project it says:
compilation terminated. /bin/sh: 1: -std=c++11: not found
I'm using gcc on ubuntu,
any ideas?
Flags (or compiler options) are nothing but ordinary command line arguments passed to the compiler executable.
Assuming you are invoking g++ from the command line (terminal):
$ g++ -Wall -g -std=c++11 your_file.cpp -o your_program
or
$ g++ -Wall -g -std=c++0x your_file.cpp -o your_program
if the above doesn't work.
So in your case if -std=c++11 does not work, try -std=c++0x
Another source for this error could be an old compiler version.
Type gcc --version into the terminal and check the version. Here is a quick overview which version is capable of c++11:
C++11 Support in GCC
GCC 4.8.1 was the first feature-complete implementation of the 2011
C++ standard, previously known as C++0x.
This mode can be selected with the -std=c++11 command-line flag, or
-std=gnu++11 to enable GNU extensions as well.
Link: https://gcc.gnu.org/projects/cxx-status.html
I am trying to get the #include <experimental/any> to compile in my C++ program on clang OSX
// test.cpp
#include <experimental/any>
int main() {
return 0;
}
Tried following commands/options as learnt from here
clang++ -std=c++14 test.cpp -o test -std=c++1z -stdlib=libc++
clang++ -std=c++1x test.cpp -o test -std=c++1z -stdlib=libc++
clang++ -std=c++1y test.cpp -o test -std=c++1z -stdlib=libc++
clang++ -std=c++1z test.cpp -o test -std=c++1z -stdlib=libc++
But it doesn't compile & complains of the following error:
fatal error: 'experimental/any' file not found
clang++ --version yields following:
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
How can I get #include <experimental/any> to compile?
Should I upgrade clang on my machine?
Is C++17 supported on clang currently as of today? If yes how can get the support for it?
For OSX 10.12.5 (using Xcode Developer tools), we get
> clang++ -v
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
and there is no any in /Library/Developer/CommandLineTools/usr/include/c++/v1/experimental, but only
chrono
optional
string_view
tuple
utility
algorithm
dynarray
ratio
system_error
type_traits
So, it appears that Apple's libc++ does not provide any (there is no any in /Library/Developer/CommandLineTools/usr/include/c++/v1/ either). You must either use GCC or your own clang or boost/any.hpp, all of which you can install via homebrew.
You misspelt it. It's "experimental", not "experimentals".
However, since Clang 4.0, you should just be using <any>.
I am using clang 3.5 as distributed by them. I'm using the following command lines to install it in my travis vm:
sudo apt-add-repository 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.5 main'
sudo apt-add-repository 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.5 main'
When I run my test build with optimizations turned on, I get this error:
clang: error: optimization flag '-finline-functions' is not supported
"clang++" -c -x c++ -std=c++1y -Werror -O3 -finline-functions -Wno-inline -Wall -Werror -pthread -fPIC -std=c++1y -DBOOST_ALL_DYN_LINK -DNDEBUG -I"." -I"gamgee" -I"lib/htslib" -o "test/bin/run.test/clang-linux-3.5.0/release/threading-multi/sam_builder_test.o" "test/sam_builder_test.cpp"
I don't get the same error on my mac which runs the older 3.4 version of clang.
Has clang cut support to -finline-functions in 3.5? Is this something specific about this package build? How should one substitute the -finline-functions option for optimized builds with clang-3.5+?
See this commit: http://llvm.org/klaus/clang/commit/6590426aeb5275ec33dac2877f9349bbbb2d4b2e/#0-L-571
Previously, that flag was ignored and the user was not notified. Now the user is notified that it is ignored. You shouldn't have seen any difference in the code generation with or without that flag.
It should only be a warning, but you've upgraded it to an error with -Werror.