cross compile c++ on linux to windows - c++

clang++ main.cpp -std=c++11 -target x86_64-unknown-win32 -I/usr/lib/gcc/x86_64-w64-mingw32/4.6/include/
main.cpp:6:10: fatal error: 'string' file not found
#include <string>
^
1 error generated.
that's weird because:
/usr/lib/gcc/x86_64-w64-mingw32/4.6/include/ssp$ ls
ssp.h stdio.h string.h unistd.h
and this result the same:
clang++ main.cpp -std=c++11 -target x86_64-unknown-win32 -I/usr/lib/gcc/x86_64-w64-mingw32/4.6/include/ssp
well. I used to compile c code from linux to windows just fine using:
x86_64-w64-mingw32-gcc main.c
and I tried:
x86_64-w64-mingw32-g++ -std=c++0x main.cpp
also:
x86_64-w64-mingw32-g++ -std=c++0x main.cpp -I/usr/lib/gcc/x86_64-w64-mingw32/4.6/include
still give bunch of errors like
main.cpp:70:23: sorry, unimplemented: non-static data member initializers
main.cpp:70:23: error: in-class initialization of static data member ‘origin’ of non-literal type
main.cpp: In constructor ‘Item::Item(std::string)’:
main.cpp:83:18: error: ‘stoul’ is not a member of ‘std’
main.cpp:88:4: error: ‘origin’ was not declared in this scope
main.cpp:89:17: error: ‘stof’ is not a member of ‘std’
main.cpp: In function ‘std::ostream& operator<<(std::ostream&, const Item&)’:
....
x86_64-w64-mingw32-g++ (GCC) 4.6.3 seems to be the latest version on ubuntu repo.
I'm at lost..why the hell clang won't use the headers. why the hell x86_64-w64-mingw32-g++ won't listen that it should use c++11 standards.

The GCC version you use does not support non-static data member initializers as shown here. Find out here which version of GCC supports the C++11 feature set you required.

Related

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

In C++, I am trying to declare an unordered_set simply like this:
std::unordered_set<int> k;
But it is showing this error:
error: 'unordered_set' is not a member of 'std'
I am using g++ (GCC) 5.3.0 on windows using MinGW. Here are the things that I have already considered:
Adding the header file by #include <unordered_set>
Upgrading MinGW
Using the flag -std=gnu++11. (This is not generating any executable or error, not sure if it doing anything or not)
How to fix it and compile my code successfully?
Use -std=c++11 switch and specify output file.
g++ -std=c++11 your_file.cpp -o your_program

clang++ only compiles C++11 program using boost::format when -std=c++11 option is dropped

Please take a look at the following C++11 snippet:
#include <boost/format.hpp>
int main(int argc, char** argv)
{
auto s = boost::format("");
return 0;
}
When I compile it with clang using the -std=c++11 I get the following error:
$ clang++ -std=c++11 -o main main.cpp
In file included from main.cpp:1:
In file included from /usr/include/boost/format.hpp:19:
In file included from /usr/include/boost/detail/workaround.hpp:41:
In file included from /usr/include/boost/config.hpp:40:
In file included from /usr/include/boost/config/select_stdlib_config.hpp:18:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/cstddef:51:11: error:
no member named 'max_align_t' in the global namespace
using ::max_align_t;
~~^
1 error generated.
Without the -std=c++11 everything compiles fine, but clang prints a warning:
$ clang++ -o main main.cpp
main.cpp:5:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto s = boost::format("");
^
So, it looks like a valid workaround is to drop the C++11 flag, as the current version of clang seem to be in C++11 mode, anyway? The drawback is that you will get many warnings.
Is there a better workaround beside completely switching to gcc? Patching the source code of boost::format or gcc-libs is fine for me.
System information:
Platform: Arch Linux x86_64
Boost version: 1.55.0-6
gcc-libs: 4.9.0-1
clang++: 3.4 (tags/RELEASE_34/final)
The bug is closed now. It should be fixed in Arch with clang 3.4-2.
With this commit, Evangelos Foutras merged the following patch from upstream:
http://reviews.llvm.org/rL201729

G++ & Clang++ - namespace std _GLIBCXX_VISIBILITY(default)

I am trying to compile my C++ code using clang++ but keep getting this error with the conflicting namespace. My main.cpp file is a simple Hello World program (for debugging).
I have a feeling the issue is with my version of GCC or clang that I compiled on my cluster. Any ideas as to how to trace this issue down? Or steps to troubleshoot?
[aebrenne#hpc src]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/apps/gcc/4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --with-gmp=/data/apps/gmp/5.1.2 --with-mpfr=/data/apps/mpfr/3.1.2 --with-mpc=/data/apps/mpc-1.0.1 --enable-threads=posix --with-as=/data/apps/binutils/2.23.2/bin/as --mandir=/data/apps/gcc/4.8.1/man --pdfdir=/data/apps/gcc/4.8.1/pdf --htmldir=/data/apps/gcc/4.8.1/html --enable-languages=c,c++,fortran,ada,go,java,lto,objc,obj-c++ --prefix=/data/apps/gcc/4.8.1
Thread model: posix
gcc version 4.8.1 (GCC)
[aebrenne#hpc src]$ clang++ --version
clang version 3.4 (trunk 193367)
Target: x86_64-unknown-linux-gnu
Thread model: posix
[aebrenne#hpc src]$
[aebrenne#hpc src]$ cat main.cpp
#include <iostream>
int main() {
std::cout << "Starting test..." << std::endl;
return 0;
}
[aebrenne#hpc src]$ clang++ -std=c++11 -Wall -g -I/data/apps/gcc/4.8.1/include/c++/4.8.1 main.cpp
In file included from main.cpp:1:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/iostream:39:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/ostream:38:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/ios:38:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/iosfwd:39:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/bits/stringfwd.h:40:
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:15: error: expected '{'
namespace std _GLIBCXX_VISIBILITY(default)
^
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:15: error: C++ requires a type specifier for all declarations
namespace std _GLIBCXX_VISIBILITY(default)
^~~~~~~~~~~~~~~~~~~
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:35: error: expected expression
namespace std _GLIBCXX_VISIBILITY(default)
^
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:43: error: expected ';' after top level declarator
namespace std _GLIBCXX_VISIBILITY(default)
^
As this is the first result for searches along the lines of:
error: expected unqualified-id before 'namespace'
namespace std _GLIBCXX_VISIBILITY(default)
I'll confess that I got this error by missing a closing-brace in a header file included before the one mentioned in the backtrace.
Hopefully this helps someone.
I had the same issue.
The problem was that I had only the following as CPATH:
<gcc-install-path>/include/c++/<gcc-version>
After greping for _GLIBCXX_VISIBILITY in the same directory, it seems that the macro is defined in a sub-directory, specific for the host machine. In my case, this is x86_64-unknown-linux-gnu. Adding that to CPATH solved the problem. My new CPATH is:
<gcc-install-path>/include/c++/<gcc-version>:<gcc-install-path>/include/c++/<gcc-version>/<machine-specific-headers>
For my example machine this translates to:
export CPATH=~/f/i/gcc-4.8.4/include/c++/4.8.4:~/f/i/gcc-4.8.4/include/c++/4.8.4/x86_64-unknown-linux-gnu
I hope that helps someone.
I am using clang++ 4.2 and it worked for me, strange
clang++ -std=c++11 -Wall -g main.cpp
What if you just get rid of the -I/data/apps/gcc/4.8.1/include/c++/4.8.1
Doesn't it work by default?
for GCC define subject of attribute for function, namespaces passed arguments types, call protocol and so no. Macros _GLIBCXX_VISIBILITY(default) is redefinition of attribute( visibility_(default)) In Windows is not defined... in Linux is on! As to another OC I don't know. You must redefine this macros as empty and set them before all includes. So on error occurs. But it's strange... If you setup STL platform oriented the appropriate redefinition must be!!! You need it to manually. As to me I like attributes. They allow control some aspects not available any compiler and grantee correct behavior. For example control arguments type and number of vars passed in function printf according to format.And if you passed different type or not enough number args error occurs as a compile error!!! Nothing else gives such an opportunity!!! Use attributes on Linux. It's good an idea...
I hit the same issue.
I mix up gcc 4.8 headers and system headers(lower version,gcc 4.4.6, _GLIBCXX_VISIBILITY not defined).
use:
clang++ -std=c++11 -Wall -g -I/data/apps/gcc/4.8.1/include/c++/4.8.1 main.cpp -v -H
to see all the "include" details.
In my case:
. /include/c++/4.8.2/iostream
.. /usr/lib64/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux/bits/c++config.h
... /include/bits/wordsize.h
... /usr/lib64/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux/bits/os_defines.h
.... /include/features.h
..... /include/stdc-predef.h
..... /include/sys/cdefs.h
...... /include/bits/wordsize.h
..... /include/gnu/stubs.h
...... /include/gnu/stubs-64.h
... /usr/lib64/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux/bits/cpu_defines.h
.. /include/c++/4.8.2/ostream
... /include/c++/4.8.2/ios
.... /include/c++/4.8.2/iosfwd
..... /include/c++/4.8.2/bits/stringfwd.h
...... /include/c++/4.8.2/bits/memoryfwd.h
In file included from test.cpp:1:
In file included from /include/c++/4.8.2/iostream:39:
In file included from /include/c++/4.8.2/ostream:38:
In file included from /include/c++/4.8.2/ios:38:
In file included from /include/c++/4.8.2/iosfwd:39:
In file included from /include/c++/4.8.2/bits/stringfwd.h:40:
/include/c++/4.8.2/bits/memoryfwd.h:50:15: error: expected '{'
namespace std _GLIBCXX_VISIBILITY(default)
Fixed with this:
clang++ -std=c++11 -isystem /include/c++/4.8.2/ -isystem /include/c++/4.8.2/x86_64-baidu-linux-gnu/ test.cpp -v -H
For that _GLIBCXX_VISIBILITY is defined in /include/c++/4.8.2/x86_64-baidu-linux-gnu/bits/c++_config.h

Where is definition of std::function in clang++ (3.3/Xcode)

Problem Solved => see the update at the end
I'm trying to use std::function but it looks like just include <functional> does not provide the definition. I have tried to compile following code:
#include <functional>
std::function<int(int)> f = nullptr;
with c++11 as compile option:
% clang++ -c -std=c++11 t.cc
cause:
t.cc:3:6: error: no type named 'function' in namespace 'std'
std::function<int(int)> f = nullptr;
~~~~~^
t.cc:3:14: error: expected unqualified-id
std::function<int(int)> f = nullptr;
^
2 errors generated.
what am I missing? I know C++ well but new to clang++/C++11 thus I lack of important knowledge, I guess.
I'm using clang++ on MacOS X 10.8.
Update 1
I have tried a sample at cppreference.com site but it won't compile too. Giving some option solve the problem?
Update 2
Tried above sample from cppreference.com with clang++ -c -std=c++11 -stdlib=libc++11 x.cc, and compiler still says:
x.cc:1:10: fatal error: 'functional' file not found
#include <functional>
^
1 error generated.
Where is functional? I guess I should give -stdlib=libc++11 or whatever but it does not work too:
clang: error: invalid library name in argument '-stdlib=libc++11'
How I can find list of argument for -stdlib? (note: in man page, only available options are libc++ and libstdc++ both of them don't work)
Or functional just does not work?
This is not about the definition of the function. You don't have a linker error. You have a compiler error. The problem is, presumably, that the BSD/GNU/Darwin standard library installed in the real sysroot doesn't support C++11. You have to use the one that comes with Clang by specifying the -stdlib=libc++ compiler flag.
For C++11, it's best to always invoke clang as: clang++ -std=c++11 -stdlib=libc++
I use this most of the time, so I set the environment variable $CXX to this value. That way, I'm getting the dialect and library option in both compilation and linking. -std=c++11 is insufficient, as clang will still use the (old) system gcc headers in /usr/include/c++/4.2.1.
-stdlib=libc++ will use the clang headers in /usr/lib/c++/v1 such as <functional>.
There's a similar question with an answer by Howard Hinnant, who is (IIRC) an Apple engineer.

Activate Smart Pointers?

I wanted to play around with the new features of C++11, namely with Smart Pointers. I found an exampleg++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 here: Cplusplus11-Smart-Pointers:
#include <memory>
int main() {
std::shared_ptr<int> sptr1( new int );
}
When I try it out is everything I get:
In function ‘int main()’:|
error: ‘shared_ptr’ was not declared in this scope|
error: expected primary-expression before ‘int’|
error: expected ‘;’ before ‘int’|
This is my g++ Version:
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Do I have to "activate" C++11 at first?
You need to pass the -std=c++11 compiler flag to the g++ compiler. CodeBlocks allows you to configure this via
Settings -> Compiler -> Compiler Settings
Note for older versions of gcc, you may need -std=c++0x.