C++ compiling error: unrecognized command line option "-std=c++11" - c++11

I am using g++ version 4.8.5. I am trying to compile my project using it. It compiles without a problem, when compiling directly from the terminal. But, when using a make file, it gives me following error, even though I am using the same option.
cc1plus: error: unrecognized command line option "-std=c++11"
What am I doing wrong here ?
Edit:
as requested, here's my makefile line:
main: main.cc
#g++ -std=c++11 main.cpp -o run

Try using g++'s absolute path:
main: main.cc
#/usr/bin/g++-4.8 -std=c++11 main.cpp -o run

Related

Why can't I install the "glmnet" package?

If I try to install the "glmnet" package, I get the following error:
Error in .shlib_internal(args) :
C++14 standard requested but CXX14 is not defined
I have tried adding the following line to my Makevars.win file:
CXX14 = g++ -std=c++1y -Wno-unused-variable -Wno-unused-function -fPIC
However, after doing this the error remains. Does anyone know what could be the problem?

omp.h' file not found while compiling source code

I am trying to compile this this source code (https://sites.google.com/site/bgcsoftware/) on a mac. I installed both hdf5 and gsl using homebrew.
Would you know what the problem might be?
Thank you in advance!
h5c++ -Wall -O2 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lm
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
bgc_main.C:17:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
1 error generated.
bgc_func_mcmc.C:12:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
1 error generated.
It looks like clang is the actual compiler being used. When compiling OpenMP with clang you need to pass the -fopenmp flag.
Try adding the -fopenmp flag like this:
h5c++ -fopenmp -Wall -O2 -o bgc \
bgc_main.C bgc_func_readdata.C bgc_func_initialize.C \
bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C \
bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lm
The -fopenmp flag tells the compiler replace the code marked with #pragma omp ... with generated parallel code and should automatically add the correct -I include flags behind the scenes.
You should be able to run
h5c++ --help | grep openmp
To see other openmp related flags, depending on your compiler/OS.
adding -fopenmp did not help. However, the original code did run when I installed:
brew install --build-from-source libomp

Edison crosscompile

I am trying to crosscompile simple hello world from Widows to Intel Edison via cmd. Instruction from here works perfectly. But I wont to use makefiles and where are not exists i586-poky-linux-make in this cross toolchain. So I decided to use mingw32-make from mingw32 binarys for Windows x86. Here is my simple makefile:
main: main.cpp
i586-poky-linux-gcc --sysroot=%POKY_HOME% main.cpp -o test -lstdc++ -O2
And... Iam getting an error
C:\Intel\iotdk-ide-win>mingw32-make
i586-poky-linux-gcc --sysroot=%POKY_HOME% main.cpp -o test -lstdc++
main.cpp:1:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
makefile:4: recipe for target 'main' failed
mingw32-make: *** [main] Error 1
How can I fix it? Thanks.

Compile C++ code containing OpenMP with manually built gcc compiler

I've downloaded from github and built gcc. After that I've tried to compile a code with OpenMP:
../GCC/build/gcc/xgcc -B./../GCC/build/gcc/ -I./../GCC/build/x86_64-unknown-linux-gnu/libgomp -Wno-write-strings -O3 -Wall -fopenmp -lpng -o mandelbrot-omp mandelbrot-omp.cpp​
Then I got the following error message:
xgcc: error: libgomp.spec: No such file or directory​
I've checked and found out that libgomp directory contains the libgomp.spec file. The directory is included with -I option. What's wrong?

how to use snprintf() in g++ -std=c++11 version 4.8.2

I am trying compile code that uses snprintf in version 4.8.2 of g++ with -std=c++11 without success.
Why doesn't g++ recognize snprintf? Can I overcome this while still using snprintf and c++11?
I got the following:
make all Building file: ../src/cppHWtest.cpp Invoking: Cygwin C++
Compiler g++ -std=c++11 -D"hash_map=unordered_map" -O0 -g3 -Wall -c
-fmessage-length=0 -MMD -MP -MF"src/cppHWtest.d" -MT"src/cppHWtest.d" -o "src/cppHWtest.o" "../src/cppHWtest.cpp" cygwin warning: MS-DOS style path detected: C:\Users\poudyal\workspace\cppHWtest\Debug
Preferred POSIX equivalent is:
/cygdrive/c/Users/poudyal/workspace/cppHWtest/Debug CYGWIN
environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames ../src/cppHWtest.cpp: In function 'int main()':
../src/cppHWtest.cpp:20:35: error: 'snprintf' was not declared in this
scope snprintf(buff, 10, "%s", "Hell O");
^ make: *** [src/cppHWtest.o] Error 1 src/subdir.mk:18: recipe for target 'src/cppHWtest.o' failed
**** Build Finished ****
Probably less intrusive solution than switching the mode to -std=gnu++11 is -U__STRICT_ANSI__. This will enable #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) at stdio.h:234 (GCC 4.8.3).

Resources