在Linux中编译visual C ++代码? [英] compiling visual C++ code in linux?

查看:193
本文介绍了在Linux中编译visual C ++代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行图像匹配的visual C ++程序。我正在使用openCV。我正在寻找在Linux服务器上运行该exe文件。但我不知道如何在Linux中编译visual C ++代码?



任何人都可以在这方面帮助我。 。 。如果你在MSVC中编写C ++代码的时候巧妙地做了事情,你隔离了所有与平台相关的代码(即Microsoft C ++的扩展和仅限于Windows的库的使用)从一开始就从其余部分开始,并确切知道修改的位置,以便在Linux上运行。



不幸的是,你的问题暗示这是你第一次尝试跨平台编码,在这种情况下,你可能会在你的代码中散布微软主义,并且必须逐个挑选它们。启动编译器,查看其错误消息,然后从那里开始。祝你好运,这将是一个痛苦,但也是你的下一个项目非常宝贵的一课。



(这里我没有指向MSVC。对于那些用GNU-isms代码并希望在MSVC上编译它们的人来说,这是真的)。​​

通常的构造如下所示:

  #if defined(_MSC_VER)
// Microsoft版本
#elif defined(__GNUC__)
/ / GCC版本
#else
#error不支持平台/编译器。
#endif

编辑: ,这个想法是将ifdef'ed代码保持在绝对最小值。使用typedef,转发函数(即log()使用Unix或Windows日志记录),或者 - 如果其他所有情况都失败 - 使用宏。 不要在代码中使用上面的代码,将它隔离在少数头文件/实现文件中,并保存在单独的源文件夹中。

你也会想要熟悉Makefiles(无耻插件: Makefile教程),因为MSVC项目文件在Linux上不工作(显然)。另一方面,Makefiles在Windows上也可以非常漂亮地工作(例如,通过 Cygwin ,如果你想深入研究到如何在命令行上调用MSVC编译器,大致如下:

  ifeq($(OSTYPE),linux) 
CC:= gcc
else
CC:= cl.exe
endif


i have a visual C++ program which performs image matching. I am using openCV. I am looking to run the exe on a linux server. But i dont know how to compile visual C++ code in linux?

Can anyone plz help me in this regard . . .

解决方案

If you did things smartly while writing the C++ code in MSVC, you isolated all platform-dependent code (i.e., Microsoft extensions to C++ and uses of Windows-only libraries) from the rest right from the start, and know exactly where to do the modifications to make it run on Linux as well.

Unfortunately, your question hints at this being your first attempt at cross-platform coding, and in that case, you probably littered Microsoft-isms all over your code, and have to pick through them one by one. Start the compiler, have a look at its error messages, and go from there. Good luck, it will be a pain, but also a very valuable lesson for your next project.

(I'm not finger-pointing at MSVC here. The very same is true for people who litter their code with GNU-isms and then want to have it compile on MSVC...)

The usual construct looks like this:

#if defined( _MSC_VER )
// Microsoft version
#elif defined( __GNUC__ )
// GCC version
#else
#error Platform / compiler not supported.
#endif

Edit: In case it is not obvious, the idea is to keep the ifdef'ed code above at an absolute minimum. Use typedef's, forwarding functions (i.e., log() to use either Unix or Windows logging), or - if all else fails - macros. Don't use the above all over the code, isolate it in a few header / implementation files, kept in a separate source folder.

You will also want to familiarize yourself with Makefiles (shameless plug: Makefile tutorial), because MSVC project files don't work on Linux (obviously). Makefiles, on the other hand, can work quite beautifully on Windows as well (e.g. through Cygwin, if you care to delve into how to call the MSVC compiler on the command line, roughly along these lines:

ifeq ($(OSTYPE),linux)
    CC := gcc
else
    CC := cl.exe
endif

这篇关于在Linux中编译visual C ++代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆