fix: too many sections (52187) - Cmake, Qmake - c++

I need to compile a C++ program on Windows using the CLion IDE with CMake and Qt Creator with QMake.
On Linux, I do not get any problems at all.
On Windows, I wanted to use the MinGW compiler. My source code relies on boost. Therefore, according to this question, I was installing the compiler from the MinGW Distro.
So far so good. Now, during the compilation process I get the following error:
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\[...]: too many sections (52187)
C:\Users\MATTHI~1\AppData\Local\Temp\cc2TyXHu.s: Assembler messages:
C:\Users\MATTHI~1\AppData\Local\Temp\cc2TyXHu.s: Fatal error: can't write 231 bytes to section .text of CMakeFiles\[...]: 'file too big'
after some research, (here and here) I found out that heavy templating might be the reason for this issue... However, I do not do any templating at all, but I'm including the Eigen libraries that might cause the issue.
In any case, I need to fix this and the proposed solution is to add the following flags to my compiler:
-Wa,-mbig-obj.
My question now is: how can I do this in my IDE (CLion or QtCreator) or in my CMakeLists.txt (CMake) and/or myProject.pro (QMake) files?

Related

Is it ok for CMake to use c++, rather than mpicxx, to compile my code?

I'm trying to build an executable from C++ source code which uses MPI, on a GNU/Linux Devuan Chimaera system. Now, I'm an MPI/OpenMP newbie, I'm just trying to adapt this code, which isn't mine, to be built with CMake - when before it had a Makefile. My build succeeds, but I'm seeing segfaults, so I want to make sure my problem isn't with the build phase, which bugs me.
My CMakeLists.txt has:
find_package(OpenMP REQUIRED)
find_package(MPI REQUIRED)
and my system has OpenMPI 4.1.1 installed, which is found. I do this for my target:
target_link_libraries(my_executable PRIVATE MPI::MPI_CXX OpenMP::OpenMP_CXX)
but nothing else which indicates its expecting to be compiled by mpicxx.
... and indeed, when I configure (with CMake 3.22.1) and then build, the usual c++ executable gets invoked to compile (and then link) the my_target executable.
Questions:
Can source code which originally was getting compiled with mpicxx be compiled with "just" a C++ compiler, with the appropriate includes?
Assuming there's any merit to using mpicxx for compilation - how do I get CMake to use it for my target?
Edit: It's been suggested to me to try using mpirun to run my program. With it, I get no segmentation faults, consistently; it's only when I run directly that I see them.
Can source code which originally was getting compiled with mpicxx be compiled with "just" a C++ compiler, with the appropriate includes?
Yes, and you're doing it correctly.
The MPI systems I've used (Cori, Perlmutter, Stampede) have all provided implementations that work correctly with CMake's MPI support. However, it's possible that a sufficiently poorly administered system will break this.
Assuming there's any merit to using mpicxx for compilation - how do I get CMake to use it for my target?
This is a toolchain setting... set CMAKE_CXX_COMPILER to /path/to/mpicxx either at the command line, in a preset, or in a toolchain file.

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

how to compare two image using mingw64 gcc/g++?

I need compare two image using mingw64 gcc/g++.
I tried https://github.com/huihut/OpenCV-MinGW-Build
but not compiled my source code.
test.cpp:1:9: fatal error: opencv2/core/core.hpp: No such file or directory
#include<opencv2/core/core.hpp>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
how to compile and compare two image using mingw64 gcc/g++?
First thing: you cant do such tasks with "MinGW gcc/g++" this is only a compiler. What you ment is hor to do such thing with C or C++ which are programming languages.
You already found a project yourself but there are some dependencies you dont have in your posted message it is OpenCV have a look at their Release page their also seem to be some precompiled windows binaries. Install this library and try again and see if you got all dependencies. Or better: always read the readmes often they tell what you need to build the projekt.

Sharing a C++ program between OSX and Linux?

I've written a relatively small C++ program in CLion, on a Mac. CLion uses CMake to compile an executable file which can only be run on my Apple machine, I know this much.
My project includes the 'ncurses' library, but other than that it only uses standard C++ ones. My question is, how do I go about running my program on another laptop, running Linux? What is the standard way of deploying C++ applications between platforms, at least between Linux and OSX which both come with a C/C++ compiler? Must CMake exist on both machines for this to be done?
Sorry for the very general question, I've been learning how to write code but not really how to go about sharing it!
To those in a similar situation, I did the following to share my code between Mac and Linux.
As I said, CLion uses CMake. I thought there would be a lot going on under the hood but it turns out all you need to compile your source files is the CMakeLists file, and an installation of CMake itself.
CLion generates the CMakeLists file, but it can be written from scratch and it only needs around 5 lines to begin compiling. In it, you declare the source files you wish to include in compilation, and a few other things, like minimum CMake version and the version of C++ your project uses.
There's a good explanation of what goes into the CMakeLists file here.
My Linux machine runs Ubuntu, and the version of CMake I was using was 2.8.something - quite early compared to 3.6 on my Mac. So firstly this meant I had to change cmake_minimum_required(VERSION 3.6) to 2.8.
Then I tried running cmake . in the directory containing the source files, which threw up a load of compile errors to the terminal. Most of which concerned things like template classes and curly brace initialisation - features of more recent versions of C++.
This was because CMake's set(CMAKE_CXX_STANDARD 11) syntax, which sets the project's C++ version, wasn't around in CMake 2.8. Replacing this line with set (CMAKE_CXX_FLAGS "-std=c++11") fixed this issue.
Another cmake . worked just fine, which then spat out a load of files into the source directory. I'm not entirely sure what all of them do, but they all surround a generated 'Makefile'. Running make in the same directory compiles all of the source files and outputs an executable, which worked perfectly.
The ncurses library seems pretty baked-in to Unix-like/based systems, so I was able to use and compile this library by simply #includeing it in my code. 3rd party libraries might require a bit more work!

How to compile c++11 code with android ndk and eclipse?

I'm using android NDK r8d, and eclipse Juno. I'm trying to compile C++ code which uses C++11 stuff like mutex, lock_guard, shared_ptr, etc. in a native android project in eclipse.
I get errors like:
"error: 'shared_ptr' is not a member of 'std'"
"fatal error: mutex: No such file or directory"
I came across a similar question here. It seems to work for them, but the explanation there is not complete so I can't get it to work for me.
I added "NDK_TOOLCHAIN_VERSION=4.7" to the Application.mk and "LOCAL_CFLAGS += -std=c++11" to Android.mk file. Still, it doesn't compile.
In the link above it says:
"Be sure that the standard library include path (like
/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) is in the
target settings."
How and where do I insert it?
I also get errors in eclipse IDE (on the source, before compiling). I know I should define "__GXX_EXPERIMENTAL_CXX0X__" to resolve them but I just don't know where to put it.
So, if someone could post an answer with a full explanation of how to compile and make eclipse work with C++11 it would be great.
Regarding your first question:
Go to Project > Properties > C/C++ General / Paths and Symbols
In the "Includes" tab, add the proper directory, e.g.
/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include
Regarding your second question, I'm also looking for an answer. It is absolutely not clear how to define the GXX_EXPERIMENTAL_CXX0X macro in Eclipse.
Some say that it should be "added as a predefined macro to the indexer", but it looks like we both could not find a way to implement that...
I have read elsewhere that it should be added to "C/C++ General / Paths and Symbols / Symbols / GNU C++" but I can't find the "Symbols / GNU C++" part in my version of Indigo.
I find export an environment variable NDK_TOOLCHAIN_VERSION=4.8 before i start eclipse can solve this problem.
Eclipse use ndk's default toolchain version 4.6, if NDK_TOOLCHAIN_VERSION is not define, and gcc witch this version does not support all c++11's future like multithread and so on.