C ++ 11:编译和执行:跨平台编译

时间:2015-12-20 01:09:38

标签: c++ c++11 compilation cross-platform

我有一个简短的C ++代码,我已在远程服务器A上成功编译。我希望在另一个目标远程服务器T上运行可执行文件。

代码main.cpp包含以下代码段(需要C ++ 11支持):

#include <random>
default_random_engine GENERATOR;
void get_random_indices(set<int> &output, int max_ind) {
    uniform_int_distribution<int> dist(0, max_ind);

    while (output.size() < SAMPLE_SIZE) {
        output.insert(dist(GENERATOR));
    }
}

我使用以下行编译代码:

g++ -o exec_foo -std=c++11 main.cpp

服务器A的规范是

[me@A ~]$ uname -a
Linux some-ip:D 2.6.32-573.1.1.el6.x86_64 #1 SMP Tue Jul 14 02:46:51 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux

[me@A ~]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/nfs/nfs5-insecure/home/insecure-ro/software/rhel6_x86_64/gcc-5.1.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/l/gcc-5.1.0
Thread model: posix
gcc version 5.1.0 (GCC)

当我在服务器exec_foo中运行A时,它运行正常。现在,在目标服务器T上运行相同的可执行文件会导致以下错误:

./exec_foo: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by ./exec_foo)
./exec_foo: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by ./exec_foo)
./exec_foo: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./exec_foo)

检查目标服务器T上的规范,我看到以下内容:

-bash-4.1$ uname -a
Linux marry-christmas 2.6.32-358.6.2.el6.marry-christmas.20130516.x86_64 #1 SMP Fri May 17 04:49:39 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

-bash-4.1$ g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 

好的,我明白了。服务器T找不到库的某些链接。但是我无法在T上本地编译代码:

-bash-4.1$ g++ -o exec_foo --std=c++11 main.cpp 
cc1plus: error: unrecognized command line option "-std=c++11"

c++11。我们试试c++0x

-bash-4.1$ g++ -o exec_foo --std=c++0x main.cpp 
main.cpp:64: error: ‘default_random_engine’ does not name a type
main.cpp: In function ‘void get_random_indices(std::set<int, std::less<int>, std::allocator<int> >&, int)’:
main.cpp:66: error: ‘uniform_int_distribution’ was not declared in this scope
main.cpp:66: error: expected primary-expression before ‘int’
main.cpp:66: error: expected ‘;’ before ‘int’
main.cpp:69: error: ‘GENERATOR’ was not declared in this scope
main.cpp:69: error: ‘dist’ was not declared in this scope

除了更新我无权做的服务器g++上的血腥gcc + T之外,还有出路吗?

许多人提前感谢,并嫁给圣诞节。

0 个答案:

没有答案