Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::snprintf not found with GCC 4.8, 4.6 #16

Closed
mboisson opened this issue May 7, 2014 · 17 comments
Closed

std::snprintf not found with GCC 4.8, 4.6 #16

mboisson opened this issue May 7, 2014 · 17 comments

Comments

@mboisson
Copy link

mboisson commented May 7, 2014

Hi,
For some reason, GCC 4.8 and 4.6 tell me that snprintf is not part of std. I tried virtually every -std options, and nothing works. However, replacing std::snprintf by just snprintf in arma_boost.hpp solved the problem as it falls back on snprintf from C99.

While I consider this to be a compiler bug, would it be possible to just change it in your code to use snprintf instead of std::snprintf ?

@kevinushey
Copy link
Contributor

Thanks. In fact, snprintf being in std is a C++11 feature (http://en.cppreference.com/w/cpp/io/c/fprintf).

I imagine RcppArmadillo must also assume C++98 support, and since that also precludes C99 features, I am not sure what the best way to handle this is. But I guess not specifying std won't hurt anyone, since the 'main' compilers will silently borrow C99 features as needed...

Thoughts, @eddelbuettel?

@eddelbuettel
Copy link
Member

For changes to Armadillo, you need to talk Armadillo's author -- which is Conrad.

@eddelbuettel
Copy link
Member

Ok, on second look the file in question, ie arma_boost.hpp, has this carefully #ifdef'ed (as is common with Conrad's code).

But it turns out that we do define #define ARMA_HAVE_STD_SNPRINTF -- and that line is from Aug 2010 and has not bitten anybody yet. Oh, and I even overlooked that we then undefine it in some cases:

/* TODO: we might need to undef this on other platforms as well */
#if defined(__GNUC__) && defined(_WIN64) || defined(__FreeBSD__)
#undef ARMA_HAVE_STD_SNPRINTF                                                                                                                                                                                                               
#endif

Could you be a bit more specific in how this hurt you? I guess your code used snprintf and the compiler choked?

We could of course flip the definition, but I'd have to do a wee bit more research about this.

@mboisson
Copy link
Author

mboisson commented May 7, 2014

Here is what I get :
/software6/compilers/gcc/4.8/bin/g++ -I/software6/bioinfo/apps/mugqic_space//software/R_3.0.2_gcc4.8/R-3.0.2/lib64/R/include -DNDEBUG -I/usr/local/include -I"/software6/bioinfo/apps/mugqic_space/software/R_3.0.2_gcc4.8/R-3.0.2/lib64/R/library/Rcpp/include" -I../inst/include -fpic -g -O2 -c RcppArmadillo.cpp -o RcppArmadillo.o
In file included from ../inst/include/armadillo:97:0,
from ../inst/include/RcppArmadilloForward.h:37,
from ../inst/include/RcppArmadillo.h:30,
from RcppArmadillo.cpp:22:
../inst/include/armadillo_bits/arma_boost.hpp: In function ‘std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::format, T2>&)’:
../inst/include/armadillo_bits/arma_boost.hpp:18:27: erreur: ‘snprintf’ is not a member of ‘std’
#define arma_snprintf std::snprintf

I tried manual compilation after installing through R failed with that error, to try and follow what is going on.

@kevinushey
Copy link
Contributor

You should be able to avoid this locally by enforcing -std=c++11 or -std=c++0x.

@mboisson
Copy link
Author

mboisson commented May 7, 2014

I did try with std=c++11, std=c++0x, std=gnu++0x, none of them changed the result. As I said, I do recognize that this might be a compiler or libstdc++ bug, but it's probably easier to go around it than to get this fixed in a timely manner.

@eddelbuettel
Copy link
Member

I would edit RcppArmadilloConfig.h for now.

Note that the problem has not bitten anybody else in years it seems, so is there any chance it could be local to you setup?

@kevinushey
Copy link
Contributor

I don't see -std=c++11 in any of the compilation examples you showed either -- are you sure that you are setting it correctly? E.g., in a file ~/.R/Makevars with PKG_CXXFLAGS=-g -O3 -Wall -std=c++11?

@eddelbuettel
Copy link
Member

Moreover, showing an assert is a real big NO for CRAN, and we would know. You are running R from a seemingly large and complex lab installation and I fear that you may have a #define somewhere that alters the flow of includes etc pp -- because nobody else sees this. Yet Rcpp et al are fairly widely tested.

@mboisson
Copy link
Author

mboisson commented May 7, 2014

Here is the example with -std=c++11. I put CXXFLAGS in ~/.R/Makevars, and not PKG_CXXFLAGS, but it was used.

[mboisson@colosse3 src]$ /software6/compilers/gcc/4.8/bin/g++ -I/software6/bioinfo/apps/mugqic_space//software/R_3.0.2_gcc4.8/R-3.0.2/lib64/R/include -DNDEBUG -I/usr/local/include -I"/software6/bioinfo/apps/mugqic_space/software/R_3.0.2_gcc4.8/R-3.0.2/lib64/R/library/Rcpp/include" -I../inst/include -fpic -g -O2 -c RcppArmadillo.cpp -o RcppArmadillo.o -std=c++11
In file included from ../inst/include/armadillo:97:0,
from ../inst/include/RcppArmadilloForward.h:37,
from ../inst/include/RcppArmadillo.h:30,
from RcppArmadillo.cpp:22:
../inst/include/armadillo_bits/arma_boost.hpp: In function ‘std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::format, T2>&)’:
../inst/include/armadillo_bits/arma_boost.hpp:18:27: erreur: ‘snprintf’ is not a member of ‘std’
#define arma_snprintf std::snprintf

It is possible that it's something with our installation, as we compile everything from source (including GCC). However, I am now at over a hundred of packages that all compiled fine with our GCC 4.8 installation.

Have you tried compiling R and Rcpparmadillo with GCC 4.8 ?

@mboisson
Copy link
Author

mboisson commented May 7, 2014

Here is what I get with a sample code to just test std::snprintf with GCC 4.8 :

#include
int main()
{
char * test = new char[10];
std::snprintf(test, 10, "%f", 2.);
return 0;
}

g++ test.cpp -std=c++11
test.cpp: In function ‘int main()’:
test.cpp:5:2: erreur: ‘snprintf’ is not a member of ‘std’
std::snprintf(test, 10, "%f", 2.);
^
test.cpp:5:2: note: suggested alternative:
In file included from /software6/compilers/gcc/4.8.2/include/c++/4.8.2/cstdio:42:0,
from test.cpp:1:
/usr/include/stdio.h:385:12: note: ‘snprintf’
extern int snprintf (char *__restrict __s, size_t __maxlen,
^

@mboisson
Copy link
Author

mboisson commented May 7, 2014

That #include was of cstdio

@mboisson
Copy link
Author

mboisson commented May 7, 2014

By the way, I opened a bug report on GCC bug tracker, for libstdc++ : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61101

@eddelbuettel
Copy link
Member

Yes, gcc 4.8 is my default on Ubuntu, and has been used a gazillion times.

@mboisson
Copy link
Author

mboisson commented May 7, 2014

Hum, I don't know then, maybe it has to do with the glibc from CentOS 6... My question remains though, why force std::snprintf rather than just letting the compiler find whatever it can ? Does std::snprintf have different behavior than snprintf ?

@eddelbuettel
Copy link
Member

I see no issue here so I am inclined to close this.

edd@max:/tmp$ cat mboisson.cpp 
#include <cstdio>
#include <iostream>

int main() {
  char * test = new char[10];
  std::snprintf(test, 10, "%f", 2.);
  std::cout << test << std::endl;
  return 0;
}
edd@max:/tmp$ g++ -Wall -o mboisson mboisson.cpp 
edd@max:/tmp$ ./mboisson
2.000000
edd@max:/tmp$ 

@eddelbuettel
Copy link
Member

I am closing this as a local / non-reproducible issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants