c++ compiles in Ubuntu but not in centOS - c++

I have a bunch of code which compiles in Ubuntu using GCC 4.8.4.
When I transfer to centOS and compile it there the following errors occur:
[ 0%] Building CXX object src/chrono/CMakeFiles/ChronoEngine.dir/core/ChClassRegister.cpp.o
In file included from /home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.cpp:21:
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h: In destructor 'chrono::ChClassFactory::~ChClassFactory()':
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h:225: error: expected initializer before ':' token
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h:228: error: could not convert '((chrono::ChLog*)chrono::GetLog())->chrono::ChLog::<anonymous>.chrono::ChStreamOutAscii::operator<<(((const char*)"Delete ChClassFactory \012"))' to 'bool'
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h:229: error: expected primary-expression before '}' token
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h:229: error: expected ')' before '}' token
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h:229: error: expected primary-expression before '}' token
/home/com/medyn/chrono/chrono_ver1/Chrono_source_Old/src/chrono/core/ChClassRegister.h:229: error: expected ';' before '}' token
make[2]: *** [src/chrono/CMakeFiles/ChronoEngine.dir/core/ChClassRegister.cpp.o] Error 1
make[1]: *** [src/chrono/CMakeFiles/ChronoEngine.dir/all] Error 2
make: *** [all] Error 2
These errors are for both GCC 4.4.7 and GCC 4.8.5.
The lines of code for which it gives the error are:
~ChClassFactory () {
for(const auto & it : class_map ) {
GetLog() << " registered: " << it.first << "\n";
}
GetLog() << "Delete ChClassFactory \n";
}
And the files included at the top of this script are:
#include <stdio.h>
#include <string>
#include <typeinfo>
#include "core/ChLog.h"
#include "core/ChRunTimeType.h"
#include <unordered_map>
I have checked that all of the include files exists and I have made another script to test if I can use them, and I can.
The reason why I don't stay with Ubuntu is because the Supercomputer I have to use is running centOS.
Does anyone have a solution for this problem?
Please let my know if you need additional information.
Regards,
Anders
Edit
With the GCC 4.8.5 version the program provided by NathanOliver compiles and run.
I compile it directly from terminal using:
g++ -std=c++11 main.cpp -o main
./main
1 2 3 4 5
And it runs with -std=c++0x.
Somehow I cant use -std=c++14.
It gives the following error:
g++: error: unrecognized command line option '-std=c++14'
Edit
So to get back to the main problem. My Makefile I have, have the following line:
//Flags used by the compiler during all build types.
CMAKE_CXX_FLAGS:STRING=-std=c++0x
So I can't see why the program should not run?

Related

gfortran compilation error: FORM specifier in OPEN statement at (1) has invalid value 'print'

I am trying to compile an old Fortran 77 code (.f file) using GNU gfortran (configured with gcc 4.8.1) on a mac 10.8 and I am getting this error even on using -std=legacy flag.
gfortran -std=legacy -o grdsp96 grdsp96.f
grdsp96.f:1872.72:
open (1,file=dfile(i),access='append',form='print')
1
Error: FORM specifier in OPEN statement at (1) has invalid value 'print'
grdsp96.f:2052.72:
open (1,file=dfile(i),status='unknown',form='print')
1
Error: FORM specifier in OPEN statement at (1) has invalid value 'print'
make: *** [all] Error 1
How to fix this ? Thanks.

Is it possible to compile c++ using Clang only on windows?

I really tried a lot. Clang does not come with standard C++ includes, and obviously can not find them :
clang++ file.cpp -o file.out
C:\Folder\file.cpp:1:11: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Passing the mingw includes by arguments, it returns another error:
clang++ -target x86_64-w64-mingw32 C:\Folder\file.cpp -IC:\MinGW\mingw64\lib\gcc\x86_64-w64-mingw32\6.3.0\include\c++ -IC:\MinGW\mingw64\lib\gcc\x86_64-w64-mingw32\6.3.0\include\c++\x86_64-w64-mingw32 -IC:\MinGW\mingw64\x86_64-w64-mingw32\include -o C:\Folder\file.out -std=c++11
clang++.exe: error: unable to execute command: program not executable
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
When I use -c it does not use the linker and also not generate an executable file.
Edit : I'm running on windows
Run your commands from "x64 Native Tools Command Prompt for VS 2017", or something similar. It will setup some required env vars for you.

dlib example, test builds fail

Running ubuntu 12.04, I downloaded the source and compiled it as instructed (see https://github.com/davisking/dlib). Below is the error message displayed.
cmake --build . --config Release
[ 1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bsp/bsp.cpp.o
In file included from /home/andreif/downlib/dlib-19.2/dlib/bsp/../sockets/../threads/parallel_for_extension.h:9:0,
from /home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads.h:24,
from /home/my_path/dlib-19.2/dlib/bsp/../sockets/sockets_kernel_2.h:33,
from /home/my_path/dlib-19.2/dlib/bsp/../sockets/posix.h:4,
from /home/my_path/dlib-19.2/dlib/bsp/../sockets.h:14,
from /home/my_path/dlib-19.2/dlib/bsp/bsp.h:7,
from /home/my_path/dlib-19.2/dlib/bsp/bsp.cpp:6:
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h: In function ‘std::future<typename std::result_of<_Functor(_ArgTypes="" ...)="">::type> dlib::async(dlib::thread_pool&, Function&&, Args&& ...)’:
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:63:15: error: expected nested-name-specifier before ‘bind_t’
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:63:15: error: ‘bind_t’ has not been declared
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:63:22: error: expected ‘;’ before ‘=’ token
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:63:22: error: expected primary-expression before ‘=’ token
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:63:24: error: expected primary-expression before ‘decltype’
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:63:24: error: expected ‘;’ before ‘decltype’
/home/my_path/dlib-19.2/dlib/bsp/../sockets/../threads/async.h:64:37: error: ‘bind_t’ was not declared in this scope
make[2]: [dlib_build/CMakeFiles/dlib.dir/bsp/bsp.cpp.o] Error 1
make[1]: [dlib_build/CMakeFiles/dlib.dir/all] Error 2
make: *** [all] Error 2
The problem was my c++ compiler: the default gcc 4.6 in ubuntu 12.04 has c++11 support, but it has to be enabled at the command line when calling it. I tried editing /.bashrc to automatically do this, but it didn't work. The solution for me was to install gcc/g++ 4.8 (and use update-alternatives to keep the old installation usable), as described here
http://mortenvp.com/installing-a-newer-gccg-on-ubuntu-12-04-lts/

error: 'log1p' is not a member of 'std'

I create a simple main function and above it, I include armadillo library.
#include <armadillo>
I compiled it using g++ (version of GCC is 5.3) and under cygwin 64bit on windowse 8. I turned on c++11 option and added -larmadillo for linking to armadillo library.
Once I compile the code, I receive such horrible error. The same code runs absolutely fine on windowse XP 32 bit.
usr/include/armadillo_bits/compiler_setup.hpp:73:88: note: #pragma message: WAR
NING: #define ARMA_DONT_USE_CXX11 before #include <armadillo>
#pragma message ("WARNING: #define ARMA_DONT_USE_CXX11 before #include <arm
adillo>")
^
In file included from /usr/include/armadillo:310:0,
from main.cpp:1:
/usr/include/armadillo_bits/arma_cmath.hpp: In function 'float arma::arma_log1p(
float)':
/usr/include/armadillo_bits/arma_cmath.hpp:270:12: error: 'log1p' is not a membe
r of 'std'
return std::log1p(x);
^
compilation terminated due to -Wfatal-errors.
Makefile:110: recipe for target 'main.o' failed
make: *** [main.o] Error 1

has ::std::has_nothrow_default_constructor been moved/changed?

In trying to build boost mirror with gcc 4.7.2, I ran into this error, but oddly enough, I see this documentation.
Has ::std::has_nothrow_default_constructor been moved/changed?
In file included from /home/kfeng/src/mirror-lib/include/mirror/type_traits.hpp:20:0,
from /home/kfeng/src/mirror-lib/include/mirror/mirror_base.hpp:38,
from /home/kfeng/src/mirror-lib/include/mirror/mirror.hpp:16,
from /home/kfeng/src/mirror-lib/src/mirror/example/all_member_variables.cpp:10:
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:2: error: ‘has_nothrow_default_constructor’ is not a member of ‘std’
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:28:9: error: parse error in template argument list
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:43: error: expected ‘{’ before ‘::’ token
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:51: error: expected initializer before ‘||’ token
In file included from /home/kfeng/src/mirror-lib/include/mirror/type_traits.hpp:21:0,
from /home/kfeng/src/mirror-lib/include/mirror/mirror_base.hpp:38,
from /home/kfeng/src/mirror-lib/include/mirror/mirror.hpp:16,
from /home/kfeng/src/mirror-lib/src/mirror/example/all_member_variables.cpp:10:
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:2: error: ‘has_nothrow_copy_constructor’ is not a member of ‘std’
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:28:9: error: parse error in template argument list
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:40: error: expected ‘{’ before ‘::’ token
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:48: error: expected initializer before ‘||’ token
make[2]: *** [src/mirror/example/CMakeFiles/mirror-all_member_variables.dir/all_member_variables.cpp.o] Error 1
make[1]: *** [src/mirror/example/CMakeFiles/mirror-all_member_variables.dir/all] Error 2
make: *** [all] Error 2
ANSWER using Pubby's Note Below
Something like this should work with gcc 4.7.2 - I will submit a patch and let the maintainer decide how best to deal with it.
template <typename T>
struct is_default_constructible
: std::integral_constant<
bool,
::std::has_trivial_default_constructor<T>::value ||
#if __cplusplus>=201103L
::std::is_nothrow_default_constructible<T>::value ||
#else
::std::has_nothrow_default_constructor<T>::value ||
#endif
mirror::_class::_<T>::has_default_ctr::value>
{ };
In C++11 it was changed to std::is_nothrow_default_constructible to be more consistent with naming.
You are looking at documentation for GCC 4.6.2, but using GCC 4.7.2, so it's not very surprising they don't match.
The traits were renamed by n3142
See a previous answer of mine https://stackoverflow.com/a/12716778/981959 for some code that attempts to detect which is supported by your compiler, although a comment says it doesn't work with libc++.