2013-07-15 192 views
0

一个名为“.o”文件我在Visual Studio 2012写了一个程序类,我想在Linux机器上运行它。我试过在Linux机器上编译,但我相信我使用的一些库不是跨平台兼容的。无论如何,我可以创建一个在Linux上运行的.o文件,这不需要我更改我的代码?创建从的Visual Studio 2012项目

语言:C++ 下面是我使用的库:

#include <iostream> 
#include <queue> 
#include <map> 
#include <climits> 
#include <iterator> 
#include <algorithm> 
#include <fstream> 
#include <string> 
#include <iomanip> 

什么,当我试图在Linux中

Main.cpp: In function ‘int main()’: 
Main.cpp:110:24: error: no matching function for call to    'std::basic_ifstream<char>::basic_ifstream(std::string&)’ 
Main.cpp:110:24: note: candidates are: 
/usr/include/c++/4.6/fstream:460:7: note: std::basic_ifstream<_CharT,  _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char, _Traits  = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode] 
/usr/include/c++/4.6/fstream:460:7: note: no known conversion for argument 1 from  ‘std::string {aka std::basic_string<char>}’ to ‘const char*’ 
/usr/include/c++/4.6/fstream:446:7: note: std::basic_ifstream<_CharT,  _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>] 
/usr/include/c++/4.6/fstream:446:7: note: candidate expects 0 arguments, 1 provided 
/usr/include/c++/4.6/fstream:420:11: note:  std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&) 
/usr/include/c++/4.6/fstream:420:11: note: no known conversion for argument 1 from  ‘std::string {aka std::basic_string<char>}’ to ‘const std::basic_ifstream<char>&’ 
+0

当你在linux上编译它会发生什么? – doctorlove

+2

在linux上构建它。 –

+0

这看起来像是C++ 11的一个扩展(以'string'作为参数打开一个文件)。尝试使用'-std = C++ 11' [或'-std = C++ 0x',如果你有一个旧版本的gcc]。 –

回答

1

编译在所有诚实发生,你会过得更好建设它一些跨平台友好的东西,尤其是看到它是C++,没有理由依赖于Visual Studio。尝试寻找类似code :: blocks的东西来构建它以在Linux上运行。

1

我想,即使你找到了办法,不会去上班。你需要在Linux计算机分别生成的.o

2

您列出似乎是具体到Visual Studio或Windows,所以假设你已经安装了正确的C++标准库中的Linux机器上的头文件都没有,它应该只是编译。

如果你真的想交叉编译,那么你必须将源代码gcc,以及C++标准库头文件和二进制文件下载到你的Windows机器上。然后构建交叉编译的编译器(这可能意味着安装“windows兼容版本的gcc”,如Cygnus cygwin或gcc MingW)。实现这一点并不是一帆风顺的。相信我,你不想这样做,除非你真的必须这样做。

一个更好的解决方案,如果你不想在Linux机器上编译出于某种原因,那就是让你的Windows机器上安装一个虚拟机,然后在那上面安装Linux,然后使用这个Linux VM作为你的编译系统。

编辑:

为了澄清,基于在问题的编辑:这个问题似乎是C++ 11功能的使用,这大概是在Visual Studio中,默认其中GCC /克++将采取更保留的方法。解决方案是告诉编译器在命令行上使用C++ 11标准-std=c++11来编译。这应该允许使用字符串中的名称打开文件的扩展名以正常工作。

相关问题