[CMake] Comaptibility with older gcc

Dan Liew dan at su-root.co.uk
Sat Jan 28 04:45:47 EST 2017


> I was also doubting about libstdc++ versions, is there maybe a way of asking
> Cmake to statistically include it in the built library?

I assume you mean statically. If so then you could try invoking cmake
like this on the command line.

```
mkdir new_build_dir
cd new_build_dir
CXXFLAGS="-static-libstdc++ " CFLAGS="-static-libstdc++" cmake
/path/to/source/tree
make -j$(nproc)
```

Note that `new_build_dir` must be empty every time you invoke the
`cmake` command
because it will only try to detect your compiler once. Subsequent
invocations of cmake
in an existing build directory does not change the compiler and
setting CXXFLAGS and
CFLAGS to different values has no effect.

However I don't think this is the best approach. I think you would be
much better of recreating
the production environment on your development machine. This makes it
much easier to reproduce
issues you may hit in production.

There are many ways about doing this but my suggestion would be to use
Docker or a virtual machine for that purpose.

You mention you want to use Eclipse so what you could do is develop
your application on your local machine (i.e. outside of Docker or the
virtual machine)
but have your source files mounted into your Docker container (these
are called volume mounts) or the virtual machine.

That way you can use Eclipse for your development locally but when you
want to, you can do a build inside the container/vm using the same
source files
to test the build still works and also produce binaries that will
"just work" on your production system.

HTH,
Dan.


More information about the CMake mailing list