I'm a bit new to this so apologies if this doesn't make sense/ is a stupid question!!
我对此有点新意,如果这没有意义/这是一个愚蠢的问题,请道歉!
Anyway, I'm creating a project that has to uses OpenCV as well as UDP sockets. I'm currently writing the C++ part in Visual Studio (2013), so the project is visual C++. The plan is eventually to move the project from a PC on to an embedded computer running some linux distro.
无论如何,我正在创建一个必须使用OpenCV以及UDP套接字的项目。我目前正在Visual Studio(2013)中编写C ++部分,所以该项目是visual C ++。该计划最终将项目从PC转移到运行一些Linux发行版的嵌入式计算机上。
I'm wondering if there will be any majors issues later on that will cause me headaches if I develop the whole C++ code on Visual Studio and then try to port to a linux environment?
我想知道以后是否会出现任何专业问题,如果我在Visual Studio上开发整个C ++代码然后尝试移植到linux环境会让我头疼?
Also if that is the case would there be a way to avoid these future problems by just changing IDE or something else??
如果是这种情况,是否有办法通过更改IDE或其他东西来避免这些未来的问题?
4 个解决方案
#1
1
If you are using MFC for your GUI you can say goodbye to any possibility to port your code to Linux one day.
如果您使用MFC作为GUI,您可以告诉有朝一日将代码移植到Linux的任何可能性。
If you are using visual studio only as an IDE and use portable third party libraries (Qt, boost...) you should be able to port the code smoothly.
如果您仅将visual studio用作IDE并使用可移植的第三方库(Qt,boost ...),您应该能够顺利移植代码。
One good way to achieve this:
实现这一目标的一个好方法:
- Have all your file names in lower case
- Avoid using any win32 API (prefer boost library)
- As mentioned above, don't use \ in file paths, / almost always works on all platforms
- Write some Cmake scripts to generate your vcproj and sln files
- ... it is not exhaustive...
将所有文件名都小写
避免使用任何win32 API(更喜欢boost库)
如上所述,不要在文件路径中使用\,/几乎总是适用于所有平台
编写一些Cmake脚本来生成vcproj和sln文件
......它并非详尽无遗......
If this works on PC, you can then use Cmake to generate Linux Makefiles and it will hopefully compile and run under Linux.
如果这适用于PC,那么您可以使用Cmake生成Linux Makefile,它有望在Linux下编译和运行。
Ideally, have lots of unit tests to be ran, because porting may introduce multiple small bugs that you will have a hard time finding.
理想情况下,要运行大量的单元测试,因为移植可能会引入多个小错误,您很难找到它们。
#2
0
You can use a multiplatform compiler, like MINGW (http://www.mingw.org/) with eventually Codeblocks (http://www.codeblocks.org/) or Netbeans to prevent the compatibility issues. The written code should be highly compatible. But with the Visual-C++ compiler, it is probably more complicated to compile on Linux the program because this compiler is only on Windows.
您可以使用多平台编译器,如MINGW(http://www.mingw.org/),最终使用Codeblocks(http://www.codeblocks.org/)或Netbeans来防止兼容性问题。编写的代码应该高度兼容。但是使用Visual-C ++编译器,在Linux上编译程序可能会更复杂,因为这个编译器只在Windows上运行。
#3
0
I have recently moved a Visual C++ project to a Linux distro without major troubles. The biggest problem was properly that I had to change all \ to /. If you are in doubt you could always use a multiplatform compiler.
我最近将一个Visual C ++项目移动到一个Linux发行版,没有遇到什么麻烦。最大的问题是我必须将所有\更改为/。如果您有疑问,可以随时使用多平台编译器。
#4
0
It is possible to have a project that compiles using Visual Studio on Windows that also compiles on Linux. I have two such projects. They may be found at https://svn.sullivanandkey.com/SnKOpen/cpp/now/trunk/ and https://svn.sullivanandkey.com/SnKOpen/cpp/yekneb/trunk/.
可以在Windows上使用Visual Studio编译也可以在Linux上编译的项目。我有两个这样的项目。它们可以在https://svn.sullivanandkey.com/SnKOpen/cpp/now/trunk/和https://svn.sullivanandkey.com/SnKOpen/cpp/yekneb/trunk/找到。
Neither of these projects use a GUI, however it is possible if you use a cross platform GUI library such as wxWidgets, FLTK, or Qt.
这些项目都不使用GUI,但是如果您使用跨平台GUI库(例如wxWidgets,FLTK或Qt),则可以使用GUI。
My YekNeb project compiles on the following operating systems: FreeBSD, GNU/Linux, Microsoft Windows, Solaris, and ReactOS.
我的YekNeb项目编译在以下操作系统上:FreeBSD,GNU / Linux,Microsoft Windows,Solaris和ReactOS。
The key is to limit yourself to APIs that are available on all the platforms you wish to target. If you use any third party libraries such as OpenCV, make certain they are supported on every platform you wish to use.
关键是要将自己限制在您希望定位的所有平台上可用的API。如果您使用任何第三方库(如OpenCV),请确保在您希望使用的每个平台上都支持它们。
At times you need to use code that behaves differently depending on whether or not a given function is available on a given platform. I recommend against using the techniques I used in the two projects I mentioned above to do that. I will soon be transitioning to CMake and making use of the configure functionality found at CMake:How To Write Platform Checks.
有时,您需要使用行为不同的代码,具体取决于给定平台上是否有给定功能。我建议不要使用我在上面提到的两个项目中使用的技术来做到这一点。我将很快转换到CMake并利用CMake中的配置功能:如何编写平台检查。
I hope this helps.
我希望这有帮助。
#1
1
If you are using MFC for your GUI you can say goodbye to any possibility to port your code to Linux one day.
如果您使用MFC作为GUI,您可以告诉有朝一日将代码移植到Linux的任何可能性。
If you are using visual studio only as an IDE and use portable third party libraries (Qt, boost...) you should be able to port the code smoothly.
如果您仅将visual studio用作IDE并使用可移植的第三方库(Qt,boost ...),您应该能够顺利移植代码。
One good way to achieve this:
实现这一目标的一个好方法:
- Have all your file names in lower case
- Avoid using any win32 API (prefer boost library)
- As mentioned above, don't use \ in file paths, / almost always works on all platforms
- Write some Cmake scripts to generate your vcproj and sln files
- ... it is not exhaustive...
将所有文件名都小写
避免使用任何win32 API(更喜欢boost库)
如上所述,不要在文件路径中使用\,/几乎总是适用于所有平台
编写一些Cmake脚本来生成vcproj和sln文件
......它并非详尽无遗......
If this works on PC, you can then use Cmake to generate Linux Makefiles and it will hopefully compile and run under Linux.
如果这适用于PC,那么您可以使用Cmake生成Linux Makefile,它有望在Linux下编译和运行。
Ideally, have lots of unit tests to be ran, because porting may introduce multiple small bugs that you will have a hard time finding.
理想情况下,要运行大量的单元测试,因为移植可能会引入多个小错误,您很难找到它们。
#2
0
You can use a multiplatform compiler, like MINGW (http://www.mingw.org/) with eventually Codeblocks (http://www.codeblocks.org/) or Netbeans to prevent the compatibility issues. The written code should be highly compatible. But with the Visual-C++ compiler, it is probably more complicated to compile on Linux the program because this compiler is only on Windows.
您可以使用多平台编译器,如MINGW(http://www.mingw.org/),最终使用Codeblocks(http://www.codeblocks.org/)或Netbeans来防止兼容性问题。编写的代码应该高度兼容。但是使用Visual-C ++编译器,在Linux上编译程序可能会更复杂,因为这个编译器只在Windows上运行。
#3
0
I have recently moved a Visual C++ project to a Linux distro without major troubles. The biggest problem was properly that I had to change all \ to /. If you are in doubt you could always use a multiplatform compiler.
我最近将一个Visual C ++项目移动到一个Linux发行版,没有遇到什么麻烦。最大的问题是我必须将所有\更改为/。如果您有疑问,可以随时使用多平台编译器。
#4
0
It is possible to have a project that compiles using Visual Studio on Windows that also compiles on Linux. I have two such projects. They may be found at https://svn.sullivanandkey.com/SnKOpen/cpp/now/trunk/ and https://svn.sullivanandkey.com/SnKOpen/cpp/yekneb/trunk/.
可以在Windows上使用Visual Studio编译也可以在Linux上编译的项目。我有两个这样的项目。它们可以在https://svn.sullivanandkey.com/SnKOpen/cpp/now/trunk/和https://svn.sullivanandkey.com/SnKOpen/cpp/yekneb/trunk/找到。
Neither of these projects use a GUI, however it is possible if you use a cross platform GUI library such as wxWidgets, FLTK, or Qt.
这些项目都不使用GUI,但是如果您使用跨平台GUI库(例如wxWidgets,FLTK或Qt),则可以使用GUI。
My YekNeb project compiles on the following operating systems: FreeBSD, GNU/Linux, Microsoft Windows, Solaris, and ReactOS.
我的YekNeb项目编译在以下操作系统上:FreeBSD,GNU / Linux,Microsoft Windows,Solaris和ReactOS。
The key is to limit yourself to APIs that are available on all the platforms you wish to target. If you use any third party libraries such as OpenCV, make certain they are supported on every platform you wish to use.
关键是要将自己限制在您希望定位的所有平台上可用的API。如果您使用任何第三方库(如OpenCV),请确保在您希望使用的每个平台上都支持它们。
At times you need to use code that behaves differently depending on whether or not a given function is available on a given platform. I recommend against using the techniques I used in the two projects I mentioned above to do that. I will soon be transitioning to CMake and making use of the configure functionality found at CMake:How To Write Platform Checks.
有时,您需要使用行为不同的代码,具体取决于给定平台上是否有给定功能。我建议不要使用我在上面提到的两个项目中使用的技术来做到这一点。我将很快转换到CMake并利用CMake中的配置功能:如何编写平台检查。
I hope this helps.
我希望这有帮助。