CMake fails on Mac [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am running a C++ program to test code in my C++ project. I have successfully run it using Eclipse. However, when I try to build it using CMake (for automated testing) it hits the following issue:
The cmake command resolves without problems, but when I run make, it fails with errors of the following three categories:
In file included from /Users/douglas/Desktop/automatedTesting/src/main.cpp:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:169:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:641:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
In file included from /Users/douglas/Desktop/automatedTesting/src/string.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:139:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/streambuf:139:5: error:
unknown type name 'locale'
Along with ‘locale’ the same issue occurs with ‘streamsize’
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/streambuf:155:41: error:
incomplete type 'std::__1::ios_base' named in nested name specifier
And lastly:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:98:24: note:
forward declaration of 'std::__1::ios_base'
These errors are repeated multiple times until a total of 20 are generated, at which point it gives the following final output:
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [CMakeFiles/makeTest.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/makeTest.dir/all] Error 2
make: *** [all] Error 2
My CMakeLists.txt is the following:
cmake_minimum_required (VERSION 2.6)
project(makeTest)
set (makeTest_VERSION_MAJOR 1)
set (makeTest_VERSION_MINOR 0)
add_executable(makeTest src/main.cpp serial-messenger/forTest.cpp src/String.cpp src/parson.c)
target_include_directories(makeTest PRIVATE src)
target_include_directories(makeTest PRIVATE serial-messenger)
Environment details:
OS: Mac OS High Sierra version 10.13.4
CMake: 3.13.0
CLANG: Apple LLVM version 9.1.0 (clang-902.0.39.2)
XCode is installed
I'm sure I must have made some error with setting up the environment for CMake, but I have no idea what it might be.
Edit: it looks like since Macs are case insensitive, it is mistaking my String.h file for string.h, causing the problem.
Edit 2: The problem was indeed due to Mac being case insensitive. Running it on a case sensitive OS like Linux resolves the issue.

Never give a standard name to a header with custom functionality!
Changing only a case (lower to upper or vice versa) isn't a good idea too.
According to the include chain in the error message, the system header file
.../usr/include/c++/v1/cstring
actually includes a custom one
.../automatedTesting/src/string.h
This is because you give a standard name string.h to your custom header. (Well, the actual name of the file is String.h, but MacOS uses a case-insensitive filesystem). And this is a real problem: the system header expects to obtain some standard definitions with such include, but the custom header doesn't provide them.
Rename your custom header to the non-standard name (e.g., mystring.h) and adjust your #include directives accordingly.

Related

How to compile a cpp file with the alglib library?

I'm working on a C++ code on linux that needs some special functions which can be provided by alglib: https://www.alglib.net/download.php. The thing is, i'm new to Ubuntu so I don't know how to install the library or execute the files I need for my program.
The library's manual (https://www.alglib.net/translator/man/manual.cpp.html#gs_attaching) explain that you should just pick the packages you need and add them to your project, so I downloaded the tgz file and added specialfunctions.h, and executed it like this:
#include<math.h>
#include<stdio.h>
#include<specialfunctions.h>
But when I run the compiler through terminal I get this error:
analitica.cpp:3:9: fatal error: specialfunctions.h: No such file or directory
3 | #include<specialfunctions.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
Someone has a hint of what i'm doing wrong?

IWYU failing/unclear output?

I recently installed include-what-you-use (IWYU) to try it out. I am on version include-what-you-use 0.12 based on clang version 9.0.1-10. (My OS is Ubuntu 20.04 on WSL1)
I tried to do a very simple example on a source code file, but it quickly comes back as an error on the very first include? (Which is just a c standard library file)
After running
include-what-you-use myutils.cpp:
In file included from myutils.cpp:8:
In file included from ./myutils.h:11:
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/cfloat:42:10: fatal error: 'float.h' file not found
#include <float.h>
^~~~~~~~~
Why is it error'ing out on a c standard library include?
I cannot post the entire source here, and without extensive testing I am not sure what minimal example would cause this problem.
Am I just mis-using IWYU? I installed it via apt rather than building it and llvm/clang/etc from scratch. Is that fine?

Why am I getting this error with MinGW and Cmake?

So I am trying to compile this flip fluids addon with blender, so I followed this tutorial, https://www.youtube.com/watch?v=TVKM1egDoGs , So I first ran cmake.exe -G "MinGW Makefiles" .. and it was telling me that it was missing a CMakeLists File... So I added one... then I ran cmake.exe --build . and it got to 3 percent than showed me errors like ...
In file included from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/threadutils.h:29,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshlevelset.h:65,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshobject.h:30,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/fluidsimulation.h:38,
from C:\Users\N\Downloads\Blender-FLIP-Fluids-master\src\engine\c_bindings\fluidsimulation_c.cpp:25:
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/mutex:93:9: note: previous definition of 'class std::recursive_mutex'
class recursive_mutex : private __recursive_mutex_base
^~~~~~~~~~~~~~~
In file included from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.condition_variable.h:25,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/threadutils.h:31,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshlevelset.h:65,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshobject.h:30,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/fluidsimulation.h:38,
from C:\Users\N\Downloads\Blender-FLIP-Fluids-master\src\engine\c_bindings\fluidsimulation_c.cpp:25:
C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.mutex.h:142:44: error: conflicting declaration 'typedef class std::_NonRecursive<std::recursive_mutex> std::mutex'
This is the full error https://pastebin.com/KTnALG1E, where is this coming from?? is it a mingw error or what? Can someone help please?
Your full error message includes a more interesting bit:
C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.thread.h:32:2:
error: #error This version of MinGW seems to include a win32 port of
pthreads, and probably already has C++11 std threading classes
implemented, based on pthreads. It is likely that you will get class
redefinition errors below, and unfortunately this implementation can
not be used standalone and independent of the system header,
since it relies on it for std::unique_lock and other utility classes.
If you would still like to use this implementation (as it is more
lightweight), you have to edit the c++-config.h system header of your
MinGW to not define _GLIBCXX_HAS_GTHREADS. This will prevent system
headers from defining actual threading classes while still defining
the necessary utility classes.
So either install a different version of mingw or edit your mingw files according to the instructions above.

Fatal error comp.h not found Netbean 8.0

I know this is not the new issues, and i had do all the research check you any possible solution match my problem. Unfortunately, i couldn't found any.
Im using Mac Yosemite 10.10, Netbean 8.0 compiling an cpp project code. I notice my issues was during compiling the system will look for omp.h at
/usr/local/Cellar/libiomp/20150401/include/libiomp/omp.h
However, error was show the omp.h not found
In file included from <built-in>:339:
In file included from <command line>:4:
./predict_common.h:25:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
make[2]: *** [build/Debug/GNU-MacOSX/build_vocabolary.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
Note: This also some warning (yellow underline) at the code that #include not found.
My previous solutions was
1) Copy the omp.h file to /usr/include/ .since i notice the Netbeans was looking header files at this location. So at programming code, yellow underline was gone.
However, during compilation, system found both omp.h in different location and shown cogflict errors.
2) Remind omp.h file at /usr/include/ and remove the one at /usr/local/Cellar/libiomp/20150401/include/libiomp/omp.h
Funny was, during half way of compiling, system show error omp.h file not found at
/usr/local/Cellar/libiomp/20150401/include/libiomp/omp.h location!
I was wonder do I miss out to set PATH? what should i do and any setting need to me done in Netbeans ? Please assist..Thanks
In project properties under Build -> C Compiler edit the include directories textfield and add the directory containing that header file.
You should delete the extra copy you put in /usr/include to avoid conflicts.
The Solutions
Right click at Projectname -> Propertise -> C compiler
at
1) Include Directories -> add
/usr/local/Cellar/libiomp/20150401/include/libiomp/
*Note: at terminal check where is omp.h located by
$locate omp.h
Although it listed more than one location, but you should identify when you install clang-omp where might same location.
2) Include Header ->
omp.h
For the above solutions, it works for me.

Compilation error: "stddef.h: No such file or directory"

Whenever I try to compile this code it always ends up with this error:
In file included from /usr/include/wchar.h:6:0,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/cwchar:44,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iosfwd:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ios:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iostream:39,
from test.cpp:1:
/usr/include/sys/reent.h:14:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
The code I was trying to compile is:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World! :D";
return 0;
}
The error is because your gcc-core package and gcc-g++ are not of the same version. Either downgrade one of them to solve the problem or update both the libraries. Updating both the libraries is the recommended way.
I had this error on a fresh MinGW install, it had nothing to do with the installed packages mentioned in the current accepted answer by "Prasanth Karri". In my case the issue was caused by -nostdinc in my Makefile. I actually only needed that compiler flag when building for a different target platform (not when using MinGW) so I fixed the issue by removing that flag from MinGW builds.
When I was incorporating a software library written in C into an existing demo project(used a C++ mbed library) I encountered this problem. The demo project would compile just fine, but after I replaced the existing main file by my own, this error occurred.
At this point I hadn't yet thought about the fact that the mbed library that I needed was written in C++. My own main file was a .c file that #include the mbed header file. As a result I used my normal C source as if it was a C++ source. Therefore the compiler that was used to compile my main file was the C compiler.
This C compiler then encountered a #include of a module that actually does not exist (within its scope), as it's not a C++ compiler.
Only after I inspected the output of the build log I realised the various source C and C++ files were compiled by more that 1 compiler(the c++ compiler). The project used used compilers arm-none-eabi-c++ and arm-none-eabi-gcc (for embedded systems) as seen below.
Compile log:
Building file: ../anyfile.cpp
Invoking: MCU C++ Compiler
arm-none-eabi-c++ <A lot of arguments> "../anyfile.cpp"
Finished building: ../anyfile.cpp
Building file: ../main.c
Invoking: MCU C Compiler
arm-none-eabi-gcc <A lot of arguments> "../main.c"
In file included from <Project directory>\mbed/mbed.h:21:0,
from ../main.c:16:
<Project directory>\mbed/platform.h:25:19: fatal error: cstddef: No such file or directory
compilation terminated.
Of course in a C++ environment cstddef exists, but in a C environment cstddef doesn't exist, in stead it's just C's implementation of stddef.
In other words, cstddef does not exist in the C compiler.
I resolved this problem by renaming my main.c file to main.cpp and the rest of the code compiled smoothly too.
TLDR/Conclusion: When building a C++ project, avoid mixing C files with C++ files(sources and headers). If possible rename .c files to .cpp files to use the C++ compiler in stead of the C compiler where required.
In order to update it, follow below.
If you are on Windows, just run these on command prompt or powershell
Update the package list: mingw-get update
After updating the package list, run: mingw-get upgrade
Source: How to update GCC in MinGW on Windows?
This problem was solved for me as I installed codeblocks with mingw compiler then I copied the mingw folder from codeblocks to C drive and added
C\mingw\bin to the environment variables.
If you try to compile and see a message like, "fatal error: stddef.h: No such file or directory", the error is because your gcc-core and gcc-g++ packages are not of the same version. Rerun the Cygwin install and make sure that you select the highest numbered versions of gcc-core and gcc-g++.
After installing the C++ compiler with MinGW I encountered this problem as well. Apparently, you have to also install mingw32-base. Go to C:/MinGW/bin/mingw-get.exe (my path) and check it for installation at the Basic Setup tab.