简体   繁体   English

跨平台开发?

[英]Cross-platform development?

I am looking for a solution which would allow me to code for Linux and Windows using C++. 我正在寻找一种解决方案,该解决方案允许我使用C ++为Linux和Windows进行编码。

On Windows I use Visual Studio (I tried other stuff on Windows but I work with DirectX and as far as I know, it's the best solution). 在Windows上,我使用Visual Studio(我在Windows上尝试了其他方法,但我使用DirectX ,据我所知,这是最佳解决方案)。

On Linux I use NetBeans (which I like very much). 在Linux上,我使用NetBeans (我非常喜欢)。

My problem is that I want the project be independent of Visual Studio and NetBeans. 我的问题是我希望项目独立于Visual Studio和NetBeans。

For a while I thought that CMake was the solution, however the learning process is too important, I rather spend my time coding than learning all the tricks with CMake. 有一段时间我以为CMake是解决方案,但是学习过程太重要了,我宁愿花时间在编码上,也不愿学习CMake的所有技巧。 So I settled for Boost.Jam . 所以我选择了Boost.Jam It worked fine on Linux but sucked with Visual Studio. 它在Linux上运行良好,但在Visual Studio上很烂。

I created a small Hello World program, on Windows. 我在Windows上创建了一个小的Hello World程序。 I created a Visual Studio Makefile project and while it's compiling and linking correctly. 我创建了一个Visual Studio Makefile项目,并且该项目正在正确编译和链接。 I can run the executable but not from Visual Studio, which can't find the executable (no matter what I do). 我可以运行可执行文件,但不能从Visual Studio运行,后者找不到可执行文件(无论我做什么)。 I can't debug either. 我也不能调试。 Also I can't see the compilation error message when I get one. 另外,我也看不到编译错误消息。 All I can see from Visual Studio is that there is a makefile action in progress and that there is a mistake about it (even though the program is created and run fine). 从Visual Studio中可以看到的是,有一个makefile操作正在进行中,并且有一个错误(即使程序已创建并运行良好)。

I've been browsing the Boost.Jam documentation for a while but let's face it, it's pretty poor (no wonder not a lot of people heard of it) or I'm pretty not suited for the job (meaning stupid lol but yet why so few heard of it). 我浏览了Boost.Jam文档已有一段时间了,但让我们面对现实吧,它相当糟糕(难怪没有很多人听说过),或者我不太适合这份工作(意思是愚蠢的笑声,但是为什么?很少有人听说过)。

I have three questions: 我有三个问题:

I'd like to know if somebody heard of a project which use Boost.Jam with visual studio? 我想知道是否有人听说过在Visual Studio中使用Boost.Jam的项目吗? If yes can I have a look at it ? 如果可以,我可以看看吗?

Is there a tool out there with real Visual Studio integration? 有没有与Visual Studio真正集成的工具?

How many people think that learning to use CMake (correctly) cost a lot of time? 有多少人认为学习(正确)使用CMake会花费很多时间? Any tricks to speed up? 有什么技巧可以加快速度吗?

You should take the time to learn CMake and to speed up the learning process buy/read "Mastering CMake 4th Edition" 您应该花时间学习CMake并加快学习过程,购买/阅读“精通CMake 4th Edition”

If you have problems you should use the CMake mailing list , which is active (August 2009 had ~600 messages) 如果遇到问题,则应使用CMake 邮件列表 ,该列表处于活动状态(2009年8月有600条消息)

Qt and Qt Creator look like a good solution to your problem. Qt和Qt Creator看起来像是解决问题的好方法。 qmake can generate vcproj files and native Linux makefiles. qmake可以生成vcproj文件和本机Linux makefile。

如果要用Windows和Linux的C ++编写代码,则要用linux编写代码,并将应用程序与最小的cygwin设置捆绑在一起。

Are you sure you're looking at the right documentation? 您确定要查看正确的文档吗? You have said "Boost.Jam", so chances are high you are looking at wrong thing. 您说过“ Boost.Jam”,所以您看错事情的机会很高。 Please visit Boost.Build documentation 请访问Boost.Build文档

I am positively sure that many people used Boost.Build inside Visual Studio without problems. 我可以肯定地说,很多人在Visual Studio内部使用Boost.Build都不会出现问题。 Can you try running the program on the command line -- maybe there's some error message that Visual Studio decides not to show? 您可以尝试在命令行上运行该程序吗?也许有些错误消息是Visual Studio决定不显示的?

I'd recommend CMake as well. 我也建议CMake。 It's a bit scary at first but you ease into it progressively. 起初有点吓人,但是您可以逐步缓解它。 It's still rather easy for a beginner to write cross-platform scripts, even if they are not pretty or optimal as an expert would do. 对于初学者来说,编写跨平台脚本还是很容易的,即使它们不像专家那样漂亮也不理想。 Integration with CppUnit (for unit tests) and Hudson (build mgt) made it possible to configure a Continuous Integration framework in no time. 通过与CppUnit(用于单元测试)和Hudson(构建mgt)集成,可以立即配置持续集成框架。

I don't know much about NetBeans, but if you want to develop for both Windows and Linux and use Visual Studio on Windows, then CMake is the only sane choice , really. 我对NetBeans不太了解,但是如果您想同时为Windows和Linux开发并在Windows上使用Visual Studio,那么CMake确实是唯一明智的选择 I've used it for several years now, and I cannot begin to guess how much time it has saved me maintaining makefiles and project files. 我已经使用了几年了,我无法开始猜测它为我节省了多少时间来维护makefile和项目文件。

Upvote for Ben. 支持Ben。 We have a major vendor that did a Windows port of their old Unix code for commodity hardware access, and that's exactly what they did. 我们有一个主要的供应商,它为旧版Unix代码提供了Windows端口,以进行商品硬件访问,而这正是他们所做的。

Emacs works fine on both platforms, as does GNU make. Emacs和GNU都可以在两个平台上正常工作。 If you need a GUI, I'd use GTK+ with MinGW/msys rather than Cygnus and an X port. 如果需要GUI,我将GTK +与MinGW / msys结合使用,而不是Cygnus和X端口。

I've seen a CMake demo at Fosdem a few months ago and it looked pretty impressive. 几个月前,我在Fosdem观看了CMake演示,它看起来非常令人印象深刻。 I think it the time spent learning it may be worthwhile. 我认为花时间学习它可能是值得的。

On the other hand, it is my personal experience that maintaining separate project files per platform is a perfectly acceptable way of doing things. 另一方面,根据我个人的经验,每个平台维护单独的项目文件是一种完全可以接受的处理方式。

The only non-trivial thing about using CMake for cross-compilation is writing the toolchain information: CMake figures out the rest. 使用CMake进行交叉编译的唯一不平凡的事情是编写工具链信息:CMake会找出其余的信息。 See http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file for more information. 有关更多信息,请参见http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file

I don't know how complex you wanna get, I use mingw-4.4.2 + cmake on linux to compile my Qt4 apps for windows, and NSIS on wine to create the setup files. 我不知道您想要多么复杂,我在Linux上使用mingw-4.4.2 + cmake来编译Windows的Qt4应用程序,并在wine上使用NSIS来创建安装文件。 Basicly I hacked my CMakeLists.txt to use mingw when I pass -DWin32=1. 基本上,当我传递-DWin32 = 1时,我入侵了CMakeLists.txt以使用mingw。 here's the relevent part : 这是相关的部分:

if(WIN32) 
    SET(CMAKE_BUILD_TYPE "Release") #force release for win32, no motive to debug on win32

    SET(CMAKE_CXX_FLAGS_RELEASE  "-march=pentium4 -mtune=pentium4 -mwindows -DNDEBUG -mno-align-stringops -minline-stringops-dynamically -fno-ident -freorder-blocks-and-partition -finline-limit=700 -mfpmath=sse  -ftree-loop-distribution -floop-block -floop-interchange -floop-strip-mine -findirect-inlining -ftree-switch-conversion ${BASE_CXX_FLAGS}")

    SET(WIN32_BASE /home/win32-devel)
    SET(QT_LIB ${WIN32_BASE}/qt-win-opensource-src-4.5.3/lib/)

    SET(CMAKE_CXX_COMPILER i686-pc-mingw32-g++)
    SET(CMAKE_AR i686-pc-mingw32-ar)
    SET(CMAKE_RANLIB  i686-pc-mingw32-ranlib)
    SET(CMAKE_LINKER i686-pc-mingw32-ld)

    ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/app_icon.o
                        COMMAND i686-pc-mingw32-windres
                            -I${CMAKE_CURRENT_SOURCE_DIR}
                            -o${CMAKE_CURRENT_BINARY_DIR}/app_icon.o
                            -i${CMAKE_CURRENT_SOURCE_DIR}/icons/win32_icon.rc
                        )

    SET(OPENSSL_LIBRARIES  ${WIN32_BASE}/openssl-0.9.8l/libeay32.dll;${WIN32_BASE}/openssl-0.9.8l/libssl32.dll)
    SET(QT_LIBRARIES  ${QT_LIB}QtCore4.dll;${QT_LIB}/QtGui4.dll)
    SET(CMAKE_EXECUTABLE_SUFFIX ".exe")

    include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_LIB}../include ${WIN32_BASE}/openssl-0.9.8l/include)
    message("Building For   : Win32")
else()
    include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES} ${OPENSSL_INCLUDE_DIR})
    message("Building For   : Linux")
endif()
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,--no-undefined -static-libgcc -Wl,-O1 -Wl,--as-needed -Wl,--sort-common -s")

edit: Forgot to mention that actual development is done using KDevelop 4. 编辑:忘记提及实际开发是使用KDevelop 4完成的。

MPC ,“ Makefile,Project和Workspace Creator”,是另一个可能对您有用的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM