Compiler settings

@pgatt has very nicely been helping with compiling for Mac (Thank you!!). The mac compiler trips over all kind of things where I do not even get warnings on win/msys2. It seems the latter automatically includes stuff that not happens on a mac so it is very hard to debug. For example #include < array >

Are there settings / flags for the g++ compiler that makes it nag on the same things as the mac? I tried tor read the man pages … really I did…

(Read about azure pipelines, that may be a next step)

The azure pipelines are well worth the time investment to setup. I took a diff of what I had to change after importing baconpaul’s scripts and yaml for my repo. I’ve since changed the release from “Nightly” to “Development” to better show it’s continuous integration rather than an actual nightly build.

azure.diff.txt (4.0 KB)

I’d still be Linux only without it.

1 Like

you can always install clang/clang++ on linux and compile with that instead of g++.

As Jerry hinted at, but didn’t actually state, the compiler on the mac is clang, whereas on windows and linux it’s gcc. There is a gcc on the mac, but it’s just a wrapper around clang that makes clang act kind of like gcc.

Jerry was suggesting that one possibility is to use clang on Linux, which is definitely possible, although last time I did it I had to build it myself and it took a very long time.

For me, the differences on the mac means yet another chance to catch some potentially wrong code, so there is sort of a silver lining to this difference.

btw: I’ve never tried clang on windows, but it seems possible to do.

Unless we are talking about some really old Apple operating system and Xcode. They used to use GCC themselves back in the day. I don’t think the original poster clarified what kind of Mac system he is using.

Do you really think a system that old would build rack? I’ll bet you 5 cents that it couldn’t even support c++11.

1 Like

Well, didn’t he say in the original post that the compiler can’t even use std::array? (Which is C++11 stuff.) edit : I probably misunderstood…

I think they meant that array was being included elsewhere in the compilation path in g++ and not in clang++ - at least that’s how I read it.

older Xcode with g++ doesn’t support rack - given that the SDK itself is too old, so that was kind of moot to me :slight_smile:

That’s not GCC on Mac, that “just a wrapper around clang that makes clang act kind of like gcc”. You can build GCC on Mac if you want though, but it likely won’t work with a lot of Mac-specific APIs.

Rack uses the C++11 version of c++. I’m not 100% sure, but I believe you must use a compiler that understands that dialect of the language.

1 Like

Yes, I was not utterly accurate there. How about “XCode comes with a program called gcc, but it is just a wrapper around clang. The make files that come with the rack sdk assume you have something installed that at least resembles gcc. That’s why you can compile on the mac without installing real gcc. The gcc wrapper around clang will compiler rack itself, and will compile any “normal” plugin. But will give different compiler warnings.”

1 Like

That’s indeed what I assume(d).

c++  -std=c++11 -stdlib=libc++   -fPIC -I../../include -I../../dep/include -MMD -MP -g -O3 -march=nocona -funsafe-math-optimizations -Wall -Wextra -Wno-unused-parameter -DARCH_MAC -mmacosx-version-min=10.7  -c -o build/src/Bezosc.cpp.o src/Bezosc.cpp
src/Bezosc.cpp:67:25: error: implicit instantiation of undefined template 'std::__1::array<float, 24>'
  std::array<float, 24> xy;
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tuple:223:64: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;

This goes away after including < array > yet without < array > there is no problem here on Windows. Same for < string >

FIW I’ve got clang on FreeBSD. There’s also clang for Msys2.

It’s an implementation detail in the compiler/toolchain whether something gets included “automatically” or not. The standard way to do things is to always explicitly include in the code the headers you are using.

indeed. and it’s always a surprise going between compilers if you forget to explicitly include something that the other compiler (usually g++ in my case) doesn’t include.

still better than the old days :slight_smile:

4 sure!

How about -Wpedantic or -Wall etc. ?

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

Thanks for the link. pedantic didn’t add anything in this case.

This is strange - I added now -Wpedantic for testing (Linux build) and build Rack and a Plugin and gcc prints warnings like crazy for almost every compilation unit.

Are you sure that you put it into right place?

FLAGS += -Wpedantic in the make file. Not the right spot?

I used my own CMake based build environment for VCVRack and added it there.

But now I tested it also with normal Makefile and added -Wpedantic here - https://github.com/VCVRack/Rack/blob/v1/Makefile#L5 and gcc prints all the pedantic warnings.

I don’t know if you just build a plugin - the you maybe have to add it also here - https://github.com/VCVRack/Rack/blob/v1/plugin.mk#L17

To see if your flags are correct you can call make like this: VERBOSE=1 make and you see complete compiler invocation with all given parameters and flags. Check if it contains -Wpedantic.