How to set c++ compiler on OS X with bazel? - c++

How can you tell bazel to use a different C++ compiler on OS X?
bazel build --action_env CC=/path/to/compiler //:target
works on linux.
But -s shows that bazel always runs with external/local_config_cc/wrapped_clang (clang) on OSX regardless of what CC is.

CC correctly works only when you use the C++-only toolchain. If you have Xcode installed, bazel will detect this and automatically pick a different toolchain, the one that supports both C++ and ObjC. This toolchain can only use Xcode-provided clang.
This is unfortunate and I propose two solutions:
File a feature request for bazel to make it possible to select which toolchain is used. This will allow you to tell bazel that even though you have Xcode installed, you want to use C++ only toolchain with a custom compiler. This is quite simple and doable in a short time.
File a feature request for bazel to make it possible to select which compiler is used with C++/ObjC toolchain. I cannot comment on viability of this, I know next to nothing about osx, and I have no idea if it makes any sense to compile ObjC with a compiler that is not provided with Xcode...

Actually with the latest version of bazel specifying
BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
build --action_env CC=/path/to/compiler [...]
does work, in the sense that the specified compiler is used. However there is still a problem with the compiler flags. If the compiler flags of the old compiler are incompatible with the new one, there is a problem. I still have to find out how to change compiler flags.

Use --crosstool_top.
See also --host_crosstool_top and --apple_crosstool_top.

Related

Clion Intel C++ compiler setup

Clion does not officially support Intel C++ compiler but I found the information that it suppose to work. I am just not sure how to correctly setup the toolchain. At the moment I am successfully using the clang compiler. Simply changing to icc compiler fails to compile a simple test program. Unfortunately I could not find any more guidance about setting up the icc compiler on Clion, could someone more experienced to share some insights?
Currently:
Want to use intel c++:
I am using cygwin compiler (make, gdb, gcc, g++) GNU Project. I am specifying Clion's path to cygwin (gcc, cmake, make, g++) in File -> Settings -> Build, Execution, Deployment -> Toolchain. Click me - image settings Clion
Update 2021-12-06
From 2021.3, you can use a System toolchain for this.
Set environment variable VS2019INSTALLDIR or VS2017INSTALLDIR
Create a System toolchain in CLion
Add environment from file %ONEAPI_ROOT%\compiler\latest\env\vars.bat
Set MKake as nmake, C Compiler and C++ Compiler as icx
Note that you can't use icl, as cmake will fail when getting compiler information.
Original answer
You need to edit some environment variables.
Add %ICPP_COMPILER20%bin\intel64 to PATH
Add %ICPP_COMPILER20%compiler\lib\intel64 to LIB; but mostly LIB does not exist, so create this variable
You may need to modify the 20 in %ICPP_COMPILER20% to match your installation.
With the above steps, you should be able to pass the compiler check. However, CLion will complain "Unexpected compiler output".
This means you can compile your program with no issue, but the IDE can't recognize any header file and simply marks them as "not found".

In C++, what is wx.h?

The existing code is calling some sort of wx header file and my DEV C++ compiler just says there's no such file.
Code:
#include<wx/wx.h>
Compiler error:
[Error] wx/wx.h: No such file or directory
So my question is -
What is wx.h
How do I install it in my compiler so that I can use it?
Do I need to change my compiler or DEV C++ would do fine?
What is wx.h
It is the header file of a library. The GitHub project should have some instructions on how to fetch the dependencies and how to install them.
How do I install it in my compiler so that I can use it?
Normally you have to download the dependency, build it (following some instructions), and then you need to use the header in your project and link the library. The exact steps depend on each library and each compiler.
Do I need to change my compiler or DEV C++ would do fine?
In principle, no. Some libraries only work with some compilers, though.
Note that Dev-C++ is not a compiler, it is an IDE that comes with a port of GCC (as far as I know).
It seems that you are using WxWidgets framework but your compiler doesn't know where to find its headers, and apparently also libs which you would face with on a next step.
You, need to add to your compiler flags the output of wx-config --cxxflags. And also to your linker flags the output of wx-config --libs.
Assumption is of course that WxWidgets is installed on your PC

Show compiler info in Bazel

I am trying to report a bug for a project using Bazel. As part of the issue report I would like to include information about the used C++ compiler.
Which command can I use to do so?
bazel build -s //the_target shows me that external/local_config_cc/wrapped_clang seems to be the compiler. In bazel-<project>/... I can find that path, but running the executable wrapped_clang in there, just leads to an abort.
This answer only applies if you're using Bazel autoconfigured C++ toolchain. If you don't you'll have to modify it.
So for debugging the best would be to zip entire local_config_cc and also to provide version of the compiler ($CC --version). You get the local_config_cc at:
`bazel info output_base`/external/local_config_cc
Path to the compiler is written into the wrapped_clang script in case of the toolchain that supports both C++ and ObjC (this one gets enabled when Xcode is properly detected). C++ only toolchain invokes compiler directly (but the CROSSTOOL file can still be useful for debugging). And just in case, you can force C++ only toolchain by setting BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 environment variable.

Why doesn't Clang come with standard library headers?

I downloaded Clang 3.6.2 from this website and am trying to set it up with Code::Blocks under Windows. Unfortunately, it fails to compile a simple "hello world" program on the grounds that it doesn't know where iostream is.
Looking through the install folder, it does not appear to include a standard library with it. Why? And how do I get it?
The standard library is NOT part of the compiler itself. It is part of the runtime environment on a particular platform. Sure, some organisations put together a "kit" with all the necessary parts to build an application - there may even be someone that packages a Clang compiler with a suitable runtime.
In general, you should be able to download the Windows SDK and get the relevant header files there - and if you use clang-cl, it should be largely compatible with the MSVC compiler [or provide clang or clang++ with the correct -fms-compatibility or whatever it is called].
Or as suggested in the other answer, use libcxx, but it's not 100% complete for Windows.
They do have a c++ standard library: libcxx.llvm.org. But it's not fully supported on the windows platform.

How to properly switch between gcc versions?

I want to play with C++ 2011, so I need the unreleased gcc 4.7. I was able to succesfully get the svn trunk and compile it.
I want to keep the default gcc of my system for safety, so I configured gcc4.7 with a --prefix and installed it in a non-standard location.
Now how should I enable gcc 4.7 over the default gcc of my system ?
I already changed the CC and CXX variables, I updated my PATH to point on the gcc 4.7 bin dir first. When I type gcc --version I get 4.7 OK.
But gcc is more than just an executable. There are many executables in gcc install dir. There are also default includes and std lib c++.
So far, every blog entry / SO question I found on this subject speaks only about the gcc and g++ executables.
Can anyone give me a list of the changes I need to do to the environment to fully use gcc 4.7 ?
update LD_LIBRARY_PATH ? How to give precedence to gcc 4.7 system includes ? Are there other things to consider ?
Thanks in advance.
I would think that THE g++ is pretty much tangled up with things using C++ as the C library is tangled up with the system! Any layout changes in the C++ library classes will cause incompatibilities with other C++ programs or libraries. Thus, I wouldn't replace the system's C++ compiler or, more importantly, its standard C++ library at all (unless, maybe, the compiler vendor makes a strong claim that they retained binary compatibility with the version you are replacing).
To play or even use a different version of g++, using the prefix approach works fine. All the compiler specific tools are implicitly called from within g++ using an appropriate version and tools like ar, ld, ranblib, etc. are not really depending on the compiler version anyway. The important components uses internally are the standard library (both the headers and the library) and the preprocessor. When calling a version of g++ it figures out which of these it really needs.
BTW, when you want to play with C++2011 you can also have a look at clang.
The simplest answer is: nothing; it just works. :)
GCC finds what it needs first relative to itself, second in the "prefix" it was configured with, and finally in the standard places. By this means it's perfectly safe to relocate it wherever you like, as long as you relocate all of it - but beware that the fall back behaviour can hide brokenness if the install is incomplete.
Look at the GCC Configuration docs. I am using program suffixes to distinguish between the different GCC versions. To do that add, e.g., --progam-suffix=-4.7 to your ./configure invocation.