build2: compiler does not support modules - c++

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.

Related

How do I compile with C++98 on MacOS?

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.

Eclipse Kepler configuring c++ 11

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

std::stoi() not declared in this scope, g++ (GCC) 5.3.0

I'm still having an issue with the bug from g++ 4.6.1 however the solution provided doesn't seem relevant to g++ 5.3.0. Is there any other workaround besides installing mingw-w64?
My build command is:
g++ main1.cpp main2.cpp -g -std=gnu++11 -o program.exe

cc1plus: error: unrecognized command line option "-std=c++0x"

I am trying to make using g++. At first, I upgraded my gcc version by compiling the package locally, and add some environment path to my ~/.bashrc
alias gcc='/home/rescape/lib/bin/gcc'
alias g++='/home/rescape/lib/bin/g++'
export CC=/home/rescape/lib/bin/gcc
export CPP=/home/rescape/lib/bin/cpp
export CXX=/home/rescape/lib/bin/c++
And I try g++ -v in terminal:
[rescape#iZ231twjza6Z mxnet]$ g++ -v
Using built-in specs.
COLLECT_GCC=/home/rescape/lib/bin/g++
COLLECT_LTO_WRAPPER=/home/rescape/lib/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --prefix=/home/rescape/lib/
Thread model: posix
gcc version 4.8.0 (GCC)
Still, When I do make, such error message occurs:
[rescape#iZ231twjza6Z mxnet]$ make
g++ -std=c++0x -DMSHADOW_FORCE_STREAM -Wall -O3 -I./mshadow/ -I./dmlc-core/include -fPIC -Iinclude -msse3 -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMXNET_USE_OPENCV=1 `pkg-config --cflags opencv` -fopenmp -MM -MT build/resource.o src/resource.cc >build/resource.d
cc1plus: error: unrecognized command line option "-std=c++0x"
make: *** [build/resource.o] Error 1
Any suggestions of how to fix this? Thanks!
According to this:
[rescape#iZ231twjza6Z mxnet]$ make
g++ ...
You not use CXX variable in your Makefile, so just replace g++ with CXX in your Makefile. aliases works only when you enter commands in your shell, if you type g++ something.cpp bash execute /home/bin/g++ something.cpp, that's all, bash aliasing not help if external process (in our case make) execute g++

/usr/local/lib/gcc/x86_64-apple-darwin10.8.0/4.6.4/libgcc.a warning

I have a warning involving /usr/local/lib/gcc/x86_64-apple-darwin10.8.0/4.6.4/libgcc.a. I was trying to compile a C++ project using a Makefile, which shows the following:
executeit: bplustree.o nonleafnode.o leafnode.o
g++ -o executeit bplustree.o nonleafnode.o leafnode.o
bplustree.o: bplustree.cpp
g++ -g -c bplustree.cpp
nonleafnode.o: nonleafnode.h nonleafnode.cpp
g++ -g -c nonleafnode.h nonleafnode.cpp
leafnode.o: leafnode.h leafnode.cpp
g++ -g -c leafnode.h leafnode.cpp
clean:
rm executeit bplustree.o nonleafnode.o leafnode.o
When I invoke "make", I get the following output in Terminal:
g++ -g -c bplustree.cpp
g++ -g -c nonleafnode.h nonleafnode.cpp
g++ -g -c leafnode.h leafnode.cpp
g++ -o executeit bplustree.o nonleafnode.o leafnode.o
ld: warning: in /usr/local/lib/gcc/x86_64-apple-darwin10.8.0/4.6.4/libgcc.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
As you can see, I have gcc version 4.6.4. I am not sure if this warning is a threat to the project working in any way, but I would like to know what this warning means and if it is a threat. It would be nice if I can do something to remove it, too. Thank you.
I have Mac OS X Version 10.6.8. The file /usr/local/lib/gcc/x86_64-apple-darwin10.8.0/4.6.4/libgcc.a has "10.8.0", and this version of gcc I installed must have screwed me over. I don't know if I can remove this warning by installing OS X 10.8.0, but I will consider this question answered for now. Thank you.